Floating point -> string conversions
John Fouhy
jfouhy at paradise.net.nz
Wed Nov 10 22:35:29 EST 2004
I have another related question...
>>> pow(2, 31)
2147483648L
>>> '%d' % 2147483647.0 # python will convert to int
'2147483647'
>>> '%d' % 2147483648.0 # too big for an int, so error.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: int argument required
>>> '%d' % long(2147483648.0) # but yet, no trouble accepting a long.
'2147483648'
>>> '%d' % int(2147483648.0) # and int() converts to long anyway
'2147483648'
Is this a bug?
(python 2.3.4)
--
John.
More information about the Python-list
mailing list