Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function intoroman(n)
- if n < 1 or n > 3999 then
- return ""
- end
- local numer_toconvert = n
- local number_roman = ""
- local table_conversion = {
- ['1'] = {"","I","II","III","IV","V","VI","VII","VIII","IX"},
- ['10'] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
- ['100'] = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},
- ['1000'] = {"","M","MM","MMM"}
- }
- for x =3,0, -1 do
- local index_n = math.pow(10, x)
- local temp_r = math.floor(numer_toconvert / index_n)
- number_roman = number_roman .. table_conversion["" .. index_n][temp_r+1]
- numer_toconvert = numer_toconvert - (temp_r* index_n)
- end
- return number_roman
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement