-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Document the behaviour of Decimal.__round__ #101575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The effect of the current context precision is also worth noting: >>> round(Decimal(1.1), 27)
Decimal('1.100000000000000088817841970')
>>> round(Decimal(1.1), 28)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>] |
I agree that this should be documented, although it is hinted in the pure Python implementation but not in the online documentation:
Footnotes |
@mdickinson Where do you think it should be documented? Create a new entry for the |
@OTheDev I was thinking of the |
May I suggest first adjusting the behavior and then cementing it in the documentation? A different behavior for ~round() versus ~round(0) or round(Decimal(x),) vs. round(Decimal(x),0) or more generally having a 'context' steering something and sometimes ignoring it is trapping on a high level. Math and computers are complex enough, users need clear and consistent functionalities as good as possible. |
Users are not expected to use In addition to Index entries for both |
(cherry picked from commit 7dd8c37) Co-authored-by: Owain Davies <[email protected]>
(cherry picked from commit 7dd8c37) Co-authored-by: Owain Davies <[email protected]>
Thanks @OTheDev for the PR. As merged, it documents PRs to document support of the other functions are welcome, but as far as I know they don't have similarly “interesting” behaviour. |
Uh oh!
There was an error while loading. Please reload this page.
Documentation
The documentation is missing a description of the behaviour of
round
onDecimal
objects. It's worth documenting, since the behaviour (particularly with respect to the context) is non-obvious.Of particular note:
round
respects the rounding mode from theDecimal
context.round
always does round-ties-to-even, ignoring information from the contextLinked PRs
The text was updated successfully, but these errors were encountered: