Subscribe For Free Updates!

We'll not spam mate! We promise.

May 26, 2013

Rounding Numbers to ‘N’ Decimal

Rounding Numbers to ‘N’ Decimal

 This will let you round off a number to ‘N’ decimal places. In the below example we are rounding of a number to 2 decimal places.

var num = 4.56789;
alert(num.toFixed(2));

It will alert as 4.56.

Another function to display a number upto a length is toPrecision(x).

num = 520.2375;
result = num.toPrecision(4);
alert(result);

It will display as 520.2.
 


TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment