Module:PriceCalculator: Difference between revisions

No edit summary
No edit summary
Line 35: Line 35:
return p._calculate(price, priceType)
return p._calculate(price, priceType)
end
end
function p.renderPrice(frame)
local args = frame.args
local inputPrice = args.price or args[1] or "1"
local priceType = args.type or args[2] or "sell"
local min = tonumber(args.min or args.MinimumQuantity or "1") or 1
local max = tonumber(args.max or args.MaximumQuantity or "") -- optional
-- Calculate actual price using your _calculate function
local price = tonumber(p._calculate(inputPrice, priceType))
if not price then
return "Error: invalid calculated price"
end
-- Helper to format numbers
local function format(num)
return mw.getContentLanguage():formatNum(num)
end
-- Coin icon HTML (customize as needed)
local coinIcon = '[[File:Coins.png|22px|link=Coins]]'
-- Logic for display
if max and max ~= min then
if price > 1 then
return string.format(
'<abbr title="%d coins each">%s–%s</abbr>%s',
price,
format(price * min),
format(price * max),
coinIcon
)
else
return string.format('%s–%s%s', format(price * min), format(price * max), coinIcon)
end
elseif min == 1 then
return string.format('%s%s', format(price), coinIcon)
else
if price > 1 then
return string.format(
'<abbr title="%d coins each">%s</abbr>%s',
price,
format(price * min),
coinIcon
)
else
return string.format('%s%s', format(price * min), coinIcon)
end
end
end


return p
return p