JavaScript中的大字符串 [英] Large numbers to string in JavaScript
本文介绍了JavaScript中的大字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行以下操作时:
alert((2053716830872415770228778006271971120334843128349550587141047275840274143041).toString());
我得到2.053716830872415e + 75指数表示法。
我想按原样提醒这个号码。
我试过toFixed(),toPrecision()和toLocaleString(),他们输出相同的东西。
I get the "2.053716830872415e+75" exponential notation. I want to alert the number as is. I tried toFixed(), toPrecision() and toLocaleString() and they output the same thing.
我怎样才能做到这一点?
注意:数字是一个变量,所以我无法提醒(208 ..);
How can I accomplish this? Note: the number is a variable, so I cannot alert("208..");
推荐答案
Javascript 使用64位浮点数。
它是无法在Javascript编号中精确存储您的值。
Javascript uses 64-bit floating point numbers.
It is impossible to precisely store your value in a Javascript number.
相反,你应该使用BigInteger库。
Instead, you should use a BigInteger library.
- http://www.leemon.com/crypto/BigInt.html
- http://www-cs-students.stanford.edu/~tjw / jsbn /
- https://github.com / jtobey / javascript-bignum
- http://www.leemon.com/crypto/BigInt.html
- http://www-cs-students.stanford.edu/~tjw/jsbn/
- https://github.com/jtobey/javascript-bignum
这篇关于JavaScript中的大字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文