Converting a string to a number results in a different number
When I try to convert the bigint passed from php to an integer in nodejs, the result is always different, I couldn't figure out what was wrong with it.
> var a = parseInt('135601920000000040', 10);
undefined
> a
135601920000000030
> var a = parseFloat('135601920000000040');
undefined
> a
135601920000000030
> var n = Number('135601920000000040');
undefined
> n
135601920000000030
Not only node.js, this also happens with the js interpreter in Firefox
+3
source to share
1 answer
The number type in javascript is represented as double precision floating point, so the value passed to parseInt, parseFloat, etc. is greater than 9007199254740992 ( ECMAScirpt Numbers spec ), it will be placed according to the number type.
+3
source to share