[Python-Dev] Rounding float to int directly ...

Aahz aahz at pythoncraft.com
Fri Aug 4 05:22:00 CEST 2006


On Tue, Aug 01, 2006, Ron Adam wrote:
>
> I'm -1 on implicitly converting to an int when rounding.
> 
> One reason is if your rounded (to int type) number is then used in an 
> equation you my end up with a integer result when you wanted a floating 
> point result.
> 
>  >>> 23.5/5.2
> 4.5192307692307692
>  >>> round(23.5)/round(5.2)
> 4.7999999999999998
>  >>> round(23.5/5.2)
> 5.0
>  >>> int(round(23.5))/int(round(5.2))
> 4

That's not relevant to Py3K.  Which is where this discussion should
proably move because round() ain't changing in 2.x.
-- 
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