简体   繁体   English

Javascript 中的数字在声明为变量后会发生变化。 即使从字符串中解析它也会返回错误的数字

[英]Number in Javascript changes after declaring it as a variable. Even parsing it from a string returns a wrong number

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.每当我尝试使用数字 76561198322368902 声明变量时,无论如何它总是会更改为 76561198322368900。 Chrome Devtools Console Screenshot Chrome Devtools 控制台截图

Even when I pass the variable as a string and later parse to a number, it always changes to 76561198322368900.即使我将变量作为字符串传递并稍后解析为数字,它也总是更改为 76561198322368900。

I really don't know what to do.我真的不知道该怎么办。 I never thought Integers were capable of such thing.我从没想过整数有能力做这样的事情。

The " maximum safe integer " in JavaScript is 9007199254740991 - trying to use the number type beyond this can yield unpredictable results. JavaScript 中的“ 最大安全整数”是 9007199254740991 - 尝试使用超出此范围的数字类型会产生不可预知的结果。

Use the BigInt type if you need a bigger number.如果您需要更大的数字,请使用BigInt类型。

你刚刚超过了 Number.MAX_SAFE_INTEGER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM