Odd math related issue.

John Machin sjmachin at lexicon.net
Mon Jul 21 08:36:39 EDT 2008


On Jul 21, 10:21 pm, Alexandru Palade
<alexandru.pal... at sellerengine.com> wrote:
>
> Another thing, you could have just added a dot after the constant in
> order to promote the expression to be evaluated as float. As in
>     percentage = bytes_transferred / /self/.__sessions[path].total_bytes
> * 100.
> (notice the last dot)
>

True, you get a float result, but not a very useful one:

>>> a = 2
>>> b = 11
>>> a / b * 100 # OP's problem
0
>>> a / b * 100. # Your suggestion; same as (a / b) *100.
0.0
>>> a * 100 / b # Fredrik's suggestion
18
>>> a * 100. / b # What you probably meant
18.181818181818183
>>>



More information about the Python-list mailing list