[Python-Dev] Change in Python 3's "round" behavior
Chris Angelico
rosuav at gmail.com
Sun Sep 30 19:41:22 EDT 2018
On Mon, Oct 1, 2018 at 9:36 AM Steven D'Aprano <steve at pearwood.info> wrote:
> Then we can add a keyword only argument to round:
>
> round(number, ndigits=0, *, mode=ROUND_HALF_EVEN)
>
> To use it, you can import the rounding mode you want from math:
>
> from math import ROUND_CEILING
> round(x, 3, mode=ROUND_CEILING)
I have no problem with this.
> and everyone is happy (he says optimistically).
And I am as dubious as you are about this :)
IMO, the biggest problem with round() is that it's TOO discoverable.
People reach for it when what they really should be using is string
formatting ("I want to display all these values to three decimal
places"), and then sometimes get bitten when something doesn't
actually display the way they think it will. When it's used correctly,
it's usually fine.
ChrisA
More information about the Python-Dev
mailing list