Skip to content

Commit 2a6617d

Browse files
[3.13] gh-130664: support '_' (just as ',') in Decimal's formatting (GH-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]>
1 parent 2115e71 commit 2a6617d

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
@@ -6083,7 +6083,7 @@ def _convert_for_comparison(self, other, equality_op=False):
60836083
(?P<alt>\#)?
60846084
(?P<zeropad>0)?
60856085
(?P<minimumwidth>(?!0)\d+)?
6086-
(?P<thousands_sep>,)?
6086+
(?P<thousands_sep>[,_])?
60876087
(?:\.(?P<precision>0|(?!0)\d+))?
60886088
(?P<type>[eEfFgGn%])?
60896089
\Z

Lib/test/test_decimal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,11 @@ def test_formatting(self):
10591059
(',%', '123.456789', '12,345.6789%'),
10601060
(',e', '123456', '1.23456e+5'),
10611061
(',E', '123456', '1.23456E+5'),
1062+
# ... with '_' instead
1063+
('_', '1234567', '1_234_567'),
1064+
('07_', '1234.56', '1_234.56'),
1065+
('_', '1.23456789', '1.23456789'),
1066+
('_%', '123.456789', '12_345.6789%'),
10621067

10631068
# negative zero: default behavior
10641069
('.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)