@pbkware/dot-net-date-number-formatting - v0.3.2
    Preparing search index...

    Class DotNetNumberFormatter

    Base class for formatting and parsing numbers using .NET-compatible format strings.

    Supports both standard format strings (C, D, E, F, G, N, P, R, X, B) and custom format strings with fine-grained control over digit placeholders, separators, and sections.

    This is a base class - use DotNetIntegerFormatter, DotNetFloatFormatter, or DotNetDecimalFormatter for specific number types.

    // Use derived classes instead
    const formatter = new DotNetFloatFormatter();
    formatter.localeSettings = DotNetLocaleSettings.createInvariant();
    formatter.trySetFormat('C2');
    console.log(formatter.toString(1234.56)); // "$1,234.56"

    Hierarchy (View Summary)

    Index
    format: string = ""
    localeSettings: DotNetLocaleSettings = DotNetLocaleSettings.current

    The locale settings that determine decimal/thousands separators and other culture-specific formatting.

    parseErrorText: string = ""

    Contains the error message from the last failed operation. Check this property if DotNetNumberFormatter.trySetFormat or parsing methods return an error.

    styles: number = DotNetNumberStyles.number

    The (DotNetNumberStyles:var) that control which number formats are allowed during parsing.

    formatter.styles = DotNetNumberStyles.allowLeadingSign | DotNetNumberStyles.allowDecimalPoint;
    
    • Parameters

      • value: number | bigint
      • allowDecimal: boolean = true

      Returns string

    • Parameters

      • value: string

      Returns boolean

    • Parameters

      • value: string

      Returns boolean

    • Parameters

      • value: string

      Returns false

    • Parameters

      • value: string

      Returns string

    • Sets the format string to use for formatting numbers.

      The format string is tokenized to confirm validity and to optimize formatting/parsing operations.

      Parameters

      • value: string

        A standard format string (e.g., "C", "N2", "E3") or custom format string (e.g., "#,##0.00").

      Returns Result<void>

      A Result indicating success or containing an error message if the format string is invalid.

      // Standard format
      formatter.trySetFormat('C2'); // Currency with 2 decimal places

      // Custom format
      formatter.trySetFormat('#,##0.00'); // Number with thousands separator

      // Check for errors
      const result = formatter.trySetFormat('INVALID');
      if (result.isErr()) {
      console.error(result.error);
      }
    • Parameters

      • value: string

      Returns Result<{ negated: boolean; unstyled: string }>