mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 16:49:01 -06:00
formatBigNum prettifier
This commit is contained in:
parent
452879ebab
commit
6609b642dc
16
funcs.lua
16
funcs.lua
@ -56,9 +56,19 @@ end
|
|||||||
|
|
||||||
function formatBigNum(number)
|
function formatBigNum(number)
|
||||||
-- returns a string representing a number with commas as thousands separator (e.g. 12,345,678)
|
-- returns a string representing a number with commas as thousands separator (e.g. 12,345,678)
|
||||||
local s = string.format("%d", number)
|
local s
|
||||||
local pos = string.len(s) % 3
|
if type(number) == "number" then
|
||||||
if pos == 0 then pos = 3 end
|
s = string.format("%d", number)
|
||||||
|
elseif type(number) == "string" then
|
||||||
|
if not tonumber(number) then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
s = number
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local pos = Mod1(string.len(s), 3)
|
||||||
return string.sub(s, 1, pos)
|
return string.sub(s, 1, pos)
|
||||||
.. string.gsub(string.sub(s, pos+1), "(...)", ",%1")
|
.. string.gsub(string.sub(s, pos+1), "(...)", ",%1")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user