UNPKG

codetrix

Version:

A lightweight lodash-style utility library

15 lines (14 loc) 375 B
/** * Rounds a number to a specific number of decimal places. * * @param value The number to round. * @param decimals The number of decimal places. * @returns The rounded number. * * @example * roundTo(3.14159, 2); // 3.14 */ export function roundTo(value, decimals = 0) { const factor = Math.pow(10, decimals); return Math.round(value * factor) / factor; }