Tutorials Point

  JavaScript Basics
  JavaScript Objects
  JavaScript Advanced
  JS Useful References
  JS Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Javascript Number - toExponential()

previous next AddThis Social Bookmark Button



This method returns a string representing the number object in exponential notation


number.toExponential( [fractionDigits] )

Here is the detail of parameters:

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

Return Value:

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.


<title>Javascript Method toExponential()</title>
<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); 

This will produce following result:

num.toExponential() is : 7.71234e+1
num.toExponential(4) is : 7.7123e+1
num.toExponential(2) is : 7.71e+1
77 .toExponential() is : 7.71234e+1

To understand it in better way you can Try it yourself.

previous next Printer Friendly