Skip to content Skip to sidebar Skip to footer

Number Precision In Javascript

Why 100 == 99.999 is true, however 100 == 99.99 is false in Javascript?

Solution 1:

What Every Computer Scientist Should Know About Floating Point Arithmetic

and the shorter, more to the point:

http://floating-point-gui.de/

Solution 2:

Where are you getting that result?

From Firebug console in Firefox 3.6.3

>>>100==99.99
false
>>>100==99.999
false
>>>100==99.9999
false
>>>100==99.99999
false
>>>100==99.999999
false
>>>100==99.9999999
false
>>>100==99.99999999
false
>>>100==99.999999999
false
>>>100==99.9999999999
false
>>>100==99.99999999999
false
>>>100==99.999999999999
false
>>>100==99.9999999999999
false
>>>100==99.99999999999999
false
>>>100==99.999999999999999
true

Solution 3:

Why is 100 == 99.999 true in Javascript?

It's not; whatever Javascript implementation you are using is buggy.

however 100 == 99.99 is false in Javascript?

Because they're not equal.

Post a Comment for "Number Precision In Javascript"