Odd math related issue.

Dan Bishop danb_83 at yahoo.com
Tue Jul 22 04:34:57 CEST 2008


On Jul 21, 3:52 am, Fredrik Lundh <fred... at pythonware.com> wrote:
> Robert Rawlins wrote:
> > I’ve got what seems to me to be a totally illogical math issue here
> > which I can’t figure out. Take a look at the following code:
>
> >         /self/.__logger.info(/"%i / %i"/ % (bytes_transferred,
> > /self/.__sessions[path].total_bytes))
>
> >         percentage = bytes_transferred /
> > /self/.__sessions[path].total_bytes * 100
>
> >         /self/.__logger.info(/"%i"/ % percentage)
>
> > Seems fairly straight forward, you would think. It takes two values and
> > calculates the percentage of one from the other, however, percentage
> > always comes back as ‘0’ for some reason, look at this log output.
>
> if you divide two integers, you'll get an integer back (in Python 2.X,
> at least).  quick fix:
>
>       percentage = bytes_transferred * 100 / total_bytes
>
> </F>

The most wonderful statement in the Python language is

from __future__ import division



More information about the Python-list mailing list