How to show percentage
steve at holdenweb.com
Mon Sep 26 09:45:00 CEST 2005
Steve Holden wrote:
> Sen-Lung Chen wrote:
>> I have a question of show percentage.
>>For example ,I want to show the percentage of 1/3 = 33.33%
>> I use the 1*100/3 = 33
>>it is 33 not 33.33 , how to show the 33.33 %
> You should by now know enough answers. The easiest way to ensure that
> the result is floating point is to cast it as
> pct = 100.0 * v) / N
> This is guaranteed to work in all past and future Python versions
> without setting any options. Then you can format is using the % operator.
... apart from the obvious syntax error, that is. Sigh.
pct = (100.0 * v) / N
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org
More information about the Python-list