mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-87790: support thousands separators for formatting fractional part of Decimal (#132202)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
0c3e3da195
commit
90a5b4402b
3 changed files with 28 additions and 1 deletions
|
@ -1089,6 +1089,15 @@ class FormatTest:
|
|||
('07_', '1234.56', '1_234.56'),
|
||||
('_', '1.23456789', '1.23456789'),
|
||||
('_%', '123.456789', '12_345.6789%'),
|
||||
# and now for something completely different...
|
||||
('.,', '1.23456789', '1.234,567,89'),
|
||||
('._', '1.23456789', '1.234_567_89'),
|
||||
('.6_f', '12345.23456789', '12345.234_568'),
|
||||
(',._%', '123.456789', '12,345.678_9%'),
|
||||
(',._e', '123456', '1.234_56e+5'),
|
||||
(',.4_e', '123456', '1.234_6e+5'),
|
||||
(',.3_e', '123456', '1.235e+5'),
|
||||
(',._E', '123456', '1.234_56E+5'),
|
||||
|
||||
# negative zero: default behavior
|
||||
('.1f', '-0', '-0.0'),
|
||||
|
@ -1162,6 +1171,10 @@ class FormatTest:
|
|||
# bytes format argument
|
||||
self.assertRaises(TypeError, Decimal(1).__format__, b'-020')
|
||||
|
||||
# precision or fractional part separator should follow after dot
|
||||
self.assertRaises(ValueError, format, Decimal(1), '.f')
|
||||
self.assertRaises(ValueError, format, Decimal(1), '._6f')
|
||||
|
||||
def test_negative_zero_format_directed_rounding(self):
|
||||
with self.decimal.localcontext() as ctx:
|
||||
ctx.rounding = ROUND_CEILING
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue