JavaScript Number toExponential() method
- Forrige side prototype
- Næste side toFixed()
- Gå tilbage til forrige niveau JavaScript Number Reference Manual
Definition and usage
toExponential()
The method converts a number to exponential notation.
Instance
Example 1
let num = 5.56789; let n = num.toExponential(3);
Example 2
Convert a number to exponential notation:
let num = 5.56789; let n = num.toExponential();
Syntax
number.toExponential(digits)
Parameter
Parameter | description |
---|---|
digits |
Optional. An integer between 0 and 20, specifying the number of decimal places in exponential notation. If omitted, it is set to the number of digits required to represent the value. |
return value
type | description |
---|---|
string | represent the number in exponential notation. |
Technical details
return value
Returns the string representation of Number using exponential notation, that is, one digit before the decimal point and digits digit. The decimal part of the number will be rounded and, if necessary, padded with 0 to reach the specified length.
thrown
exception | description |
---|---|
RangeError |
when digits An exception is thrown when the value is too small or too large. Values between 0 and 20 do not cause this exception. Some implementations support a wider or narrower range of values. |
TypeError | An exception is thrown if the object that calls this method is not a Number. |
Browser support
Number.constructor
Er ECMAScript3 (ES3) funktioner.
Alle browsere understøtter ES3 (JavaScript 1999):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Støtte | Støtte | Støtte | Støtte | Støtte | Støtte |
- Forrige side prototype
- Næste side toFixed()
- Gå tilbage til forrige niveau JavaScript Number Reference Manual