17,105
edits
Falterfire (talk | contribs) (added p.fractionpair) |
(formatnum: Use faster variant of function) |
||
Line 151: | Line 151: | ||
end | end | ||
--Adds commas | --Adds commas | ||
function p.formatnum(number) | 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 | |||
result, k = string.gsub(result, "^(-?%d+)(%d%d%d)", '%1,%2') | |||
if k == 0 then | |||
break | |||
end | |||
end | |||
return result | |||
end | |||
end | end | ||