Skip to content

feat: add OptionSetNumberSeparator to format numbers with separators (#222) - #244

Open
littfed wants to merge 1 commit into
schollz:mainfrom
littfed:feat/option-number-separator
Open

littfed wants to merge 1 commit into
schollz:mainfrom
littfed:feat/option-number-separator

Conversation

@littfed

@littfed littfed commented Oct 7, 2026

Copy link
Copy Markdown

Fixes #222

Description

This PR adds support for formatting numbers with custom digit separators (such as _, ,, or spaces).

Features Added

  • OptionSetNumberSeparator(separator string): sets the digit group separator.
  • Aliases: OptionSetSeparator and OptionSeparator for convenience.
  • Formats iteration counts (current/max and unbounded counts) and iteration rates (it/s, it/min, it/hr).
  • If no separator is configured (default), numbers remain formatted without separators, preserving backwards compatibility.

Example

bar := progressbar.NewOptions(1048576,
    progressbar.OptionSetWidth(10),
    progressbar.OptionShowCount(),
    progressbar.OptionSetPredictTime(false),
    progressbar.OptionSetNumberSeparator("_"),
)
bar.Add(1024)
// Output: 0% |          | (1_024/1_048_576)

Testing

  • Added TestFormatNumber table-driven unit tests covering edge cases (single digits, exact multiples of 3, large numbers, negative values, various separators).
  • Added TestOptionSetNumberSeparator covering the option and aliases.
  • Added ExampleOptionSetNumberSeparator runnable example test.
  • All existing tests pass cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format numbers with separators

1 participant