2,875
edits
m (Add functions from Module:Shared) |
m (Add formatNum from Module:Shared) |
||
Line 17: | Line 17: | ||
} | } | ||
--Adds commas | |||
function p.formatnum(number) | |||
if tonumber(number) == nil then | |||
return number | |||
else | |||
local result = number | |||
while true do | |||
-- Format in blocks of 3 digits at a time until formatting is complete | |||
local k | |||
result, k = string.gsub(result, "^(-?%d+)(%d%d%d)", '%1,%2') | |||
if k == 0 then | |||
break | |||
end | |||
end | |||
return result | |||
end | |||
end | |||
--- Parses a string representation of a number with suffixes | --- Parses a string representation of a number with suffixes | ||
-- @param str (string) The string to parse. | -- @param str (string) The string to parse. |
edits