Skip to content

Commit 3d402ce

Browse files
committed
address review: refs to format/f-strings, add f-string example
1 parent ad204cb commit 3d402ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Doc/library/decimal.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,18 @@ floating-point flying circus:
240240
>>> c % a
241241
Decimal('0.77')
242242

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

246247
.. doctest::
247248

248249
>>> format(Decimal('2.675'), "f")
249250
'2.675'
250251
>>> format(Decimal('2.675'), ".2f")
251252
'2.68'
253+
>>> f"{Decimal('2.675'):.2f}"
254+
'2.68'
252255
>>> format(Decimal('2.675'), ".2e")
253256
'2.68e+0'
254257
>>> with localcontext() as ctx:

0 commit comments

Comments
 (0)