toExponential()
method returns a string representing the Number object in exponential notation.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
numObj.toExponential([fractionDigits])
fractionDigits
Optional. An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.
A string representing the given
Number
object in exponential notation with one digit before the decimal point, rounded to
fractionDigits
digits after the decimal point.
RangeError
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
Number
.
若
fractionDigits
argument is omitted, the number of digits after the decimal point defaults to the number of digits necessary to represent the value uniquely.
若使用
toExponential()
method for a numeric literal and the numeric literal has no exponent and no decimal point, leave whitespace(s) 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 than 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()
.
toExponential
var numObj = 77.1234; console.log(numObj.toExponential()); // logs 7.71234e+1 console.log(numObj.toExponential(4)); // logs 7.7123e+1 console.log(numObj.toExponential(2)); // logs 7.71e+1 console.log(77.1234.toExponential()); // logs 7.71234e+1 console.log(77 .toExponential()); // logs 7.7e+1
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Number.prototype.toExponential' in that specification. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toExponential
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 7 | Safari 2 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持
Number
Number.isFinite()
Number.isInteger()
Number.isNaN()
Number.isSafeInteger()
Number.parseFloat()
Number.parseInt()
Number.prototype.toExponential()
Number.prototype.toFixed()
Number.prototype.toLocaleString()
Number.prototype.toPrecision()
Number.prototype.toSource()
Number.prototype.toString()
Number.prototype.valueOf()
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()