Module:FormatNumber

local p = {}

p.formatNumber = function(number) -- if it was called via then number is a frame object and args[1] is the first argument if type(number) == 'table' then number = number.args[1] end local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')

-- reverse the int-string and append a separator to all blocks of 3 digits int = int:reverse:gsub("(%d%d%d)", "%1 ")

-- reverse the int-string back remove an optional separator and put the -- optional minus and fractional part back return minus .. int:reverse:gsub("^ ", "") .. fraction end

return p