2

I declared two variables like this and tried to compare them like this

var x  = 9999999999999999;
var y  = 10000000000000000;
x == y //returns true

What is the reason for this behavior?

6
  • 4
    The question is rather "why is 9999999999999999 being rounded to 10000000000000000" (check your JS console). Commented Nov 4, 2013 at 12:28
  • Yes, just reframed that as this. I observed the behaviour that you mentioned. Commented Nov 4, 2013 at 12:29
  • stackoverflow.com/questions/307179/… Commented Nov 4, 2013 at 12:29
  • And why : 0.3 - 0.1 = 0.19999999999999998 Commented Nov 4, 2013 at 12:29
  • Worth reading: docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html Commented Nov 4, 2013 at 12:37

1 Answer 1

1

Check this out:

"Javascript doesn't have integers, only 64-bit floats - and you've ran out of floating-point precision."

Why is 9999999999999999 converted to 10000000000000000 in JavaScript?

Thanks to the member Kos.

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

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.