Module:PriceCalculator: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | |||
function p._calculate(price, priceType) | function p._calculate(price, priceType) | ||
price = tostring(price):gsub(",", "") | -- Ensure price is a string, then strip commas | ||
price = tostring(price):gsub(",", "") | |||
price = tonumber(price) | price = tonumber(price) | ||
if not price or price < 0 then | if not price or price < 0 then | ||
return "Invalid price" | return "Invalid price" | ||
Line 19: | Line 23: | ||
return math.floor(price * factor + 0.5) | return math.floor(price * factor + 0.5) | ||
end | end | ||
function p.calculate(frame) | |||
local args = frame:getParent().args | |||
local price = args.price or args[1] | |||
local priceType = args.type or args[2] | |||
return p._calculate(price, priceType) | |||
end | |||
return p |