Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 9999999999999999 converted to 10000000000000000 in JavaScript?

Tags:

javascript

Can any one explain to me why 9999999999999999 is converted to 10000000000000000?

alert(9999999999999999); //10000000000000000 

http://jsfiddle.net/Y2Vb2/

like image 491
Ramaraj Karuppusamy Avatar asked Nov 17 '12 09:11

Ramaraj Karuppusamy


People also ask

How long can numbers be in JavaScript?

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.

How big are JavaScript numbers?

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.


1 Answers

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?

like image 106
Kos Avatar answered Sep 19 '22 21:09

Kos