diff options
author | John Belmonte <john@neggie.net> | 2022-04-11 14:34:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 14:34:18 (GMT) |
commit | b0b836b20cb56c225874a4a39ef895f89ab2970f (patch) | |
tree | b333cd2e9ee95021e1fc3b45eee2da0b7ac0ee35 /Doc | |
parent | dd207a6ac52d4bd9a71cf178fc1d5c17a6f07aff (diff) | |
download | cpython-b0b836b20cb56c225874a4a39ef895f89ab2970f.zip cpython-b0b836b20cb56c225874a4a39ef895f89ab2970f.tar.gz cpython-b0b836b20cb56c225874a4a39ef895f89ab2970f.tar.bz2 |
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>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/string.rst | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 78bd167..35e9bc1 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -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 |