1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 1 1 144 144 1 | define(function(){ /** * Enforce a specific amount of decimal digits and also fix floating * point rounding issues. * @example `enforcePrecision(0.615, 2) -> 0.62`, `(0.615).toFixed(2) -> * 0.61` */ function enforcePrecision(val, nDecimalDigits){ var pow = Math.pow(10, nDecimalDigits); return +(Math.round(val * pow) / pow).toFixed(nDecimalDigits); } return enforcePrecision; }); |