Skip to content

Commit e10fe81

Browse files
authored
gh-130664: support '_' (just as ',') in Decimal's formatting (#132155)
1 parent c66ffcf commit e10fe81

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/_pydecimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6098,7 +6098,7 @@ def _convert_for_comparison(self, other, equality_op=False):
60986098
(?P<alt>\#)?
60996099
(?P<zeropad>0)?
61006100
(?P<minimumwidth>(?!0)\d+)?
6101-
(?P<thousands_sep>,)?
6101+
(?P<thousands_sep>[,_])?
61026102
(?:\.(?P<precision>0|(?!0)\d+))?
61036103
(?P<type>[eEfFgGn%])?
61046104
\Z

Lib/test/test_decimal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ def test_formatting(self):
10831083
(',%', '123.456789', '12,345.6789%'),
10841084
(',e', '123456', '1.23456e+5'),
10851085
(',E', '123456', '1.23456E+5'),
1086+
# ... with '_' instead
1087+
('_', '1234567', '1_234_567'),
1088+
('07_', '1234.56', '1_234.56'),
1089+
('_', '1.23456789', '1.23456789'),
1090+
('_%', '123.456789', '12_345.6789%'),
10861091

10871092
# negative zero: default behavior
10881093
('.1f', '-0', '-0.0'),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Support the ``'_'`` digit separator in formatting of the integral part of
2+
:class:`~decimal.Decimal`'s. Patch by Sergey B Kirpichev.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy