From 8eb1acd0825015940a4e4591c74944f2df42311e Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Thu, 2 Jan 2020 14:31:46 +0100 Subject: [PATCH] Fixed round function not properly working in some locales, closes #258 --- common/modules/math.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/modules/math.lua b/common/modules/math.lua index 6b4a4a5d..99a87631 100644 --- a/common/modules/math.lua +++ b/common/modules/math.lua @@ -1,7 +1,8 @@ ESX.Math = {} ESX.Math.Round = function(value, numDecimalPlaces) - return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", value)) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(value * mult + 0.5) / mult end -- credit http://richard.warburton.it