The toExponential()
method in JavaScript converts a number into the exponential notation in string format. If the method is invoked on an object that is not a number, a TypeError
occurs.
The toExponential()
method is declared as shown below:
The toExponential()
method takes a single optional parameter x
.
If x
is not within the range 0-100, a RangeError
occurs.
If x
is not specified, the default value is the number of digits required to specify the number.
The toExponential()
method returns a string that represents the number as an exponential notation.
The following code shows the use of the toExponential()
method in JavaScript:
//Example 1var num = 1.25;console.log(num.toExponential());//Example 2var num2 = 1.234567;console.log(num2.toExponential(3));
Free Resources