Hi… I Created A Fuction. It’s Return A Rounded Number
function Round(Number,RoundNumber)
return math.floor(Number/RoundNumber+0.5)*RoundNumber
end
you can make this
print(Round(1.153,0.1)) -- 1.1
print(Round(1.153),0.01) -- 1.15
print(Round(1.153,0.001)) -- 1.153
I have a suggested addition to your code.
function Round(Number,RoundNumber)
RoundNumber = RoundNumber or 1
return math.floor(Number/RoundNumber+0.5)*RoundNumber
end
print(Round(1.153, 0.1)) -- 1.2
print(Round(1.153)) -- 1
And also a question.
If it truly rounds this to 1.1, then I don’t think it works.
3 Likes
Scottifly
(Scottifly)
#3
Or if you use the Search tool up top you could find other ways of doing it as well:
<Is there anyway to round up a number to only 2 decimals?
Operatik
(Operatik)
#4
math.round
seems to be a very real function.