1var subTotal="12.1345";// can also be int, float, string
2var subTotalFormatted=parseFloat(subTotal).toFixed(2); //"12.13"
3
1function round(value, precision) {
2 var multiplier = Math.pow(10, precision || 0);
3 return Math.round(value * multiplier) / multiplier;
4}
1>>> parseFloat(0.9999999.toFixed(4));
21
3>>> parseFloat(0.0009999999.toFixed(4));
40.001
5>>> parseFloat(0.0000009999999.toFixed(4));
60
7