mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +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
|
@ -309,7 +309,7 @@ non-empty format specification typically modifies the result.
|
|||
The general form of a *standard format specifier* is:
|
||||
|
||||
.. productionlist:: format-spec
|
||||
format_spec: [[`fill`]`align`][`sign`][#][0][`width`][`grouping_option`][.`precision`][`type`]
|
||||
format_spec: [[`fill`]`align`][`sign`][z][#][0][`width`][`grouping_option`][.`precision`][`type`]
|
||||
fill: <any character>
|
||||
align: "<" | ">" | "=" | "^"
|
||||
sign: "+" | "-" | " "
|
||||
|
@ -380,6 +380,15 @@ following:
|
|||
+---------+----------------------------------------------------------+
|
||||
|
||||
|
||||
.. index:: single: z; in string formatting
|
||||
|
||||
The ``'z'`` option coerces negative zero floating-point values to positive
|
||||
zero after rounding to the format precision. This option is only valid for
|
||||
floating-point presentation types.
|
||||
|
||||
.. versionchanged:: 3.11
|
||||
Added the ``'z'`` option (see also :pep:`682`).
|
||||
|
||||
.. index:: single: # (hash); in string formatting
|
||||
|
||||
The ``'#'`` option causes the "alternate form" to be used for the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue