I have a series of prices in a table that is calculated automatically based on an average health which leaves numbers such as 142, 174, 229, 4320.
for i, v in pairs(priceTbl) do local avgHealth = (v["Health"][1] + v["Health"][2] + v["Health"][3])/3 v["Price"] = math.floor(avgHealth * 1.3) end
How does one achieve making it so that when the raw price is calculated, it gets rounded to 50?
Divide/multiply a number before putting it through math.floor
:
function round(n, toNearest) toNearest = toNearest or 1 return math.floor(n / toNearest + 0.5) * toNearest end print(round(5.3)) -- 5 print(round(122, 50)) -- 100 print(round(125, 50)) -- 150