I'm having some logic/math problems in a program I'm trying to fix. So, suppose I have three values, 30, 25 and -15. The sum of these values is always going to be 100%. But I also need to know which percentile out of 100 the -15 is, if there is any, since the negative numbers need to be counted in the total sum. If I count the sum as 40, as in adding 25 and (-15), it's easy, but I wouldn't be able to know which percentile was the -15 because it is now a +10. I've used this formula: P% * X = Y where P is what % of X is Y but for it I would have to count 40 as being total, but I don't think I can just sum the numbers up. Does this make any sense? I'm sorry for not being able to be clear enough.
Asked
Active
Viewed 2,423 times
0
-
Are these for displaying to the user? I think you will have to tell us what these figures mean before we can give you a sensible answer. – TonyK Feb 03 '20 at 17:40
-
This is so that the calculus always equals 100 so that the system can function properly. In this algorithm, the program receives a number of transactions and some of them can be negative. In this operation, it needs to know which percentile out of 100 each one of the transactions were. So if I get 50 and (-50), the program needs to calculate how many % was 50 and how many % was -50 out of 100%. – DootyBooty Feb 03 '20 at 17:57
-
So, with your values $30, 25$ and $-15$, do you expect the answer $33.333\ldots%$? (one third of all values is negative!)? – Feb 03 '20 at 18:15
2 Answers
0
The only (somewhat) sensible calculation I can give you is the following: just follow the same rules that you follow when all the numbers are positive:
- Add them all together ($30+25-15=40$)
- Divide each of them by the total sum and multiply by $100\%$: $\frac{30}{40}\times 100\%=75\%, \frac{25}{40}\times 100\%=62.5\%, -\frac{15}{40}\times 100\%=-37.5\%$.
As you see, some percentages will end up being negative. In this case, you end up with the following percentages: $75\%, 62.5\%, -37.5\%$ which do add up to $100\%$.
It is the whole other question whether this calculation gives you what you need. (I cannot tell from your question alone.)
Also note, if your numbers add up to $0$, this calculation does not make sense.
-
Thank you. Sadly, I've confirmed the algorithm was way more complex than what the question had asked. Though you were great help, so I'll accept your answer. Thanks again! – DootyBooty Feb 03 '20 at 18:10
-
@DootyBooty If my solution is wrong or misleading you shouldn't have accepted it - I cannot even delete it now that it is accepted! – Feb 03 '20 at 18:14
0
"Percentile" does not mean
- "percentage ratio of the sample value to mean"
- "percentage ratio of the sample value to the sum."
It means
- "percentage fraction of samples less than the given sample" or
- "percentage fraction of samples less than or equal to the given sample" or
- rounded or interpolated variations thereof, dependent on who you ask.
For your samples, the percentile of each sample depends on the definition, but
- for $-15$ is $0$ at least, $34$ at most;
- for $25$ is $33$ at least, $67$ at most; and
- for $30$ is $66$ at least, $100$ at most.
K B Dave
- 7,912