This is due to the nature of IEEE754 double-precision 64-bit floating-point math 1 ( all compatible JavaScript implementations use this form of IEEE arithmetic ) - your number 10 466 511 635 124 471 is greater than the highest positive integer, which is represented as consecutive numbers that account for 2 53 (9 007 199 254 740 992). 64 bits of a number in JavaScript are represented using 1 bit for the sign, 52 bits for the number (the special behavior for exponents is effectively 53 bits of precision) and 11 bits for the exponent, so this is the case.
When your number exceeds this maximum number, it will use a score higher than 1 to represent this, which will reduce the smallest possible representation. With an indicator of two (as represented in your case), the smallest differentiable change in numbers will be two, and since your number is between the two, it will be rounded to the nearest.
JavaScript does not have any arbitrary integer format size , nor does it support anything similar to BigNum (to use the term Java) or arbitrary precision arithmetic. If you want to store large numbers, you will have to use another way to store it, such as strings.
1: I contacted Wikipedia as the actual specification really costs money to get legally / officially - if anyone has a better source, edit it.
source share