From a2c8d47db243dba41b34aa93f43a9958bfe9ce94 Mon Sep 17 00:00:00 2001 From: Eric Mauser Date: Fri, 17 Jun 2016 23:32:55 +0200 Subject: [PATCH] add round function --- env/functions.lua | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 env/functions.lua diff --git a/env/functions.lua b/env/functions.lua new file mode 100644 index 00000000..2e5d7d05 --- /dev/null +++ b/env/functions.lua @@ -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