473,508 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Odd math related issue.

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>

Jul 21 '08 #1
1 1295
On Jul 21, 3:52*am, Fredrik Lundh <fred...@pythonware.comwrote:
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
Jul 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1067
by: Bhavin Patel | last post by:
Hi i have one table 2 user tires to select records from that table. 1st user select some records 2nd tries to select some records . so second user is not able to see records selected by 1st...
9
1777
by: Ugur ASLAN | last post by:
Hello, I want to implement a class structure that can take a querystring and the value of querysting can be called as myClass.getQuery("test").value. I know that I can do it like...
1
2900
by: dpulgarin | last post by:
Hi, My name is Diego. I am a new member of the Forum and relatively new to IIS v6.0. I'd like to take this opportunity to post a new message about an issue I've been experiencing lately. ...
2
1181
by: pintu | last post by:
Hi Friends. in my application i am facing problems in maintaining session state. I am working on asp.net 2.0. So i didnt checked the session on each page and almost the project is completed. Now...
10
2586
by: Schraalhans Keukenmeester | last post by:
I suspect the following problem IS hosting provider specific, but they haven't been able to help me out so far. Perhaps I am doing something wrong and someone is able to spot the issue... Here...
1
1197
by: SubhaSundar | last post by:
Hi, We are testing a web application developed in Java. There is a web page with a link which takes us to a popup window. In that window, we will be checking a checkbox and there will be only one...
0
841
by: Robert Rawlins | last post by:
if you divide two integers, you'll get an integer back (in Python 2.X, Hey </F> That worked a charm mate, thanks for the info. </R>
0
150
by: Fredrik Lundh | last post by:
sahasranaman wrote: you mean that a.0 / 3 * 100 works in your Python version? that's interesting. (maybe you should at least skim the the thread before you jump in?)
35
42941
by: ValValVal | last post by:
Please sorry for my dumb question but I cannot find information on how I can change settings so that in NetBeans 6.1 I can edit blue guarded areas. I read in FAQ NetBeans Wiki:...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.