Skip to content

fix(number): preserve digits in large decimal strings in intcomma - #502

Closed
KUMAR-AKASH-M wants to merge 4 commits into
python-humanize:mainfrom
KUMAR-AKASH-M:fix/intcomma-496
Closed

KUMAR-AKASH-M wants to merge 4 commits into
python-humanize:mainfrom
KUMAR-AKASH-M:fix/intcomma-496

Conversation

@KUMAR-AKASH-M

Copy link
Copy Markdown

Fixes #496.
intcomma('1234567890123456.78') returned '1,234,567,890,123,456.8' because the string branch converted decimal strings through float(). When no rounding is requested (ndigits is None), plain decimal strings are now parsed with Decimal, matching the existing Decimal input path, so grouping retains the input digits. Behaviour is deliberately unchanged when ndigits is given (rounding still uses float formatting), and for exponent/trailing-dot strings (still float).
One behaviour note: intcomma('14308.40') now returns '14,308.40' instead of '14,308.4', consistent with intcomma(Decimal('14308.40')); trailing zeros are input digits, not rounding.
Tests: added regression cases to tests/test_number.py. Verified locally: all 244 tests in tests/test_number.py pass (36 intcomma tests before the new cases, 244 total after adding them), including the issue repro.
No CLA, screenshot, or device test is involved; this is a pure-Python formatting fix.

@hugovk

hugovk commented Nov 2, 2026

Copy link
Copy Markdown
Member

Duplicate of #498 and #497.

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.

intcomma() loses digits from large decimal strings

2 participants