Reputation: 129
A method calculates the percentage of 2 given in points (for example 15/20 and 16/20) and returns the total %.
But the problem is when i try to add weight to those values. Meaning standard weight factor 1 and weight factor 2 for both values are set on 1 (normal % calculation).
But how exactly do i add weights to them? Assuming i want to add a weight factor of 2 to the first value and leave the second one to standard(1). (So a certain score is more important then a other, hence the % changes.)
Calculation with integers
input 15 and 16 (score on /20)
With default weight factors (1 & 1) the overal percentage would be 77
If the weight factors are changed to 2 (for 15) and standard 1 (for 16) the total % would be 76.
What would be the best way to implement this, cannot find anything about this.
Regards.
Upvotes: 0
Views: 96
Reputation: 55344
Firstly,
((15/20)+(16/20)) / 2 = 0.775 (77.5%)
instead of 77% (you shouldn't round until you perform a final calculation, e.g. for a grading system, different assignment types would have different weights and systems should never round until they display a final percentage.)
To weight one amount as 2 instead of 1, you would take the amount into account twice:
((15/20)+(15/20)+(16/20)) / 3 = 0.766 (76.6%)
(I know this because I have great knowledge of Pearson's PowerSchool)
Upvotes: 2