Description

The JavaScript Number method toExponential() returns a string representing the given number in exponential format.

  • It returns a new string and doesn't change the original number.
  • It is commonly used to convert a number to its exponential equivalent.

Syntax

The method toExponential() has the below syntax, where num is a string.

num.toExponential(fractionDigits)

Parameters

The method toExponential() allows the below parameters.

fractionDigits (optional)

  • It is an integer to specify the number of digits after the decimal point.
  • The default value is as many digits as necessary to represent the number.

Result

Returns a string that represents the exponential notation of a given number, with the number of decimal digits rounded to fractionDigits.

Example 1: Using the Method

The below example shows the basic usage of the method.

var num = 123.45678;

// Without parameter
document.write(num.toExponential());          // Prints: 1.2345678e+2

// Using fraction digits 2
document.write(num.toExponential());          // Prints: 1.23e+2

// Using fraction digits 10
document.write(str.valueOf());          // Prints: 1.2345678000e+2

Output:

1.2345678e+2
1.23e+2
1.2345678000e+2

Overall

The JavaScript Number method toExponential() returns a string representing the given number in exponential format.

Related Links