This is what the laser display in the sky might look like if Jean Michel Jarre ever held a concert at the Colliseum :o)

The decimal to Roman numeral conversion routine is based upon many rules. Obviously, you have the standard characters I, V, X, L, C, D, and M representing 1, 5, 10, 50, 100, 500, and 1000 respectively.

1 (sorry, I ;o) use the subtraction rule, which allows I, X, and C to be placed to the left of a larger number (I to the left of V or X, X to the left of L or C, and C to the left of D or M) to indicate subtraction instead of addition.

I also use the horizontal bar over the top of characters to represent the fact that they are multiplied by 1000. This allows my routine to convert numbers between 1 and 3,999,999. While you cannot see that in the clock above (1000 is represented by M, not "I-Bar"), the numbers below show how they would look:

The hardest part of writing the conversion routine was those pesky "five-units" (5, 50, 500). Without those, it would have been a lot simpler. In the end, I think I managed to deal with them effectively enough. I also employ a compression routine, which detects more than 4 of any one character and converts it to the correct sequence.

You may notice that when the decimal number 0 is present, no equivalent Roman numeral appears. This is because the Romans had no concept of 0 (or negative numbers), and so there was no corresponding character.

Written for the Ozone Asylum March 2005 20-line JavaScript competition.

Validate Strict XHTML 1.1 | Validate CSS