Is there a way to choose what decimal point math.floor/ceil round to? Like make it round to the 100th or 1000th instead?
✓ ANSWER ACCEPTED
Can you choose what decimal math.floor and math.ceil round to?
1 answer
✓ Accepted answer
No, but you can do some fancy math with powers of ten to get that behavior:
function ceilBase(num, decimals)
if not decimals then decimals = 0 end
local pow = 10^decimals
num = num*pow
num = math.ceil(num)
num = num/pow
return num
end
And the same for math.floor.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
A simple method, if you're comfortable with the math, is to simply say "math.ceil(num * 10) / 10" (for rounding to a single decimal point)