# Converting a number into a scale of 5

Hello Devforum! Recently I’ve been trying to figure out a rating system for my game. Although I’m stuck on the cleanliness subject. The thing is I have a garbage count value, which holds the amount of garbage. I want to be able to make that garbage count into a scale of 1-5, with 5 being least garbage and 1 being most. Is this even possible? If not please tell me so I don’t waste my time looking! Thanks in advance!

Well what are its current maximum/minimum values? You’ll need those to be able to scale the value between 1 and 5.

if your talking about the garbage count maximum and minimum then the minimum is 0 while there is no maximum to garbage. This is why its very tricky to get it down to scale of 5

In that case, what value should represent 5?

I don’t know where your getting that a value is representing 5. I have a rating value, this value can be anywhere from 1 to 5. As of right now I’m trying to figure out how to convert the unpredictable garbage count into this scale to represent the value. I don’t know how else to explain this

You can’t scale a value if you don’t know its bounds. Here’s a dynamic function I just wrote which takes 5 inputs, the value to be scaled, the lower and upper bounds of its current scale and the lower and upper bounds of its desired scale, the function will return the value rescaled.

``````local function scaleValue(value, oldLower, oldUpper, newLower, newUpper)
local ratio = (value - oldLower)/(oldUpper - oldLower)
local scaledValue = ((newUpper - newLower) * ratio) + newLower
return scaledValue
end
``````
``````local scaledValue = scaleValue(10, 0, 100, 0, 50)
print(scaledValue) --5 as expected.
``````

In this example the value is 10, its current bounds are 0 - 100 and its desired bounds are 0 - 50, the function outputs a rescaled value of 5.