• Formats a number into a compact string representation.

    Parameters

    • number: string | number | bigint | boolean

      The number to format.

    • isMoneyOrCurrecyPrefix: string | boolean

      If true, adds a dollar sign prefix. If a string, uses it as the prefix.

    • compressedDigitsNumDecimalsOptions: { "1"?: number; "2"?: number; "3"?: number } = ...

      Options for decimal places.

      • Optional1?: number

        How many decimals there should be when there is 1 digit.

        2
        
      • Optional2?: number

        How many decimals there should be when there are 2 digits.

        1
        
      • Optional3?: number

        How many decimals there should be when there are 3 digits.

        0
        
    • OptionaldecimalPlaces: number = 0

      The number of decimal places to use when there is no suffix.

    • Optionalprecision: number = 100

      The precision to use for the Decimal instance. Defaults to 100.

    Returns string

    The formatted number.

    numberFormatter_compact(123456789, true); // "$123M"
    numberFormatter_compact(123456789, "€"); // "€123M"
    numberFormatter_compact(12345678); // "12.3M"
    numberFormatter_compact(123456789, false, { 3: 5 }); // "123.45678M"
    numberFormatter_compact(12345678, false, { 3: 5 }); // "12.3M"
    numberFormatter_compact(12345678, false, { 2: 3 });