Skip to content

Commit

Permalink
address review: refs to format/f-strings, add f-string example
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Jan 24, 2025
1 parent ad204cb commit 3d402ce
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Doc/library/decimal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,18 @@ floating-point flying circus:
>>> c % a
Decimal('0.77')

Decimals can be formatted in fixed-point or scientific notation, using the same
formatting syntax (see :ref:`formatspec`) as builtin :class:`float` type:
Decimals can be formatted (with :func:`format` built-in or :ref:`f-strings`) in
fixed-point or scientific notation, using the same formatting syntax (see
:ref:`formatspec`) as builtin :class:`float` type:

.. doctest::

>>> format(Decimal('2.675'), "f")
'2.675'
>>> format(Decimal('2.675'), ".2f")
'2.68'
>>> f"{Decimal('2.675'):.2f}"
'2.68'
>>> format(Decimal('2.675'), ".2e")
'2.68e+0'
>>> with localcontext() as ctx:
Expand Down

0 comments on commit 3d402ce

Please sign in to comment.