formatting a number as percentage

vsoler vicente.soler at gmail.com
Sun Feb 21 19:17:18 CET 2010


On Feb 21, 7:11 pm, TomF <tomf.sess... at gmail.com> wrote:
> On 2010-02-21 09:53:45 -0800, vsoler <vicente.so... at gmail.com> 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.000000%
>
> or if you want to suppress those trailing zeroes:
>
> >>> print "Grade is {0:.0%}".format(.87)
>
> Grade is 87%

Excellent, works perfect!!!



More information about the Python-list mailing list