The toExponential method in JavaScript transforms a specified number into exponential notation and produces it as a string.
Syntax
The syntax for the toExponential method is depicted as follows:
Number. toExponential(num)
Parameter
num - This parameter is optional. It denotes an integer that indicates the number of digits to be located following the decimal point.
Return
A string that signifies the exponential representation of the specified number.
JavaScript Number toExponential method example
In this section, we will explore the toExponential method by examining several examples.
Example 1
Let's examine a straightforward illustration of the toExponential function.
<script>
var a=989721;
document.writeln(a.toExponential());
</script>
Output:
9.89721e+5
Example 2
In this instance, we will provide an integer that indicates the number of digits to be positioned following the decimal point.
<script>
var a=989721;
document.writeln(a.toExponential(2)+"<br>");
document.writeln(a.toExponential(4)+"<br>");
document.writeln(a.toExponential(6));
</script>
Output:
9.90e+5
9.8972e+5
9.897210e+5