Number.prototype.toExponential()

Summary

The toExponential() method returns a string representing the Number object in exponential notation

Syntax

numObj.toExponential(fractionDigits)

Parameter

fractionDigits
An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.

Returns

A string representing a Number object in exponential notation with one digit before the decimal point, rounded to fractionDigits digits after the decimal point. If the fractionDigits argument is omitted, the number of digits after the decimal point defaults to the number of digits necessary to represent the value uniquely.

If you use the toExponential() method for a numeric literal and the numeric literal has no exponent and no decimal point, leave a space before the dot that precedes the method call to prevent the dot from being interpreted as a decimal point.

If a number has more digits that requested by the fractionDigits parameter, the number is rounded to the nearest number represented by fractionDigits digits. See the discussion of rounding in the description of the toFixed() method, which also applies to toExponential().

Throws

RangeError
If fractionDigits is too small or too large. Values between 0 and 20, inclusive, will not cause a RangeError. Implementations are allowed to support larger and smaller values as well.
TypeError
If this method is invoked on an object that is not a Number.

Examples

var numObj = 77.1234;

alert("numObj.toExponential() is " + numObj.toExponential()); //displays 7.71234e+1

alert("numObj.toExponential(4) is " + numObj.toExponential(4)); //displays 7.7123e+1

alert("numObj.toExponential(2) is " + numObj.toExponential(2)); //displays 7.71e+1

alert("77.1234.toExponential() is " + 77.1234.toExponential()); //displays 7.71234e+1

alert("77 .toExponential() is " + 77 .toExponential()); //displays 7.7e+1

Specifications

Specification Status Comment
ECMAScript 3rd Edition. Implemented in JavaScript 1.5 Standard Initial definition.
ECMAScript Language Specification 5.1th Edition (ECMA-262) Standard  
ECMAScript Language Specification 6th Edition (ECMA-262) Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See Also

Document Tags and Contributors

Contributors to this page: evilpie, Sheppy, fscholz, ethertank, Sevenspade, Ptak82, Mgjbot, Mook, Diablownik
Last updated by: fscholz,