473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I calculate Percent complete?

I have two long values that are passed in an event. I would like to
calculate percent complete as an int but am not quite sure how. Do I need to
convert them to doubles and then use the Math class to round the result?
Nov 16 '05 #1
4 61729
With a real you could just do (CompleteItems / TotalItems)*100 to get a
percentage. You could also go (CompleteItems*100 / TotalItems) to get the
same result. But you're working with long variables so the first option
will give you zero since the (CompleteItems / TotalItems) is a fraction
between 0 and 1. But you can use the second option, as long as
CompleteItems * 100 doesn't go over 9,223,372,036,854,775,807. Unless
you're writing a program to calculate Bill Gates net worth, you should be
pretty safe.

So just multiply CompleteItems by 100, then divide by TotalItems.

Michael C.
"Bill" <nf*@nospam.com> wrote in message
news:u5**************@TK2MSFTNGP09.phx.gbl...
I have two long values that are passed in an event. I would like to
calculate percent complete as an int but am not quite sure how. Do I need to convert them to doubles and then use the Math class to round the result?

Nov 16 '05 #2
This should work
int percentcomplete = Convert.ToInt32(long1 / long2);
Nov 16 '05 #3
Sorry
int percentcomplete = Convert.ToInt32(longcompleted / longtotal * 100);
Nov 16 '05 #4
Won't work. You lose your fractional percentage (longcompleted / longtotal)
to rounding, and zero * 100 always equals zero. Use this instead:

int percentcomplete = Convert.ToInt32(longcompleted*100 / longtotal);

That way you don't lose your percentage to rounding.

Michael C.

"Bill English" <nu****@comcast.net> wrote in message
news:56**********************************@microsof t.com...
Sorry:
int percentcomplete = Convert.ToInt32(longcompleted / longtotal * 100);

Nov 16 '05 #5

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

Similar topics

22
by: Bryan Rickard | last post by:
I wrote a simple program in VB6 to copy all the files from a directory on a CD-ROM to my hard disk. There are about 10 files, each about 30MB. The program uses Get and Put to get data from the...
4
by: Bill | last post by:
I have some values that I want to display as percent, such as the retail price/wholesale price. In some instances, the wholesale price is zero, so I get a division by zero error. What can I do...
2
by: mhodkin | last post by:
I created a query in which I have grouped data by City. I wish to calculate the percent of each value, e.g. City/(Total count of all Cities), in tbe next column of the query. I can't seem to...
4
by: dmisen | last post by:
I have data on air pollution coming from sources across the country, and control options for reducing pollution from each source. The example below shows data for: - 2 sources (plant_ID "001" and...
6
by: Programador | last post by:
I'm getting this error when running this program: Cannot calculate rate using the arguments provided Module Module1 Sub Main() Rate(360, -694.44444444444446, 244274.69178082192) End Sub
5
lee123
by: lee123 | last post by:
hi there i cant figure out how to get a percentage from a form i have created maybe one of you people can help me. the form i have has all of this on it: date,new orders,new, used,replacement...
3
ChaseCox
by: ChaseCox | last post by:
Hi all, I have a problem that I have been looking at for a couple days now and I can not quite get it to work. I would like to calculate the cumulative percent failure of a certain product in...
5
by: cecil | last post by:
Hi All, I have a report sectioned/grouped by year with number fields (i,e attendance). I would like to calculate percent difference of attendance for each year. Thanks in advance, Cecil
0
by: maxpirate | last post by:
From Access Vba how can i show percent complete as a rectangle with color filled upto the percent in the powerpoint slide
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.