开发者

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

开发者 https://www.devze.com 2022-12-20 11:02 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Is JavaScript’s math broken?
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

精彩评论

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