-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
round digits issues #9464
Comments
In this case, I have to vote for the "least surprising" behavior. To me, Rounding (especially literals) based on binary representation also makes tl;dr: I think most users, especially new ones, would consider |
@tlycken, I agree: it does seem odd to insist upon exact rounding to an inexact number. As no one has spoken up to defend Python-style rounding, I've noted the current behaviour in the docs (#10018). |
As this seems to have been more-or-less settled, I'm going to close it. If there are any objections, please re-open. |
How should the
digits
argument ofround
(andfloor
,ceil
andtrunc
) behave? Decimal fractions are typically not representable by floating point numbers, and so the "decimal representation" may round in a different direction than the true number. This has been mentioned before in #8728, and on julia-users.For example:
For reference:
round(8.315,2)
returns8.31
(i.e. it gives the "correct rounding").8.315.round(2)
returns8.32
Some options:
a. correct rounding (as done by Python).
b. "round the representation" (as we do at the moment)
c. get rid of the digits argument (or just make it base-2).
If we go for correct rounding, this could give unexpected results for
ceil
,floor
andtrunc
, e.g.floor(8.2, 1) == 8.1
.The text was updated successfully, but these errors were encountered: