diff options
author | Georg Brandl <georg@python.org> | 2008-07-18 11:15:06 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-07-18 11:15:06 (GMT) |
commit | bf8998183918b19e5e9ed263244c9ab325a8bcc4 (patch) | |
tree | 3c9abb04c2957457fd3ef0318ebc1d83c44762ef /Doc | |
parent | 730c8185b9fc7af9acf0a873faaa694a527e5050 (diff) | |
download | cpython-bf8998183918b19e5e9ed263244c9ab325a8bcc4.zip cpython-bf8998183918b19e5e9ed263244c9ab325a8bcc4.tar.gz cpython-bf8998183918b19e5e9ed263244c9ab325a8bcc4.tar.bz2 |
Document the different meaning of precision for {:f} and {:g}.
Also document how inf and nan are formatted. #3404.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/string.rst | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 0e345e3..357cba3 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -387,10 +387,11 @@ zero-padding. This is equivalent to an *alignment* type of ``'='`` and a *fill* character of ``'0'``. The *precision* is a decimal number indicating how many digits should be -displayed after the decimal point for a floating point value. For non-number -types the field indicates the maximum field size - in other words, how many -characters will be used from the field content. The *precision* is ignored for -integer values. +displayed after the decimal point for a floating point value formatted with +``'f'`` and ``'F'``, or before and after the decimal point for a floating point +value formatted with ``'g'`` or ``'G'``. For non-number types the field +indicates the maximum field size - in other words, how many characters will be +used from the field content. The *precision* is ignored for integer values. Finally, the *type* determines how the data should be presented. @@ -418,7 +419,7 @@ The available integer presentation types are: | | the current locale setting to insert the appropriate | | | number separator characters. | +---------+----------------------------------------------------------+ - | None | the same as ``'d'`` | + | None | The same as ``'d'``. | +---------+----------------------------------------------------------+ The available presentation types for floating point and decimal values are: @@ -439,10 +440,13 @@ The available presentation types for floating point and decimal values are: +---------+----------------------------------------------------------+ | ``'g'`` | General format. This prints the number as a fixed-point | | | number, unless the number is too large, in which case | - | | it switches to ``'e'`` exponent notation. | + | | it switches to ``'e'`` exponent notation. Infinity and | + | | NaN values are formatted as ``inf``, ``-inf`` and | + | | ``nan``, respectively. | +---------+----------------------------------------------------------+ | ``'G'`` | General format. Same as ``'g'`` except switches to | - | | ``'E'`` if the number gets to large. | + | | ``'E'`` if the number gets to large. The representations | + | | of infinity and NaN are uppercased, too. | +---------+----------------------------------------------------------+ | ``'n'`` | Number. This is the same as ``'g'``, except that it uses | | | the current locale setting to insert the appropriate | @@ -451,7 +455,7 @@ The available presentation types for floating point and decimal values are: | ``'%'`` | Percentage. Multiplies the number by 100 and displays | | | in fixed (``'f'``) format, followed by a percent sign. | +---------+----------------------------------------------------------+ - | None | the same as ``'g'`` | + | None | The same as ``'g'``. | +---------+----------------------------------------------------------+ |