Roman Numbers – Conversion to decimal number

I have read that if a smaller number is to the left of a larger number means that the smaller number has to be subtracted from the larger number.

Ok I can understand quickly for below Roman Numbers :

IX = X - I = 10 - 1 = 9

But I have difficulty in understanding Roman Numbers that have odd Roman Numerals – say :


So if we go from Left to right we get

XIX = 10 + 1 + 10 = 21

But if we go from right to left we get

XIX = 10 + 10 - 1 = 19

So which direction we should consider before applying the rule of smaller followed by bigger Roman Numerals – left to right or right to left?

Solutions Collecting From Web of "Roman Numbers – Conversion to decimal number"

When reading roman numerals, I prefer to think in the following way:

Read from left to right, and if at any point the value of a character decreases, put a comma between the decrease. Then, add each block together.

MCMXCVI $\mapsto$ M,CM,XC,V,I $\mapsto$ $1000+900+90+5+1=1996$

MDCCCLXXIV $\mapsto$ M,D,CCC,L,XX,IV $\mapsto$ $1000+500+300+50+20+4=1874$

MCMXCIX $\mapsto$ M,CM,XC,IX $\mapsto$ $1000+900+90+9 = 1999$

Note that 1999 was not written as IMM or MIM. Converting from arabic numbers to roman numerals, one only uses powers of ten one apart to denote subtraction.

When you are reading Roman numerals, start from the left-most character. Read rightward until the value of the character increases. Then, section those two characters off, and repeat.

That sounds really complicated, and I wrote it somewhat poorly, so here are some examples.

In $XIX$, we start with the left $X$ which is $10$. Then we move to the $I$ which is $1$. We decreased from $10$ to $1$, so we’ll move on. Then we get to the right $X$ which is $10$. We increased from $1$ to $10$, so we need to section off the $IX$. It would look like this:

$$XIX = X + IX = 10 + 9 = 19$$

Here’s a more complicated example:

$$MCMXXIX = M + CM + XX + IX = 1000 + 900 + 20 + 9 = 1929$$

Here we had to section off the $CM$ since we increased in value from $C$ to the second $M$. We had to section off the $IX$ since we increased in value from the $I$ to the last $X$.

One last really complicated example:

$$MMCDXLIV = MM + CD + XL + IV = 2000 + 400 + 40 + 4 = 2444$$

You can apply the following logics:

  • the units are denoted I, II, III, IV, V, VI, VII, VIII$^*$, IX; the tenths are denoted X, XX, XXX, XL, L, LX, LXX, LXXX, XC; the hundredths C, CC, CCC, CD, D, DC, DCC, DCCC, CM; the thousands, M, MM, MMM.

  • numbers are written in thousands, hundredths, tenths and units from left to right.

  • no other pattern is allowed.

The Roman Empire wasn’t designed to last longer than until 3999 AD 🙂

$^*$Sometimes IIX is used for VIII.

XIX is read left to right, the “I” is always applied to the final X.

XIX = X + IX = 10 + 9

XXI = X + XI = 10 + 11

To avoid confusion , the only pairs of Roman numerals that follow the “subtraction” rule are IV, IX, XL, XC, CD, CM. So if your shirt size followed Roman numerals ( which it does not) L would be 50, XL=50-10=40 and XXL = 10+40=50 . Therefore L would be equal to XXL size in Roman numerals !! Coming onto XIX , this equals 19 . Here we must keep in mind the other rules of Roman numerals also and not just addition subtraction. 20 as a digit as a whole is represented as XX and therefore 21 would be XXI. In XIX reading from left to right take IX as a complete digit ie 9 and therefor XIX =19

I have designed following algorithm to convert roman to decimal.

  • Let Roman String be ……
  • Replace string contents of length = 4 with appropriate content

    • Length = 4, Roman numerals are VIII = 8
  • Replace string contents of length = 3 with appropriate content

    • Length = 3, Roman numerals are MMM = 3000, XXX = 30, VII = 7, III = 3
  • Replace string contents of length = 2 with appropriate content
    • Length = 2, Roman numerals are MM = 2000, XX = 20, XI = 11, IX = 9, VI = 6, IV = 4, II = 2
  • Once this is done, then follow below rules:
    • Subtract digits from each other
      • I can be subtracted (absolute) from V or X
      • X can be subtracted (absolute) from L or C
      • C can be subtracted (absolute) from D or M
    • Finally there will be a bunch of digits. Add all of them to get the answer