mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
bpo-45995: add "z" format specifer to coerce negative 0 to zero (GH-30049)
Add "z" format specifier to coerce negative 0 to zero. See https://github.com/python/cpython/issues/90153 (originally https://bugs.python.org/issue45995) for discussion. This covers `str.format()` and f-strings. Old-style string interpolation is not supported. Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
parent
dd207a6ac5
commit
b0b836b20c
16 changed files with 368 additions and 43 deletions
|
@ -6119,7 +6119,7 @@ topics = {'assert': 'The "assert" statement\n'
|
|||
'The general form of a *standard format specifier* is:\n'
|
||||
'\n'
|
||||
' format_spec ::= '
|
||||
'[[fill]align][sign][#][0][width][grouping_option][.precision][type]\n'
|
||||
'[[fill]align][sign][z][#][0][width][grouping_option][.precision][type]\n'
|
||||
' fill ::= <any character>\n'
|
||||
' align ::= "<" | ">" | "=" | "^"\n'
|
||||
' sign ::= "+" | "-" | " "\n'
|
||||
|
@ -6221,6 +6221,15 @@ topics = {'assert': 'The "assert" statement\n'
|
|||
' '
|
||||
'+-----------+------------------------------------------------------------+\n'
|
||||
'\n'
|
||||
'The "\'z\'" option coerces negative zero floating-point '
|
||||
'values to positive\n'
|
||||
'zero after rounding to the format precision. This option '
|
||||
'is only valid for\n'
|
||||
'floating-point presentation types.\n'
|
||||
'\n'
|
||||
'Changed in version 3.11: Added the "\'z\'" option (see also '
|
||||
'**PEP 682**).\n'
|
||||
'\n'
|
||||
'The "\'#\'" option causes the “alternate form” to be used '
|
||||
'for the\n'
|
||||
'conversion. The alternate form is defined differently for '
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue