Thursday, July 3, 2014

Rounding Numbers to ‘N’ Decimals in javascript

var num = 2.443242342;
alert(num.toFixed(2)); // 2.44

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

No comments:

Post a Comment