[Python-Dev] trunc()

Eric Smith eric+python-dev at trueblade.com
Sun Jan 27 20:21:23 CET 2008


Guido van Rossum wrote:
> On Jan 27, 2008 9:26 AM, Andrea Griffini <agriff at tin.it> wrote:
>> Anyway I want just to say that if "implicit" conversion from float
>> to integer goes away then what happens to formatting conversion ?
>> Removing that too IMO would break a lot of code and it's IMO very
>> difficult to help fixing that.
> 
> The formatting code could assign specific meanings. I suspect though
> that it was never meant to be possible to use %d with a float -- it
> just is one of the artifacts of using implicit conversion, and one not
> well-thought through. Note:
> 
>>>> "%.0f" % 3.9999999999
> '4'
>>>> "%d" % 3.9999999999
> '3'
> 
> I think the latter is wrong and confusing.

format() has the same issue, for the same reason:

>>> format(3.9, 'f')
'3.900000'
>>> format(3.9, 'd')
'3'

I never noticed this before, and it's a definite error.  PEP 3101 says 
the valid types for float are 'eEfFgGn%' and an empty string.  I'll 
remove the integer conversion in the float formatter.

Eric.



More information about the Python-Dev mailing list