4

if use big number in "alert" or "console.log" return bad result. Example:

alert(999999999999999999);

Result:

1000000000000000000

But we dont have any problem on alert(999999999999999); or alert(99999999999999999999999999999);

Mo Mirmousavi
  • 1,035
  • 1
  • 7
  • 13
  • 3
    Related: [What is JavaScript's Max Int?](http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t) – Jonathan Lonowski May 24 '14 at 18:48
  • If you check this answer to the question [How to check if a number is float or integer?](http://stackoverflow.com/a/3885844/1960455) you can check if it is a _float_ or an _int_. As soon as it is a _float_ you would not get the _expected_ results anymore. – t.niese May 24 '14 at 18:50
  • Find it, Javascript doesn't have integers... Source: [Why is 9999999999999999 converted to 10000000000000000 in JavaScript?][1] [1]: https://stackoverflow.com/questions/13429451/why-is-9999999999999999-converted-to-10000000000000000-in-javascript – Mo Mirmousavi May 24 '14 at 21:16

1 Answers1

4

As the maximum integer in js is 253 or 9007199254740992 (see the link Jonathan Lonowski mentioned: What is JavaScript's Max Int? ) every number that exceeds this limit is not an integer anymore but a float.

As you can only represent certain numbers using floats. The result of an input value that is larger then an integer would - most of the time - be an aproximated one. That's why you get those results when you alert or console.log.

Community
  • 1
  • 1
t.niese
  • 39,256
  • 9
  • 74
  • 101