Module:Currency

From Brighter Shores Wiki
Revision as of 07:07, 29 October 2024 by BlackHawk (talk | contribs) (Created page with "local p = {} local function amount (a) a = string.gsub(a or '',',','') val = tonumber(a) if val == nil then return nil end local output = '' local gold = math.floor(val / 1000000) if gold > 0 then output = gold .. 'link= ' val = val - (gold * 1000000) end local silver = math.floor(val / 1000) if (silver > 0) or (gold > 0) then output = output .. silver .. 'link= ' val = val - (silver * 1000) end outpu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Currency/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Currency/doc. [edit]
Module:Currency's function cell is invoked by Template:Currency cell.
Module:Currency's function main is invoked by Template:Currency.

local p = {}

local function amount (a)
	a = string.gsub(a or '',',','')
	val = tonumber(a)
	if val == nil then
		return nil
	end
	local output = ''
	local gold = math.floor(val / 1000000)
	if gold > 0 then
		output = gold .. '[[File:Gold coin.png|link=]] '
		val = val - (gold * 1000000)
	end
	local silver = math.floor(val / 1000)
	if (silver > 0) or (gold > 0) then
		output = output .. silver .. '[[File:Silver coin.png|link=]] '
		val = val - (silver * 1000)
	end
	output = output .. val .. '[[File:Copper coin.png|link=]]'
	return output
end

--
-- Module access point
--
function p._coins(a)
    a = tostring(a) or '0'
    return amount(a)
end

return p