The toExponential()
method is used to convert a number into an exponential notation.
Here is the syntax of the toExponential()
method:
number.toExponential(x)
This method takes a number as a parameter to represent the number of digits after a decimal point. The number must be in the range of 0 to 20
.
This method returns a string
value that represents the exponential notation of a given number.
Let's look at an example of this.
let num = 6.57769;//no.of digits after decimal is 1console.log(num.toExponential(1))//no.of digits after decimal is 3console.log(num.toExponential(3))//no.of digits after decimal is 8console.log(num.toExponential(8))
num
.num
to an exponential form, which has 1
digit after the decimal point.num
to an exponential form, which has 3
digits after the decimal point.num
to an exponential form, which has 8
digits after the decimal point.