10진수를 로마자로 변환하려면 다음 JavaScript 코드를 실행해 보십시오. −
예시
<!DOCTYPE html> <html> <body> <script> // roman numeral var romanNum = new Array(); romanNum = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]; // decimal number var dNum = new Array(); dNum = [1000,900,500,400,100,90,50,40,10,9,5,4,1]; function decimalRoman(value) { if (value <= 0 || value >= 4000) return value; var romanNumeral = ""; for (var i = 0; i<romanNum.length; i++) { while (value >= dNum[i]) { value -= dNum[i]; romanNumeral += romanNum[i]; } } return romanNumeral; } document.write(decimalRoman(39)); document.write("<br>"+decimalRoman(145)); document.write("<br>"+decimalRoman(520)); </script> </body> </html>
출력
XXXIX CXLV DXX