From f1efd55e9d9afdc0bdee58c7b54dbff361e85363 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 11 Oct 2020 22:32:01 +0100 Subject: [PATCH] [Minor] Lua_util: Fix round function --- lualib/lua_util.lua | 8 ++++++-- 1 file 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 --[[[ -- 2.39.5