[Python-ideas] Deprecate the round builtin

Ben Finney ben+python at benfinney.id.au
Thu Sep 27 02:45:43 CEST 2012

"M.-A. Lemburg" <mal at egenix.com> writes:

> Mark Dickinson wrote:
> >>>> round(2.675, 2)
> > 2.67
> > 
> > So you end up explaining again and again that computing binary
> > approximations to decimal rounds of binary approximations of decimal
> > halfway cases is a bad idea.
> But that's the fault of round(), is it ? ;-) It's more one of
> educating people of what to expect when working with floats.

It's the fault of the two-parameter ‘round’, yes. It is an attractive
nuisance that appears to promise one thing but doesn't deliver, and
makes it easy to do the wrong thing by mistake.

Where feasible, and where it doesn't unreasonably restrict
functionality, IMO Python should make it difficult to do the wrong thing
by mistake.

> Your example is a typical case that comes up when people enter
> examples and wonder why they don't see the expected results.

I think this is an argument that deprecating, and eventually removing,
the two-parameter form of ‘round’, would be helpful overall.

 \        “Consider the daffodil. And while you're doing that, I'll be |
  `\              over here, looking through your stuff.” —Jack Handey |
_o__)                                                                  |
Ben Finney

More information about the Python-ideas mailing list