Copyright ©

Javascript Number - toFixed()

previous next



This method formats a number with a specific number of digits to the right of the decimal.


number.toFixed( [digits] )

Here is the detail of parameters:

Return Value:

A string representation of number that does not use exponential notation and has exactly digits digits after the decimal place.


<title>JavaScript toFixed() Method</title>
<script type="text/javascript">
   var num=177.1234;
   document.write("num.toFixed() is : " + num.toFixed()); 
   document.write("<br />"); 
   document.write("num.toFixed(6) is : " + num.toFixed(6)); 
   document.write("<br />"); 
   document.write("num.toFixed(1) is : " + num.toFixed(1)); 
   document.write("<br />"); 

   document.write("(1.23e+20).toFixed(2) is:" + 
   document.write("<br />"); 
   document.write("(1.23e-10).toFixed(2) is : " + 

This will produce following result:

num.toFixed() is : 177
num.toFixed(6) is : 177.123400
num.toFixed(1) is : 177.1
(1.23e+20).toFixed(2) is:123000000000000000000.00
(1.23e-10).toFixed(2) is : 0.00 

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

previous next

Copyright ©