From 5e77ee8cb4977256697c4bf537b2531289aa967d Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:03:06 +0200 Subject: [PATCH] Performance improvements in Util.lua --- src/components/Util.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Util.lua b/src/components/Util.lua index dc424b7..eaafc1d 100644 --- a/src/components/Util.lua +++ b/src/components/Util.lua @@ -4,8 +4,13 @@ --- File created at [24/05/2021 09:57] --- -function math.round(num, numDecimalPlaces) - return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num)) +function math.round(value, numDecimalPlaces) + if numDecimalPlaces then + local power = 10^numDecimalPlaces + return math.floor((value * power) + 0.5) / (power) + else + return math.floor(value + 0.5) + end end function string.starts(String, Start) @@ -43,4 +48,4 @@ end function string.FirstUp(str) return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2) -end \ No newline at end of file +end