Skip to content

Fix stray comma after minus sign in HumanFloatCount#815

Merged
djc merged 1 commit into
console-rs:mainfrom
sueun-dev:fix/humanfloatcount-negative-comma
Jun 24, 2026
Merged

Fix stray comma after minus sign in HumanFloatCount#815
djc merged 1 commit into
console-rs:mainfrom
sueun-dev:fix/humanfloatcount-negative-comma

Conversation

@sueun-dev

Copy link
Copy Markdown
Contributor

Fixes #814

HumanFloatCount's Display impl grouped the integer digits over the whole int part including the leading -, so the sign was counted as a digit and a comma landed right after it for sign-aligned lengths:

  • HumanFloatCount(-100.0)"-,100"
  • HumanFloatCount(-100000.0)"-,100,000"
  • HumanFloatCount(f64::NEG_INFINITY)"-,inf"

(-1000.0 only looked right because the sign offset coincides with a real group boundary.)

The fix splits the optional sign off before grouping and writes it first; positive numbers are unchanged.

Added human_float_count_negative covering negatives and -inf. It fails on the current code (left "-100" / right "-,100") and passes with the change. cargo test, cargo fmt --check, and cargo clippy are clean.

The Display impl grouped digits over the int part including the leading
'-', so the sign counted as a digit and a comma landed right after it for
sign-aligned lengths: HumanFloatCount(-100.0) rendered "-,100",
-100000.0 rendered "-,100,000", and NEG_INFINITY rendered "-,inf".
Strip the sign before grouping. Add a regression test for negatives and
-inf (it fails before, passes after).

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@djc djc merged commit cbd070d into console-rs:main Jun 24, 2026
11 checks passed
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.

HumanFloatCount prints a stray comma after the minus sign for some negatives

2 participants