Home > Blockchain >  Number in Javascript changes after declaring it as a variable. Even parsing it from a string returns
Number in Javascript changes after declaring it as a variable. Even parsing it from a string returns

Time:06-05

This is very weird please check it yourself.

Whenever I try to declare variable with the number 76561198322368902 it always changes to 76561198322368900 no matter what. Chrome Devtools Console Screenshot

Even when I pass the variable as a string and later parse to a number, it always changes to 76561198322368900.

I really don't know what to do. I never thought Integers were capable of such thing.

CodePudding user response:

The "maximum safe integer" in JavaScript is 9007199254740991 - trying to use the number type beyond this can yield unpredictable results.

Use the BigInt type if you need a bigger number.

CodePudding user response:

You just exeeded the Number.MAX_SAFE_INTEGER

  • Related