diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 7052985..b491bcf 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -862,6 +862,14 @@ Decimal objects :const:`Rounded`. If given, applies *rounding*; otherwise, uses the rounding method in either the supplied *context* or the current context. + .. method:: __format__(format) + + Format as string using the given ``format``. + + This makes it possible to specify format string for a :class:`Decimal` + object when using :meth:`str.format`. For a complete list of formatting + directives, see :ref:`formatspec`. + .. _logical_operands_label: diff --git a/Doc/library/string.rst b/Doc/library/string.rst index f9da5fa..ca167c9 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -451,8 +451,9 @@ The available presentation types for floating point and decimal values are: | | The precise rules are as follows: suppose that the | | | result formatted with presentation type ``'e'`` and | | | precision ``p-1`` would have exponent ``exp``. Then | - | | if ``-4 <= exp < p``, the number is formatted | - | | with presentation type ``'f'`` and precision | + | | if ``m <= exp < p`` where ``m`` is -4 for floats and -6 | + | | for :class:`Decimals `, the number is | + | | formatted with presentation type ``'f'`` and precision | | | ``p-1-exp``. Otherwise, the number is formatted | | | with presentation type ``'e'`` and precision ``p-1``. | | | In both cases insignificant trailing zeros are removed |