How to force a number to display in exponential notation?


Use the toExponential() method to force a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation.

The following is the parameter −

  • fractionDigits - An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number.

Example

You can try to run the following code to force a number to display in exponential function −

<html>
   <head>
      <title>Javascript Method toExponential()</title>
   </head>
   <body>
      <script>
         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>

Updated on: 23-Jun-2020

616 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements