-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Description
Documentation
The documentation is missing a description of the behaviour of round
on Decimal
objects. It's worth documenting, since the behaviour (particularly with respect to the context) is non-obvious.
Of particular note:
- two-argument
round
respects the rounding mode from theDecimal
context. - single-argument
round
always does round-ties-to-even, ignoring information from the context
Python 3.12.0a4 (main, Jan 20 2023, 16:04:05) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal, getcontext, ROUND_DOWN
>>> getcontext().rounding = ROUND_DOWN
>>> round(Decimal('3.7')) # round-ties-to-even; context rounding ignored
4
>>> round(Decimal('3.7'), 0) # uses the context rounding
Decimal('3')
Linked PRs
tim-one and jagerber48
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir