I have 3 numbers, a Min ( 18 ), a Max ( 24 ), and a variable in-between ( Let’s say 21 ).

How do I get the percentage of how far along the variable is between those two numbers?

At 21 it’s 50% but I don’t know how to calculate it.

I have 3 numbers, a Min ( 18 ), a Max ( 24 ), and a variable in-between ( Let’s say 21 ).

How do I get the percentage of how far along the variable is between those two numbers?

At 21 it’s 50% but I don’t know how to calculate it.

1 Like

for simple terms,

you can calculate the difference between max and min, then max - (wanted value) = 2ndDiff, and simply

(2ndDiff / maxMinDiff) * 100 = 50%

24 - 18 = 6

24 - 21 = 3

3 / 6 = 0.5, * 100 = 50

3 Likes

```
function calculatePercentage(min, max, var)
local distance = max - min
local progress = var - min
local percentage = (progress / distance) * 100
return percentage
end
```

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.