formatting a number as percentage
Mark Dickinson
dickinsm at gmail.com
Sun Feb 21 13:15:18 EST 2010
On Feb 21, 5:53 pm, vsoler <vicente.so... at gmail.com> 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.000000%'
>>> format(.7, '.2%')
'70.00%'
Or see TomF's response for how to use this with the str.format method.
--
Mark
More information about the Python-list
mailing list