GeezerVison is showing github.com — changes to decimal doc · python/cpython@bec8d83
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Doc/library/string.rst +14Lines changed: 14 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -629,6 +629,20 @@ after the decimal point. The rounding mode for :class:`float` matches that |
629 | 629 | of the :func:`round` builtin. For :class:`~decimal.Decimal`, the rounding |
630 | 630 | mode of the current :ref:`context <decimal-context>` will be used. |
631 | 631 |
|
| 632 | + |
| 633 | +.. note:: |
| 634 | + |
| 635 | +The :class:`~decimal.Decimal` type has special formatting behavior: |
| 636 | + |
| 637 | +* When using ``__format__`` (f-strings, ``format()``, ``str.format()``), |
| 638 | + Decimal formats with maximum precision only when precision is **omitted** |
| 639 | + in ``f``, ``e``, or ``g`` format types. If precision is explicitly specified, |
| 640 | +it is respected. |
| 641 | + |
| 642 | +* When using ``%`` formatting (old-style string formatting with the ``%`` operator), |
| 643 | +Decimal values are first converted to :class:`float`, which may result in |
| 644 | +precision loss. |
| 645 | + |
632 | 646 | The available presentation types for :class:`complex` are the same as those for |
633 | 647 | :class:`float` (``'%'`` is not allowed). Both the real and imaginary components |
634 | 648 | of a complex number are formatted as floating-point numbers, according to the |
|