aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-11 22:32:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-11 22:32:01 +0100
commitf1efd55e9d9afdc0bdee58c7b54dbff361e85363 (patch)
treef8663dd5c45b2eecea819029d58b2b79249f384d /lualib/lua_util.lua
parent30996f906090b064d52644e8dca374b6f806c5a6 (diff)
downloadrspamd-f1efd55e9d9afdc0bdee58c7b54dbff361e85363.tar.gz
rspamd-f1efd55e9d9afdc0bdee58c7b54dbff361e85363.zip
[Minor] Lua_util: Fix round function
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua8
1 files changed, 6 insertions, 2 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 521424966..bcb697e2c 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -124,10 +124,14 @@ end
-- @return {number} rounded number
--]]
--- Robert Jay Gould http://lua-users.org/wiki/SimpleRound
+-- modified version from Robert Jay Gould http://lua-users.org/wiki/SimpleRound
exports.round = function(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult) / mult
+ if num >= 0 then
+ return math.floor(num * mult + 0.5) / mult
+ else
+ return math.ceil(num * mult - 0.5) / mult
+ end
end
--[[[