且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将大数字字符串转换为数字

更新时间:2023-02-03 08:12:03

很遗憾没有.Javascript 使用双精度浮点数表示它的数字.在 16 位时,它只能存储整数部分,而不能存储小数点后的部分.您将需要一个 bignum 库来使用此值.

Unfortunately not. Javascript represents it's numbers using double precision floating point numbers. At 16 digits, it will only be able to store the integer component and not the part after the decimal point. You will need a bignum library to use this value.

作为参考,您可以在 JavaScript 中使用的最大整数是 9,007,199,254,740,991

for reference the biggest integer you can use in JavaScript is 9,007,199,254,740,991

感谢 Jeremy,您可以使用像 bignumberJS 这样的库.

Thanks to Jeremy you can use a library like bignumberJS.