avatar
h*n
1
为什么
(0.1+0.1==0.2) 是true 而 (0.1+0.1+0.1==0.3)是false?
谢谢!
avatar
z*h
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?
: 谢谢!

avatar
h*n
3
Thanks!
But 0.1+0.1 still equal to 0.2?? Kind of confusing.
avatar
A*o
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。