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

Simon Burton simon at arrowtheory.com
Wed Aug 2 03:58:06 CEST 2006


On Sat, 29 Jul 2006 15:44:33 +1200
Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Michael Urman wrote:
> > The fact that
> > round returns a float rather than an int, while intentional, does not
> > feature prominently in one's mine when the first version yielded the
> > expected results.
> 
> As an aside, does anyone else think that it would be
> useful to have a builtin which rounds and converts to
> an int in one go? Whenever I use round(), I almost
> always want the result as an int, and making me do
> it in two steps seems unnecessarily bothersome.

It's not even clear to me that int(round(x)) is always the
nearest integer to x.
Is it always true that float(some_int)>=some_int ?  (for positive values).

(ie. I am wondering if truncating the float representation
of an int always gives back the original int).

Simon.

-- 
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 2 6249 6940
http://arrowtheory.com 


More information about the Python-Dev mailing list