Can any one explain to me why 9999999999999999 is converted to 10000000000000000?
alert(9999999999999999); //10000000000000000
http://jsfiddle.net/Y2Vb2/
Note that the bitwise operators and shift operators operate on 32-bit integers, so in that case, the max safe integer is 231-1, or 2,147,483,647.
The JavaScript Number type is a double-precision 64-bit binary format IEEE 754 value, like double in Java or C#. This means it can represent fractional values, but there are some limits to what it can store. A Number only keeps about 17 decimal places of precision; arithmetic is subject to rounding.
Javascript doesn't have integers, only 64-bit floats - and you've ran out of floating-point precision.
See similar issue in Java: why is the Double.parseDouble making 9999999999999999 to 10000000000000000?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With