Calculates the minimum threshold for a given percentage and total value. This only works for percentages between 0 and 100 (inclusive).
(percentage: &Percentage, total_value: &usize)
| 75 | /// |
| 76 | /// This only works for percentages between 0 and 100 (inclusive). |
| 77 | pub fn calculate_minimum_threshold(percentage: &Percentage, total_value: &usize) -> usize { |
| 78 | let Percentage(percentage) = percentage; |
| 79 | let percentage = *percentage as usize; |
| 80 | let scaled_total = percentage * total_value; |
| 81 | |
| 82 | match scaled_total % 100 { |
| 83 | 0 => scaled_total / 100, |
| 84 | _ => (scaled_total / 100) + 1, |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /// Retains items based on the result of a authorization check evaluation. |
| 89 | /// |