The toExponential()
method returns a string representing the Number
object in exponential notation.
numObj.toExponential([fractionDigits])
fractionDigits
Optional
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
.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 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()
.
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
Specification |
---|
ECMAScript (ECMA-262) The definition of 'Number.prototype.toExponential' in that specification. |
Desktop | ||||||
---|---|---|---|---|---|---|
toExponential |
1 | 12 | 1 | 5.5 | 7 | 2 |
Mobile | ||||||
---|---|---|---|---|---|---|
toExponential |
1 | 18 | 4 | 10.1 | 1 | 1.0 |
Server | |
---|---|
toExponential |
0.1.100 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential