This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

toExponential

Summary

The toExponential() method formats a number to exponential notation.

Syntax

toExponential([ fractionDigits ])
fractionDigits
Optional. The number of digits after the decimal point. Must be in the range 0 - 20, inclusive.

Return Value

Returns a string representation of a number in exponential notation. The string contains one digit before the decimal point, and may contain fractionDigits digits after it.

If fractionDigits is not supplied, the toExponential method returns as many digits necessary to uniquely specify the number.

Examples

Using toExponential to format the text presentation of a number.

var pie = 3.14159;

pie.toPrecision();
// Returns: "3.14159e+0"

pie.toPrecision(3);
// Returns: "3.142e+0"

pie.toPrecision(1);
// Returns: "3.1e+0"

pie.toPrecision(0);
// Returns: "3e+0"

Remarks

Throws

RangeError when a fractionDigits outside the bounds of 0 - 20 (inclusive) was given.

See also

Other articles

External resources

Specification

15.7.4.6 Number.prototype.toExponential(fractionDigits)

ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011

Attributions

  • Microsoft Developer Network: Article