How Roman Numerals Work
Basic Roman Numeral Symbols
Primary Symbols:
- I = 1
- V = 5
- X = 10
- L = 50
Larger Values:
- C = 100
- D = 500
- M = 1000
Conversion Rules
1. Addition Rule
When a smaller numeral appears after a larger one, add the values together.
Examples:
- VI = V + I = 5 + 1 = 6
- XII = X + I + I = 10 + 1 + 1 = 12
- LX = L + X = 50 + 10 = 60
2. Subtraction Rule
When a smaller numeral appears before a larger one, subtract the smaller from the larger.
Examples:
- IV = V - I = 5 - 1 = 4
- IX = X - I = 10 - 1 = 9
- XL = L - X = 50 - 10 = 40
- CD = D - C = 500 - 100 = 400
- CM = M - C = 1000 - 100 = 900
3. Repetition Rule
A symbol can be repeated up to three times in succession to add to its value.
Examples:
- III = I + I + I = 1 + 1 + 1 = 3
- XXX = X + X + X = 10 + 10 + 10 = 30
- CCC = C + C + C = 100 + 100 + 100 = 300
Our Conversion Algorithm
Decimal to Roman
Our algorithm uses a greedy approach, working from the largest values to the smallest:
- Start with the input decimal number
- Use the largest possible Roman numeral value that fits
- Subtract that value and add the corresponding symbol
- Repeat until the number reaches zero
Example: Converting 1994
- 1994 ≥ 1000 → M (remainder: 994)
- 994 ≥ 900 → CM (remainder: 94)
- 94 ≥ 90 → XC (remainder: 4)
- 4 ≥ 4 → IV (remainder: 0)
- Result: MCMXCIV
Roman to Decimal
For the reverse conversion, we scan from left to right:
- Read each Roman numeral symbol
- If the current symbol is smaller than the next, subtract it
- Otherwise, add it to the total
- Continue until all symbols are processed
Limitations
Our converter handles the standard range of Roman numerals (1-3,999). This covers the traditional Roman numeral system before the introduction of larger number representations in medieval times.
Note:
Numbers above 3,999 require special notation (like overlines) that aren't part of the classical Roman numeral system.