How to show percentage
Mike Meyer
mwm at mired.org
Thu Sep 22 14:43:40 EDT 2005
"Sen-Lung Chen" <slchen at larc.ee.nthu.edu.tw> writes:
> 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 %
Python interprets '/' in an integer environment to return ints, not
floats. You can either turn one of your arguments into floats:
>>> float(1 * 100) / 3
33.333333333333336
This is going to change. Not sure when. You can ask for the new behavior:
>>> from __future__ import division
>>> 100 / 3
33.333333333333336
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list