troubleshooting Question

# Getting the % of several numbers and make them add up to 100%

C#Editors IDEs
There are a certain number of kickouts in a soccer game.
The kickouts can be won like so
2. Or by taking it down with your feet/chest
Now The above can be done by either team.
So lets say there are 4 possibilities on how the kickout can be won:
Team 1 - Heading the Ball
Team 1 - Feet/Chest
Team 2 - Heading the Ball
Team 2 - Feet/Chest
If there are 20 kickouts then the breakdown could be as follows:
Team 1 - 3/20 by Heading it
Team 1 - 6/20 by Using feet/chest
Team 2 - 5/20 by Heading it
Team 2 - 6/20 by Using feet/chest

I need to get 3/20, 6/20, 5/20 and 6/20 as a %.  I am doing the following:

double dPercentage = ((double)nNumber1 / (double)nNumber2) * 100;
dRoundedDownPercentage = Math.Floor(dPercentage);

This method always rounds the numbers down so the resulting %s will not all add up to 100%.  If I round up the %s then when I add up all the %s they come to shightly more than 100%.

How can I do this so the four %s add up exactly to 100%.

Thanks

Harry

Join the community to see this answer!
###### Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.