top of page
Search

# Roman Numeral to Decimal numbers Converter

Description:

The numeric system represented by Roman numerals originated in ancient Rome and remained the usual way of writing numbers throughout Europe well into the Late Middle Ages. Roman numerals, as used today, employ seven symbols, each with a fixed integer value.

Roman Number :

Roman numerals are a numeral system that originated in ancient Rome and remained the usual way of writing numbers throughout Europe well into the Late Middle Ages. Numbers in this system are represented by combinations of letters from the Latin alphabet

Decimal number :

The decimal numeral system is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral system. The way of denoting numbers in the decimal system is often referred to as decimal notation

Approach:

A number in Roman Numerals is a string of these symbols written in descending order(e.g. M’s first, followed by D’s, etc.). However, in a few specific cases, to avoid four characters being repeated in succession(such as IIII or XXXX), subtractive notation is often used as follows:

• I placed before V or X indicates one less, so four is IV (one less than 5) and 9 is IX (one less than 10).

• X placed before L or C indicates ten less, so forty is XL (10 less than 50) and 90 is XC (ten less than a hundred).

• C placed before D or M indicates a hundred less, so four hundred is CD (a hundred less than five hundred) and nine hundred is CM (a hundred less than a thousand).

Algorithm to convert Roman Numerals to Integer Number:

1. Split the Roman Numeral string into Roman Symbols (character).

2. Convert each symbol of Roman Numerals into the value it represents.

3. Take symbol one by one from starting from index 0:

4. If current value of symbol is greater than or equal to the value of next symbol, then add this value to the running total.

5. else subtract this value by adding the value of next symbol to the running total.

See the below table the Symbol — Value pairs:

• I — 1

• V — 5

• X — 10

• L — 50

• C — 100

• D — 500

• M — 1000

User Stories

• User should be able to enter one Roman number in an input field

• User could see the results in a single output field containing the decimal (base 10) equivalent of the roman number that was entered by pressing a button

• If a wrong symbol is entered, the User should see an error

Bonus features

• User could see the conversion to be made automatically as I type

• User should be able to convert from decimal to Roman (vice-versa)