July 29, 2006

JavaScript, round decimal numbers

This is some good code to round a decimal number to however many places you need using javascript:

// Round a number (num) to however many decimal places (dec)
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

kick it on DotNetKicks.com

1 comment:

Alex said...

Dude, email me at my gmail account because I have no idea what your email address is. It's too f-ing long!