Skip to content

Commit 886b2e5

Browse files
authored
bpo-39096: Format specification documentation fixes for numeric types (GH-23575)
1 parent 6104013 commit 886b2e5

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Doc/library/string.rst

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ The available presentation types for :class:`float` and
514514
| | this rounds the number to ``p`` significant digits and |
515515
| | then formats the result in either fixed-point format |
516516
| | or in scientific notation, depending on its magnitude. |
517+
| | A precision of ``0`` is treated as equivalent to a |
518+
| | precision of ``1``. |
517519
| | |
518520
| | The precise rules are as follows: suppose that the |
519521
| | result formatted with presentation type ``'e'`` and |
@@ -528,16 +530,19 @@ The available presentation types for :class:`float` and
528530
| | removed if there are no remaining digits following it, |
529531
| | unless the ``'#'`` option is used. |
530532
| | |
533+
| | With no precision given, uses a precision of ``6`` |
534+
| | significant digits for :class:`float`. For |
535+
| | :class:`~decimal.Decimal`, the coefficient of the result |
536+
| | is formed from the coefficient digits of the value; |
537+
| | scientific notation is used for values smaller than |
538+
| | ``1e-6`` in absolute value and values where the place |
539+
| | value of the least significant digit is larger than 1, |
540+
| | and fixed-point notation is used otherwise. |
541+
| | |
531542
| | Positive and negative infinity, positive and negative |
532543
| | zero, and nans, are formatted as ``inf``, ``-inf``, |
533544
| | ``0``, ``-0`` and ``nan`` respectively, regardless of |
534545
| | the precision. |
535-
| | |
536-
| | A precision of ``0`` is treated as equivalent to a |
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`. |
541546
+---------+----------------------------------------------------------+
542547
| ``'G'`` | General format. Same as ``'g'`` except switches to |
543548
| | ``'E'`` if the number gets too large. The |
@@ -550,12 +555,18 @@ The available presentation types for :class:`float` and
550555
| ``'%'`` | Percentage. Multiplies the number by 100 and displays |
551556
| | in fixed (``'f'``) format, followed by a percent sign. |
552557
+---------+----------------------------------------------------------+
553-
| None | Similar to ``'g'``, except that fixed-point notation, |
554-
| | when used, has at least one digit past the decimal point.|
555-
| | The default precision is as high as needed to represent |
556-
| | the particular value. The overall effect is to match the |
557-
| | output of :func:`str` as altered by the other format |
558-
| | modifiers. |
558+
| None | For :class:`float` this is the same as ``'g'``, except |
559+
| | that when fixed-point notation is used to format the |
560+
| | result, it always includes at least one digit past the |
561+
| | decimal point. The precision used is as large as needed |
562+
| | to represent the given value faithfully. |
563+
| | |
564+
| | For :class:`~decimal.Decimal`, this is the same as |
565+
| | either ``'g'`` or ``'G'`` depending on the value of |
566+
| | ``context.capitals`` for the current decimal context. |
567+
| | |
568+
| | The overall effect is to match the output of :func:`str` |
569+
| | as altered by the other format modifiers. |
559570
+---------+----------------------------------------------------------+
560571

561572

0 commit comments

Comments
 (0)