[Python-Dev] PEP 3101: floats format 'f' and 'F'
Eric Smith
eric+python-dev at trueblade.com
Wed Jul 16 17:15:40 CEST 2008
Mark Dickinson wrote:
> On Wed, Jul 16, 2008 at 3:35 PM, Eric Smith
> <eric+python-dev at trueblade.com> wrote:
>> Does anyone know why 'F' is the same as 'f'? Wouldn't it make more sense to
>> either drop it, or make it convert the exponent to upper case
>
> What exponent? Isn't the point of 'f' formatting that there is no exponent?
There's no exponent until the number gets large. I haven't looked up
how big the number has to get. On my Mac, it's somewhere between 1e50
and 1e60.
$ ./python.exe
Python 3.0b1+ (py3k:64984:64985, Jul 15 2008, 20:17:06)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '%f' % 1e100
'1e+100'
>>> '%F' % 1e100
'1e+100'
>>> '%f' % 1.2
'1.200000'
str.format() works the same.
> In C, the only difference seems to be that a NaN or infinity formatted with '%F'
> is turned into "NAN" or "INF" instead of "nan" or "inf".
Not so in Python.
>>> '%f' % float('nan')
'nan'
>>> '%F' % float('nan')
'nan'
But it is the case with 'e':
>>> '%e' % float('nan')
'nan'
>>> '%E' % float('nan')
'NAN'
More information about the Python-Dev
mailing list