UNPKG

the-math

Version:

TheMath is an extensive math library for JavaScript and Node.js. It features a flexible expression parser

20 lines (19 loc) 792 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function round(operation, options) { var _a = options || {}, _b = _a.precision, precision = _b === void 0 ? 0 : _b, _c = _a.roundType, roundType = _c === void 0 ? 'round' : _c; if (roundType === 'floor') { operation.number = Math.floor(operation.number * Math.pow(10, precision)) / Math.pow(10, precision); } if (roundType === 'ceil') { operation.number = Math.ceil(operation.number * Math.pow(10, precision)) / Math.pow(10, precision); } if (roundType === 'round') { operation.number = Math.round(operation.number * Math.pow(10, precision)) / Math.pow(10, precision); } return operation.number; } exports.default = round;