diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-11 22:32:01 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-11 22:32:01 +0100 |
commit | f1efd55e9d9afdc0bdee58c7b54dbff361e85363 (patch) | |
tree | f8663dd5c45b2eecea819029d58b2b79249f384d /lualib/lua_util.lua | |
parent | 30996f906090b064d52644e8dca374b6f806c5a6 (diff) | |
download | rspamd-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.lua | 8 |
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 --[[[ |