When running
console.log(parseInt("9658921879781125"))
9658921879781124
, which is less than the original value.
Why is this the case?
That would be because
9658921879781125 > Number.MAX_SAFE_INTEGER // true
So it is unsafe to try to work with numbers greater than Number.MAX_SAFE_INTEGER
The
MAX_SAFE_INTEGER
constant has a value of9007199254740991
(9,007,199,254,740,991 or ~9 quadrillion). The reasoning behind that number is that JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent numbers between -(253 - 1) and 253 - 1.Safe in this context refers to the ability to represent integers exactly and to correctly compare them.
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