formatting a number as percentage

TomF tomf.sessile at gmail.com
Sun Feb 21 13:11:19 EST 2010


On 2010-02-21 09:53:45 -0800, vsoler <vicente.soler 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%




More information about the Python-list mailing list