Module:Currency: Difference between revisions

130 bytes added ,  Yesterday at 23:22
m
handle negative numbers
No edit summary
m (handle negative numbers)
 
Line 15:
-- Initialize output string
local output = ''
local isNegative = val < 0
local prefix = ""
if isNegative then
val = -val
prefix = "-"
end
-- Calculate gold, silver, and copper values
local gold = math.floormodf(val / 1000000)
local silver = math.floormodf((val % 1000000) / 1000)
local copper = val % 1000
 
-- Append gold if present
if gold > 0 then
output = prefix .. output .. gold .. ' [[File:Gold coin.png|link=]] '
end
-- Append silver if present
if silver > 0 then
output = output .. prefix .. silver .. ' [[File:Silver coin.png|link=]] '
end
-- 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
 
3

edits