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

Diff for: Lib/_pydecimal.py

+1-1
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

Diff for: Lib/test/test_decimal.py

+5
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'),
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)