Copyright © tutorialspoint.com

Javascript Number - toExponential()

previous next

Advertisements


Description:

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

Syntax:

number.toExponential( [fractionDigits] )

Here is the detail of parameters:

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.

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>

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.1234.toExponential()is:7.71234e+1
77 .toExponential() is : 7.71234e+1

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


previous next

Copyright © tutorialspoint.com