From: Vsevolod Stakhov Date: Sun, 11 Oct 2020 21:32:01 +0000 (+0100) Subject: [Minor] Lua_util: Fix round function X-Git-Tag: 2.7~249 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f1efd55e9d9afdc0bdee58c7b54dbff361e85363;p=rspamd.git [Minor] Lua_util: Fix round function --- 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 --[[[