473,666 Members | 2,392 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_transfer red,
/self/.__sessions[path].total_bytes))

percentage = bytes_transferr ed /
/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_transferr ed * 100 / total_bytes

</F>

Jul 21 '08 #1
1 1307
On Jul 21, 3:52*am, Fredrik Lundh <fred...@python ware.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_transfer red,
/self/.__sessions[path].total_bytes))
* * * * percentage = bytes_transferr ed /
/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_transferr ed * 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
1074
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 user. till operation is not completed by 1st user on selected records. Can you sugest somthing that solve my problem
9
1782
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 myClass.getQuery("test") and get the value of "test" querystring. But actually, this is an example only. In order to my class library organized I need a structure like this. I search internet and documents for ASP and Vbscript, as far as I found is that in...
1
2904
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. Hopefully, you experts would be able to shed some light. Problem Description: I keep receiving the following error message when I try to connect to or access an IIS Instance from my Windows XP workstation using the "Internet Information Services...
2
1186
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 problem is like after 20 minutes the session gets ended.so session related errors are coming when any operation like insert or update is performed after that 20 minutes. how can i redirect that page to login page after session timeout.I hav to...
10
2602
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 goes. The actual path of the root dir of my account with hosting provider (H.P.) is: /usr/local/psa/home/vhosts/mydomain.com/ The webroot is a subdir of the root: /usr/local/psa/home/vhosts/mydomain.com/httpdocs. Include files go in:
1
1201
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 Close button, which will close that window. Then again we are back to the same old web page with the same link. If we click the same link, the checkbox is unchecked without retaining the value. But this scenario is working fine in developer's...
0
851
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
43074
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: FaqFormEditingGuardedBlocks that I had to change something in Properties->Code ,but I really can't figure out what this should be. Thanks in advance.
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4192
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.