2

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

0

3 Answers 3

4

What Every Computer Scientist Should Know About Floating Point Arithmetic

and the shorter, more to the point:

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

@airbai, now you have two problems :)
-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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.