add round function

This commit is contained in:
Eric Mauser
2016-06-17 23:32:55 +02:00
parent cfc074f951
commit a2c8d47db2
+9
View File
@@ -0,0 +1,9 @@
-- a real "round" instead of ceil or floor
function round(input, places)
if not places then places = 0 end
if type(input) == "number" and type(places) == "number" then
local pow = 1
for i = 1, places do pow = pow * 10 end
return floor(input * pow + 0.5) / pow
end
end