You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript stores all numbers as double-precision binary IEEE 754 floating point values. Each number is internally stored on 64 bits: 1 bit for sign, 52 for mantissa and 11 for exponent. Given that it has limited number of bits available, it can therefore represent only a limited number of different values. Integers are just a small subset of that.
The maximal integer you can safely represent (without losing the precision) is Number.MAX_SAFE_INTEGER, whose value is 9007199254740991. You are trying to represent 123456789012345678, which is larger than max safe integer, so you lost precision. That is expected.
To solve the problem, you can use BigInt (simply add n to the end of your number).
Please see this picture:
The text was updated successfully, but these errors were encountered: