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

    Class DotNetDecimalFormatter

    Formatter for decimal numbers with high precision using .NET-compatible format strings.

    Similar to DotNetFloatFormatter but with different default precision behavior. When no format is specified, trailing zeros after the decimal point are automatically trimmed.

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

    // High precision formatting
    formatter.trySetFormat('F6');
    console.log(formatter.toString(123.456)); // "123.456000"

    // Default behavior (trims trailing zeros)
    console.log(formatter.toString(123.400)); // "123.4"

    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 number using the current format string. When no format is specified, trailing zeros are trimmed.

      Parameters

      • value: number

        The number to format.

      Returns string

      The formatted number string.

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

      Parameters

      • strValue: string

        The string to parse.

      Returns Result<number>

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

    • 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);
      }