Get correct percentage

C

Conax

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
 
M

Mark Schupp

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.
 
I

Invotion

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
 
C

Conax

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
 
M

Mark Schupp

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

Don Verhagen

Conax said:
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
 
D

Dave Anderson

Don Verhagen said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top