This method returns a string representing the number object in exponential notation.
Its syntax is as follows −
number.toExponential( [fractionDigits] )
fractionDigits − An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.
A string representing a Number object in exponential notation with one digit before the decimal point, rounded to fractionDigits digits after the decimal point. If the fractionDigits argument is omitted, the number of digits after the decimal point defaults to the number of digits necessary to represent the value uniquely.
Try the following example.
<html> <head> <title>Javascript Method toExponential()</title> </head> <body> <script type="text/javascript"> var num=77.1234; var val = num.toExponential(); document.write("num.toExponential() is : " + val ); document.write("<br />"); val = num.toExponential(4); document.write("num.toExponential(4) is : " + val ); document.write("<br />"); val = num.toExponential(2); document.write("num.toExponential(2) is : " + val); document.write("<br />"); val = 77.1234.toExponential(); document.write("77.1234.toExponential()is : " + val ); document.write("<br />"); val = 77.1234.toExponential(); document.write("77 .toExponential() is : " + val); </script> </body> </html>
num.toExponential() is : 7.71234e+1 num.toExponential(4) is : 7.7123e+1 num.toExponential(2) is : 7.71e+1 77.1234.toExponential()is:7.71234e+1 77 .toExponential() is : 7.71234e+1