将大数字字符串转换为数字 [英] Converting big number string to number

查看:104
本文介绍了将大数字字符串转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以将 16 位数字和 2 个分数值的字符串转换为数字?

What way i can convert string with 16 digits and 2 fraction value to number ?

目前,当我尝试将 Number('1234567890123456.12') 转换为 1234567890123456 时.分数值将消失.

Currently when I try to convert Number('1234567890123456.12') will became to 1234567890123456. fraction values will be gone.

我只是想在不使用任何第三方库的情况下确认我可以将此字符串转换为数字吗?

I just want to confirm without using any third party lib can i convert this string to number ?

推荐答案

很遗憾没有.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.

这篇关于将大数字字符串转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆