Algorithms for Roman Numerals

Sun, 12 Jun 2016 00:00:00 GMT

Converting between regular (Hindu-Arabic) and Roman numerals seems to be a common programming exercise.

However, one annoying aspect is that the system is not always defined very well. The way I was taught about Roman numerals in school was something like the following. Roman numerals are written left-to-right using letters that each represent different values:

Letter | M | D | C | L | X | V | I
Value | 1000 | 500 | 100 | 50 | 10 | 5 | 1

The values are usually just added together (an additive system); however, when a smaller value is followed by a larger value, the smaller one is subtracted from the larger (subtractive notation). For example, 16 is written as XVI, and 14 as XIV.

I soon learned, after being told off for burning IIV onto the face of the clock I made in woodworking class, that there are rules for when one is supposed to use the subtractive notation. But it was never made clear exactly what those rules were.

This article examines how some popular programs implement conversion to Roman numerals.