[Python-ideas] Deprecate the round builtin

M.-A. Lemburg mal at egenix.com
Wed Sep 26 22:17:36 CEST 2012

Mark Dickinson wrote:
> On Wed, Sep 26, 2012 at 8:36 PM, M.-A. Lemburg <mal at egenix.com> wrote:
>> It's actually quite common in finance and time calculations to
>> round to the nearest say basis point, cent or say micro second
>> in calculations
> That's exactly where the problems creep in, though.  Naive users
> expect rounding to give 'correct' results for decimal halfway cases,
> and then are surprised when it doesn't.
>>>> 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.

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

In calculations, statistics, numeric, etc. such corner cases are
not all that common, so things are not as bad as they may appear
on first sight.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Sep 26 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2012-10-29: PyCon DE 2012, Leipzig, Germany ...            33 days to go
2012-10-23: Python Meeting Duesseldorf ...                 27 days to go
2012-09-26: Released mxODBC.Connect 2.0.1 ...     http://egenix.com/go34
2012-09-25: Released mxODBC 3.2.1 ...             http://egenix.com/go33

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-ideas mailing list