h*******n 发帖数: 2052 | 1 为什么
(0.1+0.1==0.2) 是true 而 (0.1+0.1+0.1==0.3)是false?
谢谢! |
z***h 发帖数: 405 | 2 0.1 is treated as double, which won't be exactly 0.1 internally
after 0.1+0.1+0.1 the differences accumulate signifant enough to not equal 0
.3
it's 0.30000000000000004
【在 h*******n 的大作中提到】 : 为什么 : (0.1+0.1==0.2) 是true 而 (0.1+0.1+0.1==0.3)是false? : 谢谢!
|
h*******n 发帖数: 2052 | 3 Thanks!
But 0.1+0.1 still equal to 0.2?? Kind of confusing. |
A**o 发帖数: 1550 | 4 all floating numbers are represented in binary format.
所以.1只有近似值,没有准确值。
只不过.1+.1的结果正好等于.2的近似值。
你应该学习浮点数的表达方式。
【在 h*******n 的大作中提到】 : Thanks! : But 0.1+0.1 still equal to 0.2?? Kind of confusing.
|