Editing Module:Currency

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

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'
local a = args[1] or args.Amount or args.amount or '0'
return p.parse(a)
return p.parse(a)
end
end


function p.parse(a)
function p.parse(a)
string.gsub(a, ",", "").gsub(a, ".", "")
local val = tonumber(a)
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 gold = math.floor(val / 1000000)
local isNegative = val < 0
local prefix = ""
if isNegative then
val = -val
prefix = "-"
end
-- Calculate gold, silver, and copper values
local gold = math.modf(val / 1000000)
local silver = math.modf((val % 1000000) / 1000)
local copper = val % 1000

-- Append gold if present
if gold > 0 then
if gold > 0 then
output = prefix .. output .. gold .. ' [[File:Gold coin.png|link=]] '
output = gold .. ' [[File:Gold coin.png|link=]] '
val = val - (gold * 1000000)
end
end
local silver = math.floor(val / 1000)
-- Append silver if present
if (silver > 0) or (gold > 0) then
output = output .. silver .. ' [[File:Silver coin.png|link=]] '
if silver > 0 then
val = val - (silver * 1000)
output = output .. prefix .. silver .. ' [[File:Silver coin.png|link=]] '
end
end
output = output .. val .. ' [[File:Copper coin.png|link=]]'
-- Append copper if present or if total value is exactly 0
if copper > 0 or val == 0 then
output = output .. prefix .. copper .. ' [[File:Copper coin.png|link=]]'
end

return output
return output
end
end
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see Brighter Shores:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Template used on this page: