showing results for - "convert numbers to roman numerals"
Devyn
04 Feb 2020
1var convertToRoman = function(num) {
2  var decimalValue = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
3  var romanNumeral = [
4    "M",
5    "CM",
6    "D",
7    "CD",
8    "C",
9    "XC",
10    "L",
11    "XL",
12    "X",
13    "IX",
14    "V",
15    "IV",
16    "I"
17  ];
18
19  var romanized = "";
20
21  for (var index = 0; index < decimalValue.length; index++) {
22    while (decimalValue[index] <= num) {
23      romanized += romanNumeral[index];
24      num -= decimalValue[index];
25    }
26  }
27
28  return romanized;
29};
30
31// test here
32convertToRoman(36);
33
similar questions
queries leading to this page
convert numbers to roman numerals