GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-130664: support '_' (just as ',') in Decimal's formatting by skirpichev · Pull Request #132155 · python/cpython

Conversation

@skirpichev

@skirpichev skirpichev commented Apr 6, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
>>> from _decimal import Decimal as D
>>> format(D(1234567), '_')
'1_234_567'
>>> format(D(1234567), '020_')
'0_000_000_001_234_567'
>>> format(D('1234.56'), '07_')
'1_234.56'
>>> format(D('1.23456789'), '_')
'1.23456789'
>>> format(D('123.456789'), '_%')
'12_345.6789%'
>>> from _pydecimal import Decimal as D
>>> format(D(1234567), '_')
'1_234_567'
>>> format(D(1234567), '020_')
'0_000_000_001_234_567'
>>> format(D('1234.56'), '07_')
'1_234.56'
>>> format(D('1.23456789'), '_')
'1.23456789'
>>> format(D('123.456789'), '_%')
'12_345.6789%'
  • Issue: Undocumented handling of thousands separator for floats and differences wrt Decimal #130664

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@skirpichev
pythongh-130664: support '_' (just as ',') in Decimal's formatting
1ae18f5
```pycon
>>> from _decimal import Decimal as D
>>> format(D(1234567), '_')
'1_234_567'
>>> format(D(1234567), '020_')
'0_000_000_001_234_567'
>>> format(D('1234.56'), '07_')
'1_234.56'
>>> format(D('1.23456789'), '_')
'1.23456789'
>>> format(D('123.456789'), '_%')
'12_345.6789%'
>>> from _pydecimal import Decimal as D
>>> format(D(1234567), '_')
'1_234_567'
>>> format(D(1234567), '020_')
'0_000_000_001_234_567'
>>> format(D('1234.56'), '07_')
'1_234.56'
>>> format(D('1.23456789'), '_')
'1.23456789'
>>> format(D('123.456789'), '_%')
'12_345.6789%'
```
@bedevere-app bedevere-app Bot added the awaiting review label Apr 6, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 6, 2025
Undocumented handling of thousands separator for floats and differences wrt Decimal #130664
Open
@python-cla-bot

python-cla-bot Bot commented Apr 6, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland
StanFromIreland reviewed Apr 6, 2025
View reviewed changes
Comment thread Lib/test/test_decimal.py
(',%', '123.456789', '12,345.6789%'),
(',e', '123456', '1.23456e+5'),
(',E', '123456', '1.23456E+5'),
# ... with '_' instead

@StanFromIreland StanFromIreland Apr 6, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just use the existing tests with a for loop?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@skirpichev skirpichev Apr 7, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you meant? There is no existing test with '_' separator.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
StanFromIreland
StanFromIreland reviewed Apr 6, 2025
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not need a documentation update somewhere too?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/NEWS.d/next/Library/2025-04-06-14-34-29.gh-issue-130664.JF2r-U.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev @StanFromIreland
Update Misc/NEWS.d/next/Library/2025-04-06-14-34-29.gh-issue-130664.J…
e0dbe89
…F2r-U.rst

Co-authored-by: Stan Ulbrych <[email protected]>
@skirpichev

skirpichev commented Apr 7, 2025

Copy link
Copy Markdown
Member Author

Does this not need a documentation update somewhere too?

We don't have documentation for Decimal's formatting, beyond some notes in the Format Specification Mini-Language. There are no even examples of formatted output (few added in #128698).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv
ambv merged commit e10fe81 into python:main Apr 15, 2025
@bedevere-app bedevere-app Bot removed the awaiting review label Apr 15, 2025
@skirpichev
skirpichev deleted the decimal-underscore-sep/130664 branch April 15, 2025 11:20
@skirpichev skirpichev mentioned this pull request Jul 14, 2025
, works with Decimal() against the doc of **Format Specification Mini-Language** #136636
Closed
@skirpichev skirpichev added the needs backport to 3.13 only security fixes label Jul 14, 2025
@miss-islington-app

miss-islington-app Bot commented Jul 14, 2025

Copy link
Copy Markdown

Thanks @skirpichev for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 14, 2025
@skirpichev @miss-islington
pythongh-130664: support '_' (just as ',') in Decimal's formatting (p…
26be90d
…ythonGH-132155)

(cherry picked from commit e10fe81)

Co-authored-by: Sergey B Kirpichev <[email protected]>
@bedevere-app

bedevere-app Bot commented Jul 14, 2025

Copy link
Copy Markdown

GH-136649 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jul 14, 2025
picnixz pushed a commit that referenced this pull request Jul 14, 2025
@miss-islington @skirpichev
[3.13] gh-130664: support '_' (just as ',') in Decimal's formatting (G…
2a6617d
…H-132155) (#136649)

gh-130664: support '_' (just as ',') in Decimal's formatting (GH-132155)
(cherry picked from commit e10fe81)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@StanFromIreland StanFromIreland StanFromIreland left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@skirpichev @StanFromIreland @ambv
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.