| home | contents | send comment | send link | add bookmark |

Roman Numeral Calculator

by Stephen R. Schmitt

For: , the Roman numeral is:


Contents

  1. About
  2. The source code
  3. Discussion

About

This calculator computes Roman numerals in the range 1...4999

The program is operated by entering a number in the valid range, and then pressing the Calculate button. All entries are cleared by pressing the Clear button. If the number is not in the valid range, the output windows will display:

value out of range
The Increment button increments the number and recomputes the Roman numeral. The Decrement button decrements the number.

Return to Contents


The source code

The Java Script source code for this program can be viewed by using the View|Source command of your web browser.

You may use or modify this source code in any way you find useful, provided that you agree that the author has no warranty, obligations or liability. You must determine the suitablility of this source code for your use.

Return to Contents


Discussion

Roman numerals are based on the following equivalents:

Roman    Arabic
  M       1000
  D        500
  C        100
  L         50
  X         10
  V          5
  I          1

The Roman numerals are arranged from left to right in order of decreasing value and added. For example, MMII = 2*1000 + 2*1 = 2002. If a lower numeral appears before a higher one, it is subtracted from the higher value, not added to the total. For example, IX = -1 + 10 = 9. Similarly, XC = -10 + 100 = 90, and XL = -10 + 50 = 40. This avoids writting Roman numerals with more than three consecutive occurrences of the same letter; for example, IV <-- IIII, XL <-- XXXX.

An example:

 
    MCMXLIX =    M        C      M         X    L        I    X
            = 1000 + ( -100 + 1000 ) + ( -10 + 50 ) + ( -1 + 10 ) 
            = 1000 + 900 + 40 + 9 
            = 1949

However, MMMM = 4000 since there is no character for a value larger than 1000.

Return to Contents


AbCd Classics - free on-line books


Copyright © 2004, Stephen R. Schmitt