Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Converting a float to a formatted outside of print command

Reply
Thread Tools

Converting a float to a formatted outside of print command

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

y = 0.5
x = '.1f' % y
 
Reply With Quote
 
 
 
 
Dan Bishop
Guest
Posts: n/a
 
      11-23-2009
On Nov 23, 3:15*pm, stephen_b <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
 
Philip Semanchuk
Guest
Posts: n/a
 
      11-23-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

 
Reply With Quote
 
stephen_b
Guest
Posts: n/a
 
      11-23-2009
On Nov 23, 3:17*pm, Dan Bishop <(E-Mail Removed)> wrote:
> You meant:
>
> x = '%.1f' % y


Thanks, I'm a dufus today.
 
Reply With Quote
 
Vlastimil Brom
Guest
Posts: n/a
 
      11-23-2009
2009/11/23 stephen_b <(E-Mail Removed)>:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
converting 'float (*)[4]' to 'const float**' mathieu C++ 9 09-15-2007 09:10 AM
converting a signed float into unsigned float Dipesh Batheja Ruby 1 11-16-2006 07:29 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments