formatting a number as percentage

vsoler vicente.soler at gmail.com
Tue Feb 23 14:36:23 EST 2010


On Feb 22, 8:32 pm, Hans Mulder <han... at xs4all.nl> wrote:
> Günther Dietrich wrote:
> > 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...
>
> > 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%
>
> Only the OP knows which one is more appropriate for his use case.
>
> Hope this helps,
>
> -- HansM

Great!!!

Thank you



More information about the Python-list mailing list