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

    Class DotNetIntegerFormatter

    Formatter for integer values (bigint) using .NET-compatible format strings.

    Supports formatting integers with standard format strings like D (decimal), X (hexadecimal), B (binary), and custom format strings.

    const formatter = new DotNetIntegerFormatter();
    formatter.localeSettings = DotNetLocaleSettings.createInvariant();

    // Decimal with padding
    formatter.trySetFormat('D8');
    console.log(formatter.toString(123n)); // "00000123"

    // Hexadecimal
    formatter.trySetFormat('X');
    console.log(formatter.toString(255n)); // "FF"

    // Parsing
    formatter.styles = DotNetNumberStyles.integer;
    const result = formatter.tryFromString('-12345');
    if (result.isOk()) {
    console.log(result.value); // -12345n
    }

    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;
    
    • Formats a bigint value using the current format string.

      Parameters

      • value: bigint

        The bigint value to format.

      Returns string

      The formatted number string.

    • Attempts to parse a bigint value from a string using the current parsing styles.

      Parameters

      • strValue: string

        The string to parse.

      Returns Result<bigint>

      A Result containing the parsed bigint if successful, or an error if parsing fails.

      formatter.styles = DotNetNumberStyles.integer;
      const result = formatter.tryFromString(' -123 ');
      if (result.isOk()) {
      console.log(result.value); // -123n
      }
    • 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);
      }