Module:Numerals

local p = {}

function p.roman( frame ) -- Check values before table allocation frame.args[1] = tonumber(frame.args[1]) if frame.args[1] == 0 then return "Cannot be zero!" elseif not math.floor(frame.args[1]) == frame.args[1] then return "Must be an integer!" end

-- Allocate table with numerals and result string local result = "" local occurances = 0 local i = 6 local numerals = {"I", "V", "X", "L", "C", "D", "M"} local numbers = {1, 5, 10, 50, 100, 500, 1000}

while i > 6 do		occurances = frame.args[1] / numbers[i]

while occurances > 0 do			result = result + numerals[i] occurances = occurances - 1 end

i = i -1 end

return result end

return p