JavaScript toExponential()Method

Number 对象参考手册JavaScript Number Object

Example

Convert the value of the object to exponential notation:

var num = 5.56789;
var n=num.toExponential()

nOutput:


Try it Yourself »

Definition and Usage

The toExponential() method can convert the value of the object to exponential notation.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the toExponential() method.


Syntax

number.toExponential(x)

Parameter Values

Parameter Description
x Optional. Specifies the number of decimal places in the exponential notation, a value between 0 and 20, including 0 and 20. Some implementations may support a larger range of values. If this parameter is omitted, as many digits as possible will be used.

Return Value

Type Description
String Returns a string representation of the Number Object, in exponential notation: one digit before the decimal point and num digits after the decimal point. The fractional part of the number will be rounded, and padded with zeros if necessary, so that it reaches the specified length.

Technical Details

JavaScript Version: 1.5


More Examples

Example

In this example, we will convert a number to exponential notation:

var num = 5.56789;
var n=num.toExponential(3)

The output of the above example:


Try it Yourself »


Number 对象参考手册JavaScript Number Object

Other Extensions