小数点后的双精度 [英] Precision of double after decimal point
问题描述
在午休,我们开始debatting有关双击
值类型的精度。
In the lunch break we started debatting about the precision of the double
value type.
我collegue认为,它具有小数点后总是15位。
My collegue thinks, it has always 15 places after the decimal point.
在我看来一个人不能说,因为IEEE 754不作假设
关于这一点,它取决于其中第一个 1
是二进制
表示。 (即小数点数之前数的大小,太)
In my opinion one can't tell, because IEEE 754 does not make assumptions
about this and it depends on where the first 1
is in the binary
representation. (i.e. the size of the number before the decimal point counts, too)
如何让更多的合格声明?
How to make a more qualified statement?
推荐答案
如前所述通过的 C#参考的,精度为15至16位(取决于表示的十进制值)。精密意义小数位数的值可以保存(不分位置)。
As stated by the C# reference, the precision is from 15 to 16 digits (depending on the decimal values represented). Precision meaning the number of decimal digits a value can hold (regardless of the position).
总之,你是对的,它取决于前值。小数点
例如:
12345678.1234567D
//Next digit to the right will get rounded up1234567.12345678D
//Next digit to the right will get rounded up
全样本eXvz3相对=nofollow> http://ideone.com/eXvz3
Full sample at: http://ideone.com/eXvz3
另外,需要注意的是思维双
,因为它们是十进制值是不是一个好主意值。
Also, it is important to note that thinking double
values as they are decimal values is not a good idea.
这篇关于小数点后的双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!