Repository navigation
Fix intcomma() returning scientific notation for large floats - #449
Open
Vinayak19112003 wants to merge 1 commit into
Open
Vinayak19112003 wants to merge 1 commit into
Vinayak19112003 wants to merge 1 commit into
Conversation
Wkhanex
reviewed
Oct 12, 2026
There was a problem hiding this comment.
Additional value-preservation check: six large, small, signed and signed-zero floats (1e16, -1e16, 1.5e20, 1e-5, -1e-5, -0.0) all rendered without scientific notation. Parsing the output after removing grouping commas reproduced Decimal(repr(value)) exactly. This checks that expanding the shortest float representation adds grouping without introducing extra rounding, including negative tiny values. I ran these checks on Python 3.12 with English locale hooks; no full localization or pytest run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #431.
intcomma()usedf"{value:,}"for floats, which formats viarepr(). That switches to scientific notation at 1e16 (and for tiny floats like 1e-5), so no thousands separators were added:>>> intcomma(1e16) '1e+16'The float is now expanded to fixed-point via
Decimal(repr(value))before grouping, so the full decimal representation gets commas:The
ndigitspath already used fixed-point formatting and is unchanged, as is the integer path.Tests: new
test_intcomma_large_float_no_scientific_notation(6 cases: 1e15/1e16/1.5e20/negative/tiny/ndigits=0) — fails on main, passes with the fix. Fulltests/test_number.py: 247 passed. Ruff check and format clean.