[Python-ideas] Deprecate the round builtin

MRAB python at mrabarnett.plus.com
Thu Sep 27 00:07:01 CEST 2012

On 2012-09-26 21:17, M.-A. Lemburg wrote:
> 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.
If we're going to move 'round' into 'math' because it sometimes gives
results which puzzle naive users, shouldn't we do the same to 'float'?

More information about the Python-ideas mailing list