UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

18 lines 596 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = roundTo; /** * Rounds a number to the specified number of decimal places. * @param num - The number to round. * @param decimalPlaces - The number of decimal places to round to. Defaults to 0. * @returns The rounded number. * @example * roundTo(1.2345, 2); // 1.23 * roundTo(1.6789, 0); // 2 * roundTo(123.456, 1); // 123.5 */ function roundTo(num, decimalPlaces = 0) { const factor = 10 ** decimalPlaces; return Math.round(num * factor) / factor; } //# sourceMappingURL=roundTo.js.map