Repository navigation
intcomma: expand floats whose repr uses scientific notation - #484
Closed
mayur-dhavan wants to merge 2 commits into
Closed
mayur-dhavan wants to merge 2 commits into
mayur-dhavan wants to merge 2 commits into
Conversation
Enhance number formatting to handle scientific notation.
Added test cases for floats in scientific notation to ensure correct formatting.
Author
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.
Fixes #431.
Problem
intcommaformats floats withf"{value:,}", which uses repr-style general formatting and switches to an exponent at 1e16 (and below 1e-4), so no commas are added:Fix
When the grouped result contains an exponent marker, reformat through
Decimal(repr(value)), which never uses scientific notation. Integral floats keep their trailing.0, matching the existing output for values below 1e16 (e.g.intcomma(1e15)stays'1,000,000,000,000,000.0'). Thendigitspath and string inputs are unchanged.Tests
Seven new parametrized cases in
test_intcomma(1e16, 1.5e20, -1e16, 1e16 with ndigits=0, 0.00001, 1.23e-5, 1234.5e15).tests/test_number.pypasses locally (248 passed) and the full suite passes except the pre-existingtest_benchmarks.pycollection errors, which require the optionalpytest-benchmarkplugin and fail identically on unmodified master.AI disclosure: this contribution was prepared with AI assistance (an automated coding agent acting on behalf of the author); the change and tests were validated locally against the project's test suite as described above.