Javascript: Round numbers off to X decimal places

Simple little snippet which I was surprised wasn't part of the Math class.

function round_number(num, dec) {
return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
}

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog