# Roman to Decimal Number conversion

I am trying to convert CIIXMXCVCII to decimal number. However, I am not getting it completely if it's a valid roman number representation or not. I tried this online tool: http://www.tools4noobs.com/online_tools/roman_decimal/ which says it's equivalent to 1277. However, roman representation of 1277 should be MCCLXXVII in my opinion. Can somebody clarify my doubt? Are both of these roman representation pointing to the same decimal number?

Thanks!

PS: Motivation for this comes from this mathematical joke:

• oh my god. I have no idea. Sorry. – Guy Apr 2 '14 at 18:31
• Should be PG for pergrandis. :) – Charles May 14 '14 at 22:31

The subtractive rule became “standard” only during the Middle Ages. But it's limited in application: only I, X and C can be used for subtraction (once) and next to a symbol of the “next size”:

• I can be used before V or X
• X can be used before L or C
• C can be used before D or M

Thus $1999$ can be represented as MCMXCIX, not as MIM. The notation is in order from the highest units to the lowest:

M CM XC IX

that would be, without the abbrevations,

M D CCCC L XXXX V IIII

In Latin, the number would be spelled mille nongenti nonaginta novem and the number system reflected the names. So IM would mean nothing: Romans were not really good with arithmetic. ;) This can be found in modern usage, however.

I can't see any sensible way to parse CIIXMXCVCII. The tool you mention converts MIIM into $2000$ and IMIIM into $1999$, so I'm under the impression that it discards “illegal” subtractive symbols; if we remove II (as CIIX is converted to $110$) we get CXMXCVCII: $100+990+90+5+100+2=1287$ so I don't see where $1277$ comes from. Another example is VVCVCIV that's converted to $199$, while removing the first C gives VVVCIV that's converted to $109$.

• 100+990+90+95+2 = 1277 [ C, XM, XC, VC, II ] – BitBlitz Aug 10 at 3:29
• @BitBlitz XM is not a legal numeral – egreg Aug 10 at 5:41
• I'm just explaining how the code that computed 1277 may have come up with that answer. – BitBlitz Aug 12 at 5:24
• "the number system reflected the names". Q: how does nongenti (900) correspond to a preference between the numerals DCCCC & CM? – BitBlitz Aug 12 at 5:29
• @BitBlitz The subtractive notation became largely used only in the middle ages, and there was no “preference”, actually: a Roman would have used DCCCC. – egreg Aug 12 at 8:41

You can sensibly parse it by recursively applying a hypothetical rule "any pending smaller number is subtracted from a larger subsequent number" by using a stack. (WikiPedia does say double subtractives are known...)

C = 100 (push 100)
II = 2 (push 2)
X = 8 (10 - pop 2 = push 8)
M (1000 - 108) (pop 100 & 8, push 1000 - 108 = 892)
X = push 10
C = 90  (pop 10, push 90)
V = push 5
C = 95  (pop 5, push 95)
II = 2 push 2

At end, pop and add all numbers = 2 + 95 + 90 + 892 = 1079

E.g. IVX = 10 - 4 = 6.


Not saying my method is officially sanctioned in any way - but it is a possible interpretation and will yield a number in any case.