This commit is contained in:
lx
2026-07-06 14:01:11 -04:00
commit c4f97d729d
16468 changed files with 935321 additions and 0 deletions
@@ -0,0 +1,22 @@
return function(num, sep, sepCount)
assert(type(num) == "number", "formatInteger expects a number; was given type: " .. type(num))
sep = sep or ","
sepCount = sepCount or 3
local parsedInt = string.format("%.0f", math.abs(num))
local firstSeperatorIndex = #parsedInt % sepCount
if firstSeperatorIndex == 0 then
firstSeperatorIndex = sepCount
end
local seperatorPattern = "(" .. string.rep("%d", sepCount) .. ")"
local seperatorReplacement = sep .. "%1"
local result = parsedInt:sub(1, firstSeperatorIndex) ..
parsedInt:sub(firstSeperatorIndex+1):gsub(seperatorPattern, seperatorReplacement)
if num < 0 then
result = "-" .. result
end
return result
end