mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-87790: support thousands separators for formatting fractional part of floats (#125304)
```pycon >>> f"{123_456.123_456:_._f}" # Whole and fractional '123_456.123_456' >>> f"{123_456.123_456:_f}" # Integer component only '123_456.123456' >>> f"{123_456.123_456:._f}" # Fractional component only '123456.123_456' >>> f"{123_456.123_456:.4_f}" # with precision '123456.1_235' ```
This commit is contained in:
parent
fa6a8140dd
commit
f39a07be47
9 changed files with 218 additions and 45 deletions
|
@ -515,11 +515,15 @@ class FormatTest(unittest.TestCase):
|
|||
error_msg = re.escape("Cannot specify both ',' and '_'.")
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
'{:,_}'.format(1)
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
'{:.,_f}'.format(1.1)
|
||||
|
||||
def test_with_an_underscore_and_a_comma_in_format_specifier(self):
|
||||
error_msg = re.escape("Cannot specify both ',' and '_'.")
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
'{:_,}'.format(1)
|
||||
with self.assertRaisesRegex(ValueError, error_msg):
|
||||
'{:._,f}'.format(1.1)
|
||||
|
||||
def test_better_error_message_format(self):
|
||||
# https://bugs.python.org/issue20524
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue