Javascript: Round numbers off to X decimal places

0 Comments

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

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

Source

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