Against PEP 240

Tim Peters tim.one at home.com
Thu May 31 00:38:25 EDT 2001


[Roman Suzi]
> Rounding and formating is a MUST in anything nrealy financial ;-)
> So, lets not put additional burden on the Python and
> just put "%11.2f" % round(var, 2) were due.

I doubt that's going to make Clark feel better, as I can't imagine a context
in which that code snippet would make good sense.  That's the kind of thing
he's doubtless suffering from:  well-intentioned attempts to worm around
problems too dimly understood.  "%" alone would introduce one rounding
error, and that's the best that can be done.  "round()" introduces at least
two rounding errors of its own (although you can't know that without
studying the implementation of round()), so all by itself is worse than just
printing the thing.  Even if Clark sticks to plain "%" and has an exactly
representable (in binary fp) value, he's still in a x-platform bind; e.g.,

>>> print "%11.2f" % 100.125

displays

     100.12

on most modern Unix boxes (following 754's nearest/even rounding), but
displays

     100.13

on others and on Windows (following add-a-half-and-chop rounding).  The
financial world has strict rules about how rounding is supposed to be done
too.

spend-6-months-writing-accounting-apps<wink>-ly y'rs  - tim







More information about the Python-list mailing list