Skip to content

Add group_decimals option to opt out of SI-style fraction grouping - #60

Closed
SCHPRS wants to merge 1 commit into
drakegroup:masterfrom
SCHPRS:group-decimals-option
Closed

SCHPRS wants to merge 1 commit into
drakegroup:masterfrom
SCHPRS:group-decimals-option

Conversation

@SCHPRS

@SCHPRS SCHPRS commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

spacer/spacing groups digits in threes on both sides of the decimal marker, following the 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.

This adds a group_decimals option (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'

Test plan

  • Added cases to test/test_equality.csv covering group_decimals=False/True, integer-only inputs (unaffected), and an uncertainty-pair case.
  • Full existing suite (test/test.py) still passes unmodified — 319/319 (313 original + 6 new).
  • Documented in doc/api.rst next to spacer/spacing; built with sphinx-build -W --keep-going (0 warnings).

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
SCHPRS marked this pull request as draft September 8, 2026 07:43
@SCHPRS
SCHPRS marked this pull request as ready for review September 8, 2026 07:43
@SCHPRS

SCHPRS commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@MikeBusuttil
Hello,
thank you a lot for this library.
Here is my small contribution regarding an area for improvement that I think is important
Let me know if there's anything else I can do to help you with this pull request.

@MikeBusuttil

Copy link
Copy Markdown
Collaborator

thanks @SCHPRS :) I'll review this late next week. Sounds like a useful feature! Glad you're getting usage out of the library

@MikeBusuttil

Copy link
Copy Markdown
Collaborator

resolved in #64

thanks for the suggestion & the work @SCHPRS

@MikeBusuttil

MikeBusuttil commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

here's how its used:

>>> round(1234567.891011, decimals=6, left_spacer=',', spacing=3)
'1,234,567.891011'

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.

2 participants