Editing Module:Currency
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 3: | Line 3: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = frame:getParent().args |
local args = frame:getParent().args |
||
local a = args[1] or args.Amount or args.amount or '0' |
|||
val = tonumber(a) |
|||
return p.parse(val) |
|||
end |
end |
||
function p.parse(a) |
function p.parse(a) |
||
local val = tonumber(a) |
|||
if val == nil then |
if val == nil then |
||
return nil |
return nil |
||
end |
end |
||
-- Initialize output string |
|||
local output = '' |
local output = '' |
||
⚫ | |||
local isNegative = val < 0 |
|||
local prefix = "" |
|||
if isNegative then |
|||
val = -val |
|||
prefix = "-" |
|||
end |
|||
-- Calculate gold, silver, and copper values |
|||
⚫ | |||
⚫ | |||
local copper = val % 1000 |
|||
-- Append gold if present |
|||
if gold > 0 then |
if gold > 0 then |
||
output = |
output = gold .. '[[File:Gold coin.png|link=]] ' |
||
val = val - (gold * 1000000) |
|||
end |
end |
||
⚫ | |||
if (silver > 0) or (gold > 0) then |
|||
⚫ | |||
if silver > 0 then |
|||
val = val - (silver * 1000) |
|||
⚫ | |||
end |
end |
||
⚫ | |||
-- Append copper if present or if total value is exactly 0 |
|||
if copper > 0 or val == 0 then |
|||
⚫ | |||
end |
|||
return output |
return output |
||
end |
end |