JS number function adds up zeros at the end
This question already has an answer here:
In JS, the largest integral value is 9007199254740991
That is, all the positive and negative integers should not exceed the -9007199254740991
and 9007199254740991
respectively.
The same is defined as the 253-1.
console.log(Number.isSafeInteger(parseInt('1111111111')))
console.log(parseInt('1111111111'))
console.log(Number.isSafeInteger(parseInt('111111111111111111')))
console.log(parseInt('111111111111111111'))
//9007199254740991 - The largest JS Number
console.log(Number.isSafeInteger(parseInt('9007199254740991')))
This is because you're using numbers that are larger than Number.MAX_SAFE_INTEGER
and Javascript does not guarantee to represent these numbers correctly
Use Number.isSafeInteger
to check:
> Number.isSafeInteger(Number('111111111111111111'))
< false
链接地址: http://www.djcxy.com/p/96848.html
上一篇: VolumeProvider的onAdjustVolume上的步骤有多大?
下一篇: JS数字函数在最后加上零