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
- Javascript to Round to 2 Decimal Places? by aleksei
Mainly notes to future-Twig (and for anyone else who may find them useful)
If you've found one or more of my blog posts helpful, why not say thanks by buying me a coffee or beer?
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);
}