Skip to content

Commit

Permalink
feat(imports/math): groupdigits (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigoalie authored May 25, 2023
1 parent 467e7f5 commit 4fed5dc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion imports/math/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ function math.tohex(n, upper)
return upper and n:upper() or n
end

return lib.math
---Converts input number into grouped digits
---@param number number
---@param seperator? string
---@return string
function math.groupdigits(number, seperator) -- credit http://richard.warburton.it
local left,num,right = string.match(number,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1' .. (seperator or ',')):reverse())..right
end

return lib.math

0 comments on commit 4fed5dc

Please sign in to comment.