Answers for "convert decimal to roman numerals"

1

convert decimal to roman numerals

function convertToRoman(num) 
{
  let map = {
    1000 : "M",
    900 : "CM",
    500 : "D",
    400 : "CD",
    100 : "C",
    90: "XC",
    50: "L",
    40: "XL",
    10: "X",
    9: "IX",
    5: "V",
    4: "IV",
    1: "I"
  }
  let roman = "";
  let romankeys = Object.keys(map).reverse();
  romankeys.forEach((keys) => {
      while(keys <= num)
      {
        roman += map[keys];
        num -= keys;
      }
        
  });
  return roman;
}

//https://www.rapidtables.com/convert/number/how-number-to-roman-numerals.html (The refrence for the Roman Calculator)
console.log(convertToRoman(20));
Posted by: Guest on July-10-2021

Code answers related to "convert decimal to roman numerals"

Code answers related to "Javascript"

Browse Popular Code Answers by Language