开发者

Why does Javasript's strict comparison act the way it does? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Is JavaScript’s math broken?

If the main difference between Javascript's "strict comparison" operators and the traditional ones is type coercion开发者_StackOverflow中文版, why does

0.1+0.2===0.3;

return false?


In Firefox and Chrome, 0.1 + 0.2 is 0.30000000000000004, which is not equal to 0.3. This is presumably caused by it not being possible to represent 0.1 exactly as a floating point number.


because 0.1 is tricky
it's irrational recurring 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜