diff options
author | Eric Smith <eric@trueblade.com> | 2010-11-25 16:08:06 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2010-11-25 16:08:06 (GMT) |
commit | 984bb58000df9cdba438c7ecb0bae5ad67878696 (patch) | |
tree | 87077ab2bbe949b5241ed9db5f2073572094ffde /Doc | |
parent | c1d98d685032dd831ced32463b3f88cce6af4067 (diff) | |
download | cpython-984bb58000df9cdba438c7ecb0bae5ad67878696.zip cpython-984bb58000df9cdba438c7ecb0bae5ad67878696.tar.gz cpython-984bb58000df9cdba438c7ecb0bae5ad67878696.tar.bz2 |
Issue #7094: Add alternate ('#') flag to __format__ methods for float, complex and Decimal. Allows greater control over when decimal points appear. Added to make transitioning from %-formatting easier. '#g' still has a problem with Decimal which I'll fix soon.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/string.rst | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index b785fc2..5b69fe7 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -350,9 +350,18 @@ following: | | positive numbers, and a minus sign on negative numbers. | +---------+----------------------------------------------------------+ -The ``'#'`` option is only valid for integers, and only for binary, octal, or -hexadecimal output. If present, it specifies that the output will be prefixed -by ``'0b'``, ``'0o'``, or ``'0x'``, respectively. + +The ``'#'`` option causes the "alternate form" to be used for the +conversion. The alternate form is defined differently for different +types. This option is only valid for integer, float, complex and +Decimal types. For integers, when binary, octal, or hexadecimal output +is used, this option adds the prefix respective ``'0b'``, ``'0o'``, or +``'0x'`` to the output value. For floats, complex and Decimal the +alternate form causes the result of the conversion to always contain a +decimal-point character, even if no digits follow it. Normally, a +decimal-point character appears in the result of these conversions +only if a digit follows it. In addition, for ``'g'`` and ``'G'`` +conversions, trailing zeros are not removed from the result. The ``','`` option signals the use of a comma for a thousands separator. For a locale aware separator, use the ``'n'`` integer presentation type |