What is Number.toExponential() method in JavaScript?

JavascriptWeb DevelopmentFront End Technology

This method returns a string representing the number object in exponential notation. The following is the syntax:

number.toExponential( [fractionDigits] )

The fractionDigits parameter is an integer specifying the number of digits after the decimal point.

Example

You can try to run the following code to learn how to work with Number.toExponential() method in JavaScript

Live Demo

<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>
raja
Published on 18-Jan-2018 16:27:50
Advertisements