When I type large number using fixed notation, JS changes it to scientific notation. Why? Is it only because it's hard to read large numbers or it's somehow related to difficulties of storing large numbers in memory?
-
The conventions for formatting numbers when they're converted to strings are just that: conventions. You can format numbers with your own code or through other libraries. – Pointy Sep 23 '17 at 01:24
-
It's related to how floating point numbers are stored. Many c-style languages use exponential notation for the same underlying reason. – zzzzBov Sep 23 '17 at 01:25
-
it's not javascript specific. Most languages display large numbers in scientific notation (Excel does it too) because large numbers take too much space. It has nothing to do with how they are stored in memory – Slai Sep 23 '17 at 01:32
2 Answers
The ECMA specification defines how numbers are converted to strings (which is the only time you'll be seeing scientific notation).
The relevant part of the spec is here: https://www.ecma-international.org/ecma-262/8.0/index.html#sec-tostring-applied-to-the-number-type
As far as I can fathom it, scientific notation kicks in for numbers greater than 10^21 or less than 10^-6

- 26,597
- 10
- 74
- 130
In Javascript, numbers are always stored as floating point numbers and follow IEEE 754's format. As for displaying numbers, Javascript uses ECMAScript display algorithm as mentioned by Dancrumb, which defines when to start rendering numbers in scientific notation format.
If you'd like to avoid scientific notation for large numbers, there are ways to get around it which are discussed in this post: How to avoid scientific notation for large numbers in JavaScript?.

- 66
- 1
- 3