Converting a float to a formatted outside of print command

Philip Semanchuk philip at semanchuk.com
Mon Nov 23 16:25:51 EST 2009


On Nov 23, 2009, at 4:15 PM, stephen_b wrote:

> I'd like to convert a list of floats to formatted strings. The
> following example raises a TypeError:
>
> y = 0.5
> x = '.1f' % y



You're missing a percent sign:

x = '%.1f' % y

or:

print '%.1f' % 0.5


Hope this helps
Philip




More information about the Python-list mailing list