Search This Blog

Monday, May 3, 2010

How to round to 2 decimal places using javascript

Following lines are for rounding a number to specified decimal places.

function roundNumber(num, dec)
{
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

Above javascript function can be implement as follows

var roundedNumber = roundNumber(annualPremium,2);

No comments:

Post a Comment