473,507 Members | 9,962 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 1294
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
1776
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
1195
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
42940
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
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
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
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5039
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
4702
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
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
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.