admin管理员组

文章数量:1398235

When I do the following:

alert((2053716830872415770228778006271971120334843128349550587141047275840274143041).toString());

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.

How can I acplish this? Note: the number is a variable, so I cannot alert("208..");

When I do the following:

alert((2053716830872415770228778006271971120334843128349550587141047275840274143041).toString());

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.

How can I acplish this? Note: the number is a variable, so I cannot alert("208..");

Share Improve this question asked Feb 13, 2011 at 15:55 SuprDewdSuprDewd 2696 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Javascript uses 64-bit floating point numbers.
It is impossible to precisely store your value in a Javascript number.

Instead, you should use a BigInteger library.

  • http://www.leemon./crypto/BigInt.html
  • http://www-cs-students.stanford.edu/~tjw/jsbn/
  • https://github./jtobey/javascript-bignum

本文标签: Large numbers to string in JavaScriptStack Overflow