lua - How to get decimals to round down on the half
lua, rounding
Solution
function round(val, decimal)
local exp = decimal and 10^decimal or 1
return math.ceil(val * exp - 0.5) / exp
end
Problem
I'm using this function to round currently: ``` function round(val, decimal) if (decimal) then return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) else return math.floor(val+0.5) end end ``` That function works perfectly except that when a number lands on .5 like 5.5 or 1000.5 or 7.5 I need it to round down instead of up. What changes would I have to make to the function to make that happen?