Re: formatting a number as percentage

2010-02-23 Thread Lawrence D'Oliveiro
In message <6819f2f8-7a9e-4ea4-a936-c4e00394b...@g28g2000yqh.googlegroups.com>, vsoler wrote: > I'm trying to print .7 as 70% Just to be perverse: (lambda x : (lambda s : s[:s.index(".")] + s[s.index(".") + 1:] + "%")("%.2f" % x).lstrip("0"))(.7) :) -- http://mail.python.org/mailman/list

Re: formatting a number as percentage

2010-02-23 Thread Günther Dietrich
Hans Mulder wrote: >> Did you try this: >> > print('%d%%' % (0.7 * 100)) >> 70% > >That method will always round down; TomF's method will round to >the nearest whole number: > > >>> print "%d%%" % (0.698 * 100) >69% > >>> print "{0:.0%}".format(.698) >70% It was intended as a hint to this w

Re: formatting a number as percentage

2010-02-23 Thread vsoler
On Feb 22, 8:32 pm, Hans Mulder wrote: > Günther Dietrich wrote: > > vsoler wrote: > > >> I'm trying to print .7 as 70% > >> I've tried: > > >> print format(.7,'%%') > >> .7.format('%%') > > >> but neither works. I don't know what the syntax is... > > > Did you try this: > > print('%d%%' % (

Re: formatting a number as percentage

2010-02-22 Thread Hans Mulder
Günther Dietrich wrote: vsoler wrote: I'm trying to print .7 as 70% I've tried: print format(.7,'%%') .7.format('%%') but neither works. I don't know what the syntax is... Did you try this: print('%d%%' % (0.7 * 100)) 70% That method will always round down; TomF's method will round to

Re: formatting a number as percentage

2010-02-21 Thread Günther Dietrich
vsoler wrote: >I'm trying to print .7 as 70% >I've tried: > >print format(.7,'%%') >.7.format('%%') > >but neither works. I don't know what the syntax is... Did you try this: >>> print('%d%%' % (0.7 * 100)) 70% Best regards, Günther -- http://mail.python.org/mailman/listinfo/python-list

Re: formatting a number as percentage

2010-02-21 Thread vsoler
On Feb 21, 7:11 pm, TomF wrote: > On 2010-02-21 09:53:45 -0800, vsoler said: > > > I'm trying to print .7 as 70% > > I've tried: > > > print format(.7,'%%') > > .7.format('%%') > > > but neither works. I don't know what the syntax is... > >>> print "Grade is {0:%}".format(.87) > > Grade is 87.000

Re: formatting a number as percentage

2010-02-21 Thread Mark Dickinson
On Feb 21, 5:53 pm, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... Assuming that you're using Python 2.6 (or Python 3.x): >>> format(.7, '%') '70.00%' >>> format(.7, '.2%') '70.

Re: formatting a number as percentage

2010-02-21 Thread TomF
On 2010-02-21 09:53:45 -0800, vsoler said: I'm trying to print .7 as 70% I've tried: print format(.7,'%%') .7.format('%%') but neither works. I don't know what the syntax is... print "Grade is {0:%}".format(.87) Grade is 87.00% or if you want to suppress those trailing zeroes: print

Re: formatting a number as percentage

2010-02-21 Thread Chris Colbert
>>> print('%.0f%%' % (0.7*100)) 70% On Sun, Feb 21, 2010 at 12:53 PM, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... > > Can you help? > > Thank you > -- > http://mail.python.org/ma

formatting a number as percentage

2010-02-21 Thread vsoler
I'm trying to print .7 as 70% I've tried: print format(.7,'%%') .7.format('%%') but neither works. I don't know what the syntax is... Can you help? Thank you -- http://mail.python.org/mailman/listinfo/python-list