Roman Numbers

If you need to work with Roman Numbers, I’ve made a script that will make this easy for you.

If you don’t know anything about the Roman Numeral system, I would suggest you go have a look at it’s wikipedia page. Because of the limits of the text display, this stuff only works for numbers in this range: 1 – 3999 (including both).

Anyway, here you can see it in action:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
(put a “normal” decimal number numbers in the upper white field, press convert and you will see how they would be in roman. The opposite for the lower)

Here is how to use it:

First, you need to import it:

	import com.rasmuswriedtlarsen.utils.RomanNumerals;

 

This class doesn’t need to be instantiated.

 

If you want to convert a “normal” decimal number to a roman number, call this:

var romanNumber:String = RomanNumerals.decimalToRoman ( variableHoldingDecimalNumber ) ;

The parameter for the function has to be an integer, withing 1-3999.
The function will return a string, holding the roman number.
If a mistake occurs, it will return “” and give a trace statement saying what went wrong.

 

If you want to convert a roman number to a “normal” decimal number, call this:

var decimalNumber:int = RomanNumerals.romanToDecimal ( variableHoldingRomanString );

The parameter for the function has to be a string, only containing these characters: “I,V,X,L,C,D,M”
The function will return a integer, holding the decimal number.
If a mistake occurs, it will return NaN and give a trace statement saying what went wrong.

 

I’ve put a MIT License on it, as I don’t want to be sued if your computer blows up while using it..

Download here.

Posted on September 1st, 2010
Filed under ActionScript 3, Flash, Util |

Leave a Reply