How to show percentage

Steve Holden steve at holdenweb.com
Mon Sep 26 09:45:00 CEST 2005


Steve Holden wrote:
> Sen-Lung Chen wrote:
> 
>>Dear All:
>> 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 %
>> Thanks
>>
> 
> 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.
> 
> regards
>   Steve

... apart from the obvious syntax error, that is. Sigh.

     pct = (100.0 * v) / N

regards
  Steve
-- 
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 mailing list