Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(math): group digits #338

Merged
merged 5 commits into from
May 25, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion imports/math/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ 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 useDot? boolean
---@return string
function math.groupdigits(number, useDot) -- credit http://richard.warburton.it
local divider = useDot and '.' or ','
local left,num,right = string.match(number,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1' .. divider):reverse())..right
Copy link
Member

@thelindat thelindat May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well be divider or seperator as the arg (not useDot), and then just do '%1' .. (divider or ',').

end

return lib.math