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.

21 lines (20 loc) 704 B
/** * Formats a number into a more readable string with suffixes like K, M, B, etc. * * Converts: * - Numbers in the thousands (e.g., 1200 → "1.2k") * - Numbers in the millions (e.g., 1200000 → "1.2M") * - Numbers in the billions (e.g., 1200000000 → "1.2B") * * Numbers below 1000 remain unchanged. * * @param num - The number to format. * @param digits - The number of decimal places to display (default is 1). * @returns A string representing the formatted number. * * @example * formatNumber(1200); // Output: "1.2k" * formatNumber(1200000); // Output: "1.2M" * formatNumber(999); // Output: "999" */ export default function formatNumber(num: number, digits?: number): string;