Round


Adds a function to the math library to round a number (num) to any optional number of decimal places (idp).

math.round(num, idp)

function math.round(num, idp)

assert(tonumber(num), 'Round expects a number.')

local mult = 10 ^ (idp or 0)
if num >= 0 then
return math.floor(num * mult + 0.5) / mult
else
return math.ceil(num * mult - 0.5) / mult
end

end