How to show percentage
Terry Hancock
hancock at anansispaceworks.com
Thu Sep 22 17:50:09 EDT 2005
On Thursday 22 September 2005 12:51 pm, 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
In addition to needing a floating point value as other
posters have noted, you're going to need a format string,
e.g.:
>>> print "%5.2f%%" % (100.0/3)
33.33%
Note the need to escape "%" as it is normally the format
specifier character.
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list