দশমিক সংখ্যাকে রোমানে রূপান্তর করতে, নিম্নলিখিত জাভাস্ক্রিপ্ট কোডটি চালানোর চেষ্টা করুন -
উদাহরণ
<!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