Javascript - Number toExponential() Method

The toExponential() method converts a number into an exponential notation.

Description

The toExponential() method converts a number into an exponential notation.

Syntax

number.toExponential(x)

Parameter Values

Parameter Require Description
x Optional.An integer between 0 and 20, sets the number of digits in the notation after the decimal point.

If omitted, it is set to as many digits as necessary to represent the value

Return

A String, representing the number as an exponential notation

Example

Convert a number into an exponential notation:

Demo

//display the exponential notation of a specified number.
var num = 5.56789;
var n = num.toExponential();
console.log(n);/* w  w w.  ja  v  a2s . c  om*/

var n = num.toExponential(3);
console.log(n);

Result