Full version: jsB@nk » Calculation » Equivalent » Roman Numeral Converter
URL: https://www.javascriptbank.com/roman-numeral-converter.html
Convert Arabic numerals to roman numerals with the click of a button. Numbers work up to the tens of billions.
Full version: jsB@nk » Calculation » Equivalent » Roman Numeral Converter
URL: https://www.javascriptbank.com/roman-numeral-converter.html
<script language="JavaScript">/*M = 1000D = 500C = 100L = 50X = 10V = 5I = 1*/function Roman() {var Num=document.NumF.Num.value;var MvC=0var MvC2=0var MvX=0var MvX2=0var MvI=0var MvI2=0var Mvalue=""var MV1=1000var DV1=500var MoreMs=0var MoreV=""//Start Big Loop!!while(Num >= MV1) {Num=Num - MV1MoreMs++}if(MoreMs >= 4) {while(MoreMs >= 1000) {MoreMs=MoreMs - 1000MoreV+="M" }if(MoreMs >= 900 && MoreMs < 1000) {MoreMs=MoreMs - 900MoreV+="CM"}while(MoreMs >= 500 && MoreMs < 1000) {MoreMs=MoreMs - 500MoreV+="D"}if(MoreMs >= 400 && MoreMs < 500) {MoreMs=MoreMs - 400MoreV+="CD"}while(MoreMs >= 100 && MoreMs < 500) {MoreMs=MoreMs - 100MoreV+="C"}if(MoreMs >= 90 && MoreMs < 100) {MoreMs=MoreMs - 90MoreV+="XC"}if(MoreMs >= 40 && MoreMs < 50) {MoreMs=MoreMs - 40MoreV+="XL"}while(MoreMs >= 50 && MoreMs < 100) {MoreMs=MoreMs - 50MoreV+="L"}if(MoreMs >= 9 && MoreMs < 10) {MoreMs=MoreMs - 9MoreV+="IX"}while(MoreMs >= 10 && MoreMs < 50) {MoreMs=MoreMs - 10MoreV+="X"}if(MoreMs == 9) {MoreMs=MoreMs - 9MoreV+="IX"}while(MoreMs >= 5 && MoreMs < 10) {MoreMs=MoreMs - 5MoreV+="V"}if(MoreMs == 4) {MoreMs=MoreMs - 4MoreV+="IV"}if(MoreMs == 3) {MoreV+="I"MoreMs--}if(MoreMs == 2) {MoreV+="I"MoreMs--}if(MoreMs == 1) {MoreV+="I"MoreMs--}}if(MoreMs == 3) {Mvalue+="M"MoreMs--}if(MoreMs == 2) {Mvalue+="M"MoreMs--}if(MoreMs == 1) {Mvalue+="M"MoreMs--}while(Num < MV1 && Num >= DV1) {if(Num >= 900) {Mvalue+="CM"Num=Num - 900}else if(Num < 900 && Num >= DV1) {Num=Num - DV1Mvalue+="D"}}while(Num < 500 && Num >= 100) {Num=Num - 100MvC2++}if(MvC2 == 4) {Mvalue+="CD"}if(MvC2 == 3) {Mvalue+="C"MvC2--}if(MvC2 == 2) {Mvalue+="C"MvC2--}if(MvC2 == 1) {Mvalue+="C"MvC2--}while(Num < 100 && Num >= 50) {if(Num >= 90) {Mvalue+="XC"Num=Num - 90}else if(Num < 90 && Num >= 50) {Num=Num - 50Mvalue+="L"}}while(Num < 50 && Num >= 10) {Num=Num - 10MvX2++}if(MvX2 == 4) {Mvalue+="LX"}if(MvX2 == 3) {Mvalue+="X"MvX2--}if(MvX2 == 2) {Mvalue+="X"MvX2--}if(MvX2 == 1) {Mvalue+="X"MvX2--}if(Num == 9) {Mvalue+="IX"Num=Num - 9}while(Num < 10 && Num >= 5) {if(Num <= 8 && Num >= 5) {Num=Num - 5Mvalue+="V"}}while(Num < 5 && Num >= 1) {Num=Num - 1MvI2++if(MvI2 == 4) {Mvalue+="IV"}}if(MvI2 == 3) {Mvalue+="I"MvI2--}if(MvI2 == 2) {Mvalue+="I"MvI2--}if(MvI2 == 1) {MvI2--Mvalue+="I"}//End Big Loop!//Begin Smaller Loops!while(Num >= 500 && Num < 1000 || Num == 500) {if(Num >= 900) {Mvalue+="CM"Num=Num - 900}else if(Num < 900 && Num >= DV1) {Num=Num - DV1Mvalue+="D"}}while(Num >= 100 && Num < 500 || Num == 100) {Num=Num - 100MvC++}if(MvC == 4) {Mvalue+="CD"}if(MvC == 3) {Mvalue+="C"MvC--}if(MvC == 2) {Mvalue+="C"MvC--}if(MvC == 1) {Mvalue+="C"MvC--}while(Num >= 50 && Num < 100 || Num == 50) {if(Num >= 90) {Mvalue+="XC"Num=Num - 90}else if(Num < 90 && Num >= 50) {Num=Num - 50Mvalue+="L"}}while(Num >= 10 && Num < 50 || Num == 10) {Num=Num - 10MvX++}if(MvX ==4) {Mvalue+="LX"}if(MvX == 3) {Mvalue+="X"MvX--}if(MvX == 2) {Mvalue+="X"MvX--}if(MvX == 1) {Mvalue+="X"MvX--}if(Num == 9) {Mvalue+="IX"Num=Num - 9}while(Num >= 5 && Num < 10 || Num == 5) {if(Num <= 8 && Num >= 5) {Num=Num - 5Mvalue+="V"}}while(Num >= 1 && Num < 5 || Num == 1) {Num=Num - 1MvI++if(MvI == 4) {Mvalue+="IV"}}if(MvI == 3) {Mvalue+="I"MvI--}if(MvI == 2) {Mvalue+="I"MvI--}if(MvI == 1) {MvI--Mvalue+="I"}//End Smaller Loops!MoreV1.innerHTML=MoreVMoreV2.innerHTML=Mvalue}//--></script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<form name="NumF"><input type="text" value="" name="Num" size="20"> <input type="button" value="Convert" onClick="Roman()"> <span id="MoreV1" style="text-decoration: overline"></span> <span id="MoreV2"></spaN></form><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->