[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)

Aahz aahz at pythoncraft.com
Tue Aug 1 16:09:24 CEST 2006


On Tue, Aug 01, 2006, M.-A. Lemburg wrote:
>
> You often have a need for controlled rounding when doing financial
> calculations or in situations where you want to compare two floats
> with a given accuracy, e.g. to work around rounding problems ;-)
>
> The usual approach is to use full float accuracy throughout the
> calculation and then apply rounding a certain key places.

That's what Decimal() is for.

(Note that I don't care all that much about round(), but I do think we
want to canonicalize Decimal() for all purposes in standard Python where
people care about accuracy.  Additional float features can go into
NumPy.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan


More information about the Python-Dev mailing list