Why 100 == 99.999 is true, however 100 == 99.99 is false in Javascript?
Asked
Active
Viewed 2,386 times
3 Answers
4
What Every Computer Scientist Should Know About Floating Point Arithmetic
and the shorter, more to the point:

Marco Mariani
- 13,556
- 6
- 39
- 55
3
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

harpo
- 41,820
- 13
- 96
- 131
-
5@airbai, now you have two problems :) – harpo Mar 23 '11 at 07:16
-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.

Stephen Canon
- 103,815
- 19
- 183
- 269