8000 bpo-39096: Improve description of 'e', 'f' and 'g' presentation types… · python/cpython@c642374 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c642374

Browse files
authored
bpo-39096: Improve description of 'e', 'f' and 'g' presentation types (#23537)
* Improve description of 'e', 'f' and 'g' presentation types * Drop the 'E' from Scientific 'E' notation; remove >= 0 qualifications * Fix false statement that the alternate form is valid for Decimal * Nitpick: remove the Harvard/Oxford comma * Add note that the decimal point is also removed if no digits follow it, except in alternate form
1 parent 00a6568 commit c642374

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

Doc/library/string.rst

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ following:
384384

385385
The ``'#'`` option causes the "alternate form" to be used for the
386386
conversion. The alternate form is defined differently for different
387-
types. This option is only valid for integer, float, complex and
388-
Decimal types. For integers, when binary, octal, or hexadecimal output
387+
types. This option is only valid for integer, float and complex
388+
types. For integers, when binary, octal, or hexadecimal output
389389
is used, this option adds the prefix respective ``'0b'``, ``'0o'``, or
390-
``'0x'`` to the output value. For floats, complex and Decimal the
390+
``'0x'`` to the output value. For float and complex the
391391
alternate form causes the result of the conversion to always contain a
392392
decimal-point character, even if no digits follow it. Normally, a
393393
decimal-point character appears in the result of these conversions
@@ -476,20 +476,36 @@ with the floating point presentation types listed below (except
476476
``'n'`` and ``None``). When doing so, :func:`float` is used to convert the
477477
integer to a floating point number before formatting.
478478

479-
The available presentation types for floating point and decimal values are:
479+
The available presentation types for :class:`float` and
480+
:class:`~decimal.Decimal` values are:
480481

481482
+---------+----------------------------------------------------------+
482483
| Type | Meaning |
483484
+=========+==========================================================+
484-
| ``'e'`` | Exponent notation. Prints the number in scientific |
485-
| | notation using the letter 'e' to indicate the exponent. |
486-
| | The default precision is ``6``. |
485+
| ``'e'`` | Scientific notation. For a given precision ``p``, |
486+
| | formats the number in scientific notation with the |
487+
| | letter 'e' separating the coefficient from the exponent. |
488+
| | The coefficient has one digit before and ``p`` digits |
489+
| | after the decimal point, for a total of ``p + 1`` |
490+
| | significant digits. With no precision given, uses a |
491+
| | precision of ``6`` digits after the decimal point for |
492+
| | :class:`float`, and shows all coefficient digits |
493+
| | for :class:`~decimal.Decimal`. If no digits follow the |
494+
| | decimal point, the decimal point is also removed unless |
495+
| | the ``#`` option is used. |
487496
+---------+----------------------------------------------------------+
488-
| ``'E'`` | Exponent notation. Same as ``'e'`` except it uses an |
489-
| | upper case 'E' as the separator character. |
497+
| ``'E'`` | Scientific notation. Same as ``'e'`` except it uses |
498+
| | an upper case 'E' as the separator character. |
490499
+---------+----------------------------------------------------------+
491-
| ``'f'`` | Fixed-point notation. Displays the number as a |
492-
| | fixed-point number. The default precision is ``6``. |
500+
| ``'f'`` | Fixed-point notation. For a given precision ``p``, |
501+
| | formats the number as a decimal number with exactly |
502+
| | ``p`` digits following the decimal point. With no |
503+
| | precision given, uses a precision of ``6`` digits after |
504+
| | the decimal point for :class:`float`, and uses a |
505+
| | precision large enough to show all coefficient digits |
506+
| | for :class:`~decimal.Decimal`. If no digits follow the |
507+
| | decimal point, the decimal point is also removed unless |
508+
| | the ``#`` option is used. |
493509
+---------+----------------------------------------------------------+
494510
| ``'F'`` | Fixed-point notation. Same as ``'f'``, but converts |
495511
| | ``nan`` to ``NAN`` and ``inf`` to ``INF``. |
@@ -518,7 +534,10 @@ The available presentation types for floating point and decimal values are:
518534
| | the precision. |
519535
| | |
520536
| | A precision of ``0`` is treated as equivalent to a |
521-
| | precision of ``1``. The default precision is ``6``. |
537+
| | precision of ``1``. With no precision given, uses a |
538+
| | precision of ``6`` significant digits for |
539+
| | :class:`float`, and shows all coefficient digits |
540+
| | for :class:`~decimal.Decimal`. |
522541
+---------+----------------------------------------------------------+
523542
| ``'G'`` | General format. Same as ``'g'`` except switches to |
524543
| | ``'E'`` if the number gets too large. The |

0 commit comments

Comments
 (0)
0