# Number to Roman Converter

e.g. 11

#### Roman Numeral

e.g. XI

Note: You can also input Roman Numeral to convert to Number

Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.

``````Symbol       Value
I             1
V             5
X             10
L             50
C             100
D             500
M             1000
``````

These symbols can be combined like this to create numbers:

1 2 3 4 5 6 7 8 9
I II III IV V VI VII VIII IX
10 20 30 40 50 60 70 80 90
X XX XXX XL L LX LXX LXXX XC
100 200 300 400 500 600 700 800 900
C CC CCC CD D DC DCC DCCC CM

Things to note about roman numerals:

• When a symbol appears after a larger (or equal) symbol it is added
Example: VI = V + I = 5 + 1 = 6
Example: LXX = L + X + X = 50 + 10 + 10 = 70
• But if the symbol appears before a larger symbol it is subtracted
Example: IV = V − I = 5 − 1 = 4
Example: IX = X − I = 10 − 1 = 9
• `I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
• `X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
• `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.

### Romanize Number

Javascript method used in this converter to convert from Decimal Number to Roman:-

``````const romanize = (number) => {
const lookup = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};
let roman = '';

for (let i in lookup ) {
while ( number >= lookup[i] ) {
roman += i;
number -= lookup[i];
}
}
return roman;
}
``````

### Roman to Decimal Number

Javascript method used in this converter to convert from Roman to Decimal Number:-

``````const romanToInteger = (roman) => {
const lookup = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};
const array = roman.split('');
let total = 0, current, currentValue, next, nextValue;

for(let i=0; i<array.length; i++){
current = array[i];
currentValue = lookup[current];
next = array[i+1];
nextValue = lookup[next];

if(currentValue < nextValue) {
total -= currentValue;
}else {
total += currentValue;
}
}