@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.
12 lines (11 loc) • 404 B
TypeScript
/**
* 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
*/
export default function roundTo(num: number, decimalPlaces?: number): number;