pols-utils - v5.3.11
    Preparing search index...

    Function format

    • Converts a number to a formatted string representation.

      Parameters

      • value: number

        The numeric value to format.

      • config: {
            decimals?: number;
            decimalSeparator?: string;
            significativeNumber?: boolean;
            thousandSeparator?: string;
        } = {}

        Configuration object.

        • Optionaldecimals?: number

          Default 0. Number of decimal places to include.

        • OptionaldecimalSeparator?: string

          Default '.'. Character to use as the decimal separator.

        • OptionalsignificativeNumber?: boolean

          Default false. If true, trailing zeros in the decimal part will be omitted.

        • OptionalthousandSeparator?: string

          Default ','. Character to use as the thousand separator.

      Returns string

      A formatted string representing the number.

      console.log(PUtilsNumber.format(123456789.1234)) // 123,456,789
      console.log(PUtilsNumber.format(123456789.1234, { decimals: 2 })) // 123,456,789.12
      console.log(PUtilsNumber.format(123456789.1234, { decimals: 5 })) // 123,456,789.12340
      console.log(PUtilsNumber.format(123456789.1234, { decimals: 5, significativeNumber: true })) // 123,456,789.1234
      console.log(PUtilsNumber.format(123456789.1234, { decimals: 5, significativeNumber: true, decimalSeparator: ',', millarSeparator: ' ' })) // 123 456 789,1234