Module:Coins

-- -- Implements -- -- @todo the old version uses #expr allowing users to do -- which is a pain --

local p = {} local addcommas = require( 'Module:Addcommas' )._commas

function p.amount ( frame )

local args = frame:getParent.args -- for or     local a = args[1] or args['amount'] or 0 local color = 'green' local img = '1'

-- round to 2 d.p.   a = math.floor( a * 100 ) / 100

-- set the color -- blue for positive, red for negative, green for zero if a > 0 then -- blue color = '#014cc0' elseif a < 0 then -- red color = '#c02614' end

-- set the coins image local num = math.abs( a ) local amounts = { 1000, 250, 100, 25, 5, 4, 3, 2 } for _, v in pairs( amounts ) do       if num > v then img = tostring( v ) break end end

img = '' a = addcommas( a )

-- create span tag local span = mw.html.create( 'span' ) span :css( {           ['white-space'] = 'nowrap',            ['color'] = color        } ) :wikitext( img .. ' ' .. a )

return tostring( span )

end

return p