By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

Get correct percentage

P: n/a
Hello,

This is actually a general programming question but I don't know which
newsgroup best to put it so please pardon me.

I've always been looking for the best way to get an accurate percentage
statistics.

For example, in a election scenario:

Person A gets 33 votes
Person B gets 33 votes
Person C gets 34 votes
Person D gets 35 votes

Total votes = 33 + 33 + 34 + 35 = 135
Percent for A = 0.244.... = 0.24 = 24%
Percent for B = 0.244... = 0.24 = 24%
Percent for C = 0.251... = 0.25 = 25%
Percent for D = 0.259... = 0.26 = 26%

Then add up the percentage values: 24 + 24 + 25 + 26 = 99
(where it should be 100)
So, does anybody have a way to get around this problem? How should I
calculate the percentage for each person so that the percentage will add up
to 100 in the end?

Thanks for your help
Happy New Year
Conax
Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
What you are seeing is rounding error. You can reduce the effect by using
more precision:

Percent for A = 0.244 = 24.4%
Percent for B = 0.244 = 24.4%
....

If that is not good enough then you should add the same disclaimer that
pollsters use to the effect that the results will not necessarily add up to
100% due to rounding error.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Conax" <Co******@hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
Hello,

This is actually a general programming question but I don't know which
newsgroup best to put it so please pardon me.

I've always been looking for the best way to get an accurate percentage
statistics.

For example, in a election scenario:

Person A gets 33 votes
Person B gets 33 votes
Person C gets 34 votes
Person D gets 35 votes

Total votes = 33 + 33 + 34 + 35 = 135
Percent for A = 0.244.... = 0.24 = 24%
Percent for B = 0.244... = 0.24 = 24%
Percent for C = 0.251... = 0.25 = 25%
Percent for D = 0.259... = 0.26 = 26%

Then add up the percentage values: 24 + 24 + 25 + 26 = 99
(where it should be 100)
So, does anybody have a way to get around this problem? How should I
calculate the percentage for each person so that the percentage will add up to 100 in the end?

Thanks for your help
Happy New Year
Conax

Jul 19 '05 #2

P: n/a
I think your percentages are accurate, but you simply
have to decide exactly how accurate you want them. Then
it becomes a decision of when (or if) to round. Any time
you round you will have a margin of error + or - a
certain amount.

Say you have 3 items with equal percentages. They could
each be represented as any of the following:

33%
33.3%
33.33%
33.333%
etc...

The more numbers to the right of the decimal, the greater
your degree of accuraccy.

Sincerely,
Invotion Engineering Team
Advanced Microsoft Hosting Solutions
http://www.Invotion.com
-----Original Message-----
Hello,

This is actually a general programming question but I don't know whichnewsgroup best to put it so please pardon me.

I've always been looking for the best way to get an accurate percentagestatistics.

For example, in a election scenario:

Person A gets 33 votes
Person B gets 33 votes
Person C gets 34 votes
Person D gets 35 votes

Total votes = 33 + 33 + 34 + 35 = 135
Percent for A = 0.244.... = 0.24 = 24%
Percent for B = 0.244... = 0.24 = 24%
Percent for C = 0.251... = 0.25 = 25%
Percent for D = 0.259... = 0.26 = 26%

Then add up the percentage values: 24 + 24 + 25 + 26 = 99
(where it should be 100)
So, does anybody have a way to get around this problem? How should Icalculate the percentage for each person so that the percentage will add upto 100 in the end?

Thanks for your help
Happy New Year
Conax
.

Jul 19 '05 #3

P: n/a
Thanks for your replies Mark and Invotion.

I was hoping someone would have a logic to somehow display percentage
without decimal points and yet can add up to 100%. But I am probably asking
too much, and should live with what you have suggested.

Thanks again for your help!

Regards
Conax
Jul 19 '05 #4

P: n/a
You could determine the difference from 100% and arbitrarily increase or
decrease some of the individual values. I wouldn't, but you could.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Conax" <Co******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Thanks for your replies Mark and Invotion.

I was hoping someone would have a logic to somehow display percentage
without decimal points and yet can add up to 100%. But I am probably asking too much, and should live with what you have suggested.

Thanks again for your help!

Regards
Conax

Jul 19 '05 #5

P: n/a

"Conax" <Co******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Thanks for your replies Mark and Invotion.

I was hoping someone would have a logic to somehow display percentage
without decimal points and yet can add up to 100%. But I am probably asking too much, and should live with what you have suggested.
[start sacarasm]
Yes, unfortunately none of have a suggestion for changing the laws of
mathametics. It's like asking to split up $3 between 2 people without using
cents.
[end sacarasm]

Don


Thanks again for your help!

Regards
Conax

Jul 19 '05 #6

P: n/a
"Don Verhagen" wrote:

Yes, unfortunately none of have a suggestion for changing
the laws of mathametics. It's like asking to split up $3
between 2 people without using cents.


Imagine the ramifications if you could do it...

Assuming i/j (or even 100*i/j) is an integer for each integer i and j, we
should be able to represent every rational number exactly (in binary as well
as in decimal). This, in turn, would imply a trivial solution to the
Discrete Log Problem, meaning we could trivially factor arbitrarily large
numbers. That would render RSA encryption (among other things, like
Diffie-Hellmann key exchanges) immediately obsolete.

Bye-bye public key encryption...
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #7

P: n/a
"Don Verhagen" <ne**@southeast-florida.com> wrote in message
news:bt************@ID-181477.news.uni-berlin.de...

"Conax" <Co******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Thanks for your replies Mark and Invotion.

I was hoping someone would have a logic to somehow display percentage
without decimal points and yet can add up to 100%. But I am probably asking
too much, and should live with what you have suggested.


[start sacarasm]
Yes, unfortunately none of have a suggestion for changing the laws of
mathametics. It's like asking to split up $3 between 2 people without

using cents.
[end sacarasm]


$3 between 2 people:

Person 1: $2
Person 2: $1
Person 3: $0

Poor person 3. ;)

Cheers!
Peter Foti
Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.