formcycle 8.4.0 - JavaScript for forms
    Preparing search index...

    Interface NumberFormatApiFormatter

    The API for formatting and parsing numerical values, independent of any NumberFormat element.

    The API is available via $.xutil.numberFormat.formatter.

    interface NumberFormatApiFormatter {
        formatNumber: (
            value: string | number,
            options: Partial<NumberFormatOptions>,
        ) => string;
        isCorrectlyFormatted: (
            value: string,
            options: Partial<NumberFormatOptions>,
        ) => boolean;
        parseAsNumber: (
            value: string,
            options: Partial<NumberFormatOptions>,
        ) => number;
        parseAsString: (
            value: string,
            options: Partial<NumberFormatOptions>,
        ) => string;
    }
    Index

    Properties

    formatNumber: (
        value: string | number,
        options: Partial<NumberFormatOptions>,
    ) => string

    Formats a number using the given options. The number may be given either as a number or a string. The string must be a valid number, using a dot as the decimal separator. Using a string avoids floating point precision issues.

    Type declaration

      • (value: string | number, options: Partial<NumberFormatOptions>): string
      • Parameters

        • value: string | number

          The number to format.

        • options: Partial<NumberFormatOptions>

          The options to use when formatting the number.

        Returns string

        The formatted number.

    When the given number is a string that does not represent a valid number.

    isCorrectlyFormatted: (
        value: string,
        options: Partial<NumberFormatOptions>,
    ) => boolean

    Checks if the given value is a valid number formatted according to the given options.

    Type declaration

      • (value: string, options: Partial<NumberFormatOptions>): boolean
      • Parameters

        • value: string

          The formatted number to check.

        • options: Partial<NumberFormatOptions>

          The options to use for checking the number.

        Returns boolean

        True if the given value is a valid number, false otherwise.

    parseAsNumber: (value: string, options: Partial<NumberFormatOptions>) => number

    Parses a formatted number using the given options. The value is returned as a number.

    Type declaration

      • (value: string, options: Partial<NumberFormatOptions>): number
      • Parameters

        • value: string

          The formatted number to be parsed.

        • options: Partial<NumberFormatOptions>

          The options to use when parsing the number.

        Returns number

        The parsed number.

    When the given number string does not represent a valid number.

    parseAsString: (value: string, options: Partial<NumberFormatOptions>) => string

    Parses a formatted number using the given options. The value is returned a string, using a dot as the decimal separator.

    Type declaration

      • (value: string, options: Partial<NumberFormatOptions>): string
      • Parameters

        • value: string

          The formatted number to be parsed.

        • options: Partial<NumberFormatOptions>

          The options to use when parsing the number.

        Returns string

        The parsed number.

    When the given number string does not represent a valid number.