Skip to content

intcomma() loses digits from large decimal strings #496

Open

Description

@agammann

intcomma() silently loses a fractional digit when given a large decimal string, even with ndigits omitted. The equivalent Decimal input preserves it.

Reproduced on current main (6b817b963dbb091b9ad20a746cb6a26653a93b95; 42 commits after 4.16.0) with Python 3.14.8 on Windows:

from decimal import Decimal
from humanize import intcomma

print(intcomma('1234.12'))
print(intcomma('1234567890123456.78'))
print(intcomma(Decimal('1234567890123456.78')))

Observed:

1,234.12
1,234,567,890,123,456.8
1,234,567,890,123,456.78

Expected: grouping the large decimal string should retain its input digits, yielding 1,234,567,890,123,456.78. This is formatting without an explicit rounding request.

The string branch in src/humanize/number.py converts values containing a decimal point with float(value), then formats that rounded binary float. The final 7 is lost before grouping. The Decimal control shows the formatting path can preserve the value.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions