UNPKG

diginext-utils

Version:
20 lines 506 B
/** * 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 * ``` */ export function round(value, decimals = 0) { const factor = Math.pow(10, decimals); return Math.round(value * factor) / factor; } //# sourceMappingURL=round.js.map