为什么Javasript的严格比较会有这样的表现?
Possible Duplicate:
Is JavaScript’s math broken?
If the main difference between Javascript's "strict comparison" operators and the traditional ones is type coercion, why does
0.1+0.2===0.3;
return false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为 0.1 很棘手
它是
非理性以二进制形式重复出现(参见评论)编辑
实际上我只是即兴发挥,我不确定。是否有 Math.boffin 可以反驳或提供证明?
会很有趣的
because 0.1 is tricky
it's
irrationalrecurring in binary (see comments)EDIT
actually I'm winging it here, I don't know that for sure. Is there a Math.boffin out there who can disprove or provide a proof?
would be very interesting
在 Firefox 和 Chrome 中,
0.1 + 0.2
为0.30000000000000004
,它不等于0.3
。这可能是由于无法将0.1
精确地表示为浮点数所致。In Firefox and Chrome,
0.1 + 0.2
is0.30000000000000004
, which is not equal to0.3
. This is presumably caused by it not being possible to represent0.1
exactly as a floating point number.