Module:Money
Appearance
This module is intended for formatting the amount of Money into different denominations (right now only til Billions). Used on {{Money }}.
local p = {}
--Function to determine if string is empty value
local function isEmpty(s)
return s == nil or s == ''
end
--Function to determine if string is empty value
local function isNotZero(s)
return s ~= 0 and s ~= "00"
end
local function formatString(num)
if (num>999) then
if num>9999 then
if num>999999 then
if num>999999999 then
if num>99999999999999 then
return string.sub(tostring(num), 1, -5).." × 10<sup>"..string.sub(tostring(num), -2, -1).."</sup>"
end
if isNotZero(string.sub(tostring(num), -9, -8)) then
return string.sub(tostring(num), 1, -10).."."..string.sub(tostring(num), -9, -8).." Billion"
end
return string.sub(tostring(num), 1, -10).." Billion"
end
if isNotZero(string.sub(tostring(num), -6, -5)) then
return string.sub(tostring(num), 1, -7).."."..string.sub(tostring(num), -6, -5).." Million"
end
return string.sub(tostring(num), 1, -7).." Million"
end
return string.sub(tostring(num), 1, -4).."k"
end
return string.sub(tostring(num), 1, -4)..","..string.sub(tostring(num), -3)
end
return tostring(num)
end
--uses the template as a wrapper, grabbing any arguments passed to the template
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrapper="Template:Money"
})
return p._main(args, frame)
end
function p._main(args, frame)
frame = frame or mw.getCurrentFrame()
local quantity = tonumber(args[1])
return formatString(quantity)
end
return p