1 October 2011

This snippet shows you how to round a number to a specified number of decimal places in JavaScript.

Source code viewer
  1. var number = 100.994;
  2.  
  3. number.toFixed(); // Returns "100"
  4. number.toFixed(2); // Returns "100.99"
Programming Language: Javascript