Number.prototype.toExponential()
The predictable member of the formatting trio. Unlike toPrecision it never switches representation, which makes it the right choice when consistent output shape matters more than readability.
Demo
There is always exactly one digit before the point, and the exponent carries the magnitude — 12345 with two digits becomes '1.23e+4'. Small numbers get a negative exponent rather than a string of leading zeros, which is the main reason to reach for this over toFixed when values span many orders of magnitude. Unlike toPrecision, the output shape never changes: a consumer can always split it on 'e' and get a mantissa and an exponent.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| digits | number | no (as many as needed) | Digits after the decimal point, 0 to 100. Omitted, as many as are needed to represent the value uniquely. |
Return value
string — A string in exponential form — exactly one digit before the decimal point, then the requested digits after it, then e and a signed exponent.
Common patterns
readings.map(r => r.toExponential(3));
const [m, e] = n.toExponential(2).split('e');
new Intl.NumberFormat().format(n);
Examples
Pitfalls
(12345).toExponential(2)
(12345).toPrecision(2)
(1234.5).toExponential(2)
(1234.5).toLocaleString('en-US')
parseInt('1.23e+4')
Number('1.23e+4')
(0.0001).toExponential()
(0.0001).toExponential(3)
When to use
- Scientific output where exponential notation is the convention
- Values spanning many orders of magnitude, formatted consistently
- Logs and fixed-width reports
- Producing a mantissa and exponent you intend to parse apart
- Anything a user reads → toLocaleString or Intl.NumberFormat
- Fixed decimal places → toFixed
- Significant digits with automatic notation → toPrecision
- You need a number back → this returns a string
Notes
FAQ
toExponential always uses exponential form and counts digits AFTER the point. toPrecision counts total significant digits and picks fixed or exponential notation depending on magnitude. If you always want the same shape, this is the one.
(12345).toExponential(2); // '1.23e+4' — 3 significant (12345).toPrecision(2); // '1.2e+4' — 2 significant