Floating point -> string conversions

John Fouhy jfouhy at paradise.net.nz
Thu Nov 18 20:46:31 EST 2004


Steve Holden <steve at holdenweb.com> wrote in message news:<t9Skd.57$nj.56 at lakeread01>...
> The fact that %s coerces things makes us expect more of other format 
> tokens, but what would you expect %d to do with 2147483648.5?

I'd expect it to give me "2147483648", since that would be consistent
with its other behaviour :-)

(eg: eval('"%d" % 1.5') == '1')

I guess what annoys me is that python encourages you to not worry
about the difference between ints and longs (which is great) (unless
you're doing high performance computing), but then something like this
can cause code to stop working just because you've passed a border
which is almost invisible.

(of course, this means that one solution which I would be happy with
is for python to reject any non-integer/long arguments to "%d" :-) )

-- 
John.



More information about the Python-list mailing list