1

Possible Duplicate:
How to avoid scientific notation for large numbers in javascript?

Hi All,

Doing something like this

alert(999999999999999999999999999999999999999999999999);

results in this

Javascript Popup 1e+48

How to i stop converting a number to a string from saying 1e+XX or Infinity?

Community
  • 1
  • 1
Timothy Ruhle
  • 7,387
  • 10
  • 41
  • 67

2 Answers2

1

No one seems to have provided the most obvious solution which is to enclose in quotes so that javascript treats it as a string and not a number.

alert('999999999999999999999999999999999999999999999999');
krock
  • 28,904
  • 13
  • 79
  • 85
1

There is only so many digits that will actually be able to maintain precision so when you reach that limit it starts using the e+ notation...

alert(' '+ 12345678901234567890 + ' ')

Will output 12345678901234567000

So for example also if you did

alert(' '+ 999999999999999999 + ' ')

You get 1000000000000000000

GL...

John Sobolewski
  • 4,512
  • 1
  • 20
  • 26