By 05/02/2014 15 Comments

How to rounding off numbers to ‘x’ decimal places in Javascript

Rounding off numbers

  • It is used for mathematical calculations depends upon requirements
  • Here we use two methods for rounding off numbers using decimal value


  • The toFixed(x) method used to provides x length after the decimal point


  • The toPrecision(x) provides x total length

Following code describes simple example by using these two methods / functions


var num = 2.443242342; // floating point numbers are assigned in num variable

alert(num.toFixed(2)); // call method toFixed, pass 1 parameter and produce 2.44 as output in alert popup

num = 500.2349;

result = num.toPrecision(4); // result will equal 500.2


Posted in: JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .