DEV Community

Dev Nestio
Dev Nestio

Posted on

Roman Numeral Converter — Arabic ↔ Roman up to 3,999,999

Overview

Roman Numeral Converter converts between Arabic numbers and Roman numerals.

🔗 https://devnestio.pages.dev/roman-numeral/

Features

  • Arabic → Roman: supports 1 through 3,999,999
  • Roman → Arabic: validates canonical form with round-trip check
  • Extended range uses vinculum overline notation (MĖ„, DĖ„, CĖ„)
  • Step-by-step breakdown shows each symbol and its contribution
  • 13 click-to-load examples

Algorithm

Greedy subtraction from a lookup table:

const ROMAN_MAP = [
  [1000000,'M˄'], [900000,'C˄M˄'], ..., [900,'CM'], ..., [1,'I']
];
while (rem >= val) { result += sym; rem -= val; }
Enter fullscreen mode Exit fullscreen mode

Validation uses a round-trip check — re-encode the parsed number and compare with input. This rejects non-canonical forms like IIII or VV automatically.

👉 Try it: https://devnestio.pages.dev/roman-numeral/

Top comments (0)