8

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 accomplish this? Note: the number is a variable, so I cannot alert("208..");

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Are there any arbitrary-precision arithmetic JavaScript libraries out there?
Of those three libraries, the last one definitely seems the most "modern" in terms of implementation style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.