Floating point -> string conversions

Batista, Facundo FBatista at uniFON.com.ar
Fri Nov 12 07:48:28 EST 2004


[Steve Holden]
#- I don't think so. The fact of the matter is that a %d format token 
#- explicitly expects an integral value.
#- 
#- 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?

%d expects only an integral value. If would accept other data types, should
be explicited in the documentation (as is explicited with %s, for example).

I think that here's a bug, but don't know where:

Should %d accept only integer values? So this is a bug:

>>> '%d' % 2147483647.0
'2147483647'

Should %d accept also floats, and make the conversion? So there're two bugs:

- In the doc (it's not explicited that it should accept a other data types)

- In this behaviour difference:

>>> '%d' % 2147483647.0
'2147483647'
>>> '%d' % 2147483648.0

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    '%d' % 2147483648.0
TypeError: int argument required


.	Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041112/1f8d8272/attachment.html>


More information about the Python-list mailing list