diginext-utils
Version:
README.md
23 lines • 599 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.round = round;
/**
* Rounds a number to a specified number of decimal places.
*
* @param value - The number to round
* @param decimals - Number of decimal places (default: 0)
* @returns The rounded number
*
* @example
* ```ts
* round(3.14159, 2); // 3.14
* round(3.14159, 0); // 3
* round(3.5); // 4
* round(2.735, 2); // 2.74
* ```
*/
function round(value, decimals = 0) {
const factor = Math.pow(10, decimals);
return Math.round(value * factor) / factor;
}
//# sourceMappingURL=round.js.map