[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Aug 1 13:19:03 CEST 2006
M.-A. Lemburg wrote:
> I suppose you don't know about the optional argument
> to round that lets you round up to a certain decimal ?!
Yes, I know about, but I rarely if ever use it.
Rounding a binary float to a number of decimal
places seems a fundamentally ill-considered thing
to do anyway. What are the use cases for it,
given that one can easily select a number of decimal
places when formatting a number for display?
> If we were to follow your suggestion, we'd have round()
> return an integer when called without the argument and
> a float when called with the argument.
No, round() wouldn't have that option at all. If
you wanted it, you would use fround() instead,
which would have the option and return a float
always.
This would be a Py3k thing, obviously. If done
before then, the new function would have to be
given a different name.
--
Greg
More information about the Python-Dev
mailing list