Converting a float to a formatted outside of print command

S

stephen_b

I'd like to convert a list of floats to formatted strings. The
following example raises a TypeError:

y = 0.5
x = '.1f' % y
 
P

Philip Semanchuk

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
 
V

Vlastimil Brom

2009/11/23 stephen_b said:
I'd like to convert a list of floats to formatted strings. The
following example raises a TypeError:

y = 0.5
x = '.1f' % y
Maybe
'%.1f' % y
?

hth
vbr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top