Skip to content

Commit

Permalink
Merge pull request #3 from ArdentLeKhey/ArdentLeKhey-performance-patc…
Browse files Browse the repository at this point in the history
…h-round

Performance improvements in Util.lua
  • Loading branch information
ArdentLeKhey committed Apr 16, 2024
2 parents dbba7d7 + 5e77ee8 commit 82b7fd3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Util.lua
Expand Up @@ -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)
Expand Down Expand Up @@ -43,4 +48,4 @@ end

function string.FirstUp(str)
return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2)
end
end

0 comments on commit 82b7fd3

Please sign in to comment.