3

Based on http://users.dickinson.edu/~braught/courses/cs131s99/Lessons/03-Out&Data.html, for readability, JavaScript uses scientific notation to display very large numbers (absolute value greater than or equal to 1021). For example, the write statement

document.write(1000000000000000000000000);

would produce the output 1e24

Can I avoid scientific notation display?

Thanks

Ricky
  • 34,377
  • 39
  • 91
  • 131

2 Answers2

0

It’s not for readability. If an integer is larger than 253 (9007199254740992), then JavaScript cannot guarantee its exact storage. In your case the number is actually 999999999999999983222784.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
  • 1
    That is correct. I wish I knew scientific notation, because I think it would be pretty easy to expand that. Maybe he'd be OK with inaccurate number storage? –  Jan 21 '11 at 03:57
0

You can use something like YourJS.fullNumber(). For instance you could try something like YourJS.fullNumber(1e20) to produce 100000000000000000000. Try out your own code here:

https://www.yourjs.com/console/?gist=9dce161c033e7391b2f871a19006a653&file=Example+of+YourJS.fullNumber.js

Chris West
  • 885
  • 8
  • 17