Search code examples
phpmathmaxminscoring

reference value in php for scoring (min x = 1, max y = 100)


I'd like to do a tiny scoring, but I stumble at maths. I guess you will handle it :-) I have a few values: e.g. 124, 426, 100, 24, 41. The highest shell be MaxScore = 100 (here 426), and the minimum MinScore = 1 (here 24). Every value (here 124,100,41) between MaxScore and MinScore shell get an own Score, related to min and max.

With php max(), I get

$max = max(124, 426, 100, 24, 41);

426 as the highest and with min()

$min = min(124, 426, 100, 24, 41);

24 as the lowest value. Fine.

Next step could be like: 426 = 100 and 24 = 1. But the rest? What's the calculation? As you can see, it's not a programmer problem (not yet), rather a maths-issue. I hope I did make myself clear. Thank you!


Solution

  • Ok this seems to work. Might have put more parenthesis in than needed.

    $new_val = 1 + (($val - $min) * (99 / ($max - $min)))