Repository navigation
Conversation
spacer/spacing groups digits in threes on both sides of the decimal
marker, per SI convention (spacing=3 turns 0.123456 into 0.123 456).
That's wrong when spacer is used as a locale thousands separator,
where only the integer part should be grouped.
For example, formatting 1234567.891011 for on-screen display should
give "1,234,567.891011" -- thousands grouped, decimals untouched --
but round(..., spacer=',', spacing=3) currently returns
"1,234,567.891,011". There is currently no way to express "group
only the integer part" without post-processing the string output.
Add group_decimals (default True, preserving current behavior) so
callers can opt out with False:
>>> round(1234567.891011, decimals=6, spacer=',', spacing=3)
'1,234,567.891,011'
>>> round(1234567.891011, decimals=6, spacer=',', spacing=3, group_decimals=False)
'1,234,567.891011'
Covered by new cases in test_equality.csv; documented in doc/api.rst
next to spacer/spacing.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
SCHPRS
marked this pull request as draft
September 8, 2026 07:43
SCHPRS
marked this pull request as ready for review
September 8, 2026 07:43
Contributor
Author
|
@MikeBusuttil |
Collaborator
|
thanks @SCHPRS :) I'll review this late next week. Sounds like a useful feature! Glad you're getting usage out of the library |
Collaborator
Collaborator
|
here's how its used: >>> round(1234567.891011, decimals=6, left_spacer=',', spacing=3)
'1,234,567.891011' |
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.
Summary
spacer/spacinggroups digits in threes on both sides of the decimal marker, following the SI convention (spacing=3turns0.123456into0.123 456). That's wrong whenspaceris used as a locale thousands separator, where only the integer part should be grouped.For example, formatting
1234567.891011for on-screen display should give"1,234,567.891011"— thousands grouped, decimals untouched — butround(..., spacer=',', spacing=3)currently returns"1,234,567.891,011". There is currently no way to express "group only the integer part" without post-processing the string output.This adds a
group_decimalsoption (defaultTrue, preserving current behavior) so callers can opt out withFalse:Test plan
test/test_equality.csvcoveringgroup_decimals=False/True, integer-only inputs (unaffected), and an uncertainty-pair case.test/test.py) still passes unmodified — 319/319 (313 original + 6 new).doc/api.rstnext tospacer/spacing; built withsphinx-build -W --keep-going(0 warnings).