JavaScript(JS) number method - toexponential

www.igif‮c.aedit‬om

The toExponential() method is a built-in method of the Number object in JavaScript. It returns a string representation of the number in exponential notation (also called scientific notation), with one digit before the decimal point and a specified number of digits after the decimal point.

Here's an example usage:

const num = 123456789;

console.log(num.toExponential(2)); // 1.23e+8
console.log(num.toExponential(5)); // 1.23457e+8
console.log(num.toExponential(10)); // 1.2345678900e+8

In the above example, the toExponential() method is called on the num variable, which is assigned the value 123456789. The method is called three times with different arguments to format the output. The first call specifies that there should be two digits after the decimal point, which results in the string "1.23e+8". The second call specifies that there should be five digits after the decimal point, which results in the string "1.23457e+8". The third call specifies that there should be ten digits after the decimal point, which results in the string "1.2345678900e+8".