Uh oh!
There was an error while loading. Please reload this page.
gh-130664: support '_' (just as ',') in Decimal's formatting - #132155
Conversation
```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%'
```| (',%', '123.456789', '12,345.6789%'), | ||
| (',e', '123456', '1.23456e+5'), | ||
| (',E', '123456', '1.23456E+5'), | ||
| # ... with '_' instead |
There was a problem hiding this comment.
Can we not just use the existing tests with a for loop?
There was a problem hiding this comment.
What you meant? There is no existing test with '_' separator.
StanFromIreland
left a comment
There was a problem hiding this comment.
Does this not need a documentation update somewhere too?
Uh oh!
There was an error while loading. Please reload this page.
…F2r-U.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
skirpichev
commented
Apr 7, 2025
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). |
Thanks @skirpichev for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…ythonGH-132155) (cherry picked from commit e10fe81) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
GH-136649 is a backport of this pull request to the 3.13 branch. |
Uh oh!
There was an error while loading. Please reload this page.