UNPKG

409 BJavaScriptView Raw
1var toNumber = require('../lang/toNumber');
2 /**
3 * Enforce a specific amount of decimal digits and also fix floating
4 * point rounding issues.
5 */
6 function enforcePrecision(val, nDecimalDigits){
7 val = toNumber(val);
8 var pow = Math.pow(10, nDecimalDigits);
9 return +(Math.round(val * pow) / pow).toFixed(nDecimalDigits);
10 }
11 module.exports = enforcePrecision;
12