Number toFixed()

The toFixed() method returns a string representation of a number with a specified number of decimal points.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var num = 10; 
        
        document.writeln(num.toFixed(2)); //"10.00" 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

The rounding nature of toFixed()

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var num = 10.005; 
        document.writeln(num.toFixed(2)); //"10.01" 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Essential Types  

Number:
  1. The Number Type
  2. Number toExponential()
  3. Number toFixed()
  4. Number toPrecision()
  5. Number toString()
  6. Number valueOf()
  7. Converting Strings to Numbers
  8. typeof and instanceof for Number objects and primitive values