tastypie
Version:
Tastypie is a webservice API framework for Node.js based on Django's Tastypie Framework. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces
13 lines (11 loc) • 409 B
JavaScript
var toNumber = require('../lang/toNumber');
/**
* Enforce a specific amount of decimal digits and also fix floating
* point rounding issues.
*/
function enforcePrecision(val, nDecimalDigits){
val = toNumber(val);
var pow = Math.pow(10, nDecimalDigits);
return +(Math.round(val * pow) / pow).toFixed(nDecimalDigits);
}
module.exports = enforcePrecision;