Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Converting a float to a formatted outside of print command

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


redplusbluemakespurple at gmail

Nov 23, 2009, 1:15 PM

Post #1 of 6 (209 views)
Permalink
Converting a float to a formatted outside of print command

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

y = 0.5
x = '.1f' % y
--
http://mail.python.org/mailman/listinfo/python-list


danb_83 at yahoo

Nov 23, 2009, 1:17 PM

Post #2 of 6 (210 views)
Permalink
Re: Converting a float to a formatted outside of print command [In reply to]

On Nov 23, 3:15 pm, stephen_b <redplusbluemakespur...@gmail.com>
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 meant:

x = '%.1f' % y
--
http://mail.python.org/mailman/listinfo/python-list


iurisilvio at gmail

Nov 23, 2009, 1:24 PM

Post #3 of 6 (207 views)
Permalink
Re: Converting a float to a formatted outside of print command [In reply to]

You forgot a % simbol in your string:

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

[]s
iurisilvio

On Mon, Nov 23, 2009 at 7:15 PM, stephen_b <redplusbluemakespurple [at] gmail
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>


philip at semanchuk

Nov 23, 2009, 1:25 PM

Post #4 of 6 (209 views)
Permalink
Re: Converting a float to a formatted outside of print command [In reply to]

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

--
http://mail.python.org/mailman/listinfo/python-list


redplusbluemakespurple at gmail

Nov 23, 2009, 1:27 PM

Post #5 of 6 (163 views)
Permalink
Re: Converting a float to a formatted outside of print command [In reply to]

On Nov 23, 3:17 pm, Dan Bishop <danb...@yahoo.com> wrote:
> You meant:
>
> x = '%.1f' % y

Thanks, I'm a dufus today.
--
http://mail.python.org/mailman/listinfo/python-list


vlastimil.brom at gmail

Nov 23, 2009, 1:28 PM

Post #6 of 6 (209 views)
Permalink
Re: Converting a float to a formatted outside of print command [In reply to]

2009/11/23 stephen_b <redplusbluemakespurple [at] gmail>:
> I'd like to convert a list of floats to formatted strings. The
> following example raises a TypeError:
>
> y = 0.5
> x = '.1f' % y
> --
> http://mail.python.org/mailman/listinfo/python-list
Maybe
'%.1f' % y
?

hth
vbr
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.