Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting a float to a formatted outside of print command

0 views
Skip to first unread message

stephen_b

unread,
Nov 23, 2009, 4:15:07 PM11/23/09
to
I'd like to convert a list of floats to formatted strings. The
following example raises a TypeError:

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

Dan Bishop

unread,
Nov 23, 2009, 4:17:42 PM11/23/09
to
On Nov 23, 3:15 pm, stephen_b <redplusbluemakespur...@gmail.com>
wrote:

You meant:

x = '%.1f' % y

Philip Semanchuk

unread,
Nov 23, 2009, 4:25:51 PM11/23/09
to Python-list (General)

You're missing a percent sign:

x = '%.1f' % y

or:

print '%.1f' % 0.5


Hope this helps
Philip

stephen_b

unread,
Nov 23, 2009, 4:27:45 PM11/23/09
to
On Nov 23, 3:17 pm, Dan Bishop <danb...@yahoo.com> wrote:
> You meant:
>
> x = '%.1f' % y

Thanks, I'm a dufus today.

Vlastimil Brom

unread,
Nov 23, 2009, 4:28:53 PM11/23/09
to pytho...@python.org
2009/11/23 stephen_b <redplusblue...@gmail.com>:
> --
> http://mail.python.org/mailman/listinfo/python-list
Maybe
'%.1f' % y
?

hth
vbr

0 new messages