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.

Number methodES3 (1999)Live demo
Common call
n.toExponential(2)
Returns
a string like '1.23e+4'
Replaces
toPrecision when you always want exponential
Watch out
the digits argument counts places AFTER the point
number.toExponential([digits])
→ string

Demo

Live evaluation
Try:
Inputs
nnumbera number
dnumberdigits after the point
Output
(12345).toExponential(2)
'1.23e+4'

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

NameTypeRequiredDescription
digitsnumberno (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

Consistent output across magnitudes
Every value formats to the same shape.
readings.map(r => r.toExponential(3));
Split into mantissa and exponent
The format is reliably parseable.
const [m, e] = n.toExponential(2).split('e');
Readable output instead
Exponential notation is rarely what a user wants.
new Intl.NumberFormat().format(n);

Examples

1. Large number
(12345).toExponential(2)
Returns
'1.23e+4'
2. Small fraction
(0.0001).toExponential()
Returns
'1e-4'
3. Zero digits
(12345).toExponential(0)
Returns
'1e+4'
4. Negative
(-12345).toExponential(2)
Returns
'-1.23e+4'
5. toFixed differs
(0.0001).toFixed(2)
Returns
'0.00'
6. It is a string
typeof (1).toExponential(2)
Returns
'string'

Pitfalls

1. The argument is digits AFTER the point, not total
toExponential(2) gives three significant digits — one before the point and two after. toPrecision(2) gives two in total. Swapping the two methods without adjusting the argument changes the precision by one digit.
Three significant
(12345).toExponential(2)
'1.23e+4'
Two significant
(12345).toPrecision(2)
'1.2e+4'
2. It is unreadable for ordinary values
Formatting a price or a count this way produces output no user wants to see. It belongs in scientific contexts and in logs where consistent width matters, not in a UI.
Not for humans
(1234.5).toExponential(2)
'1.23e+3'
Readable
(1234.5).toLocaleString('en-US')
'1,234.5'
3. It returns a string, like its siblings
All three formatting methods do. Arithmetic on the result concatenates, and the exponential form does not even parse back cleanly with parseInt — though Number and parseFloat both handle it.
parseInt stops at e
parseInt('1.23e+4')
1
Number understands
Number('1.23e+4')
12300
4. Omitting the argument gives variable width
With no digits argument the method uses as many as needed to round-trip the value, so different numbers produce different widths. If you are aligning columns, always pass a count.
Varies
(0.0001).toExponential()
'1e-4'
Fixed width
(0.0001).toExponential(3)
'1.000e-4'

When to use

Use it
  • 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
Reach for something else
  • 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

Complexity
O(1)
Return
A new string; the number is unchanged
CPython impl
V8: Builtins-number-toexponential
Memory
Allocates the result string
Thread-safe
Single-threaded

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

History

ES3
toExponential added with toFixed and toPrecision.