I would suggest you make a hash table with the numbers "0" to "99" as indices (enclosed in quotes) and the values being the word names for those numbers. That will make localization possible without out a lot of complicated code to determine, for example, the difference between "eleven" and "juu ichi" (ten one
) in Japanese or between "ninety-nine" and "quatre vingt dix neuf" (eighty-nineteen) in French, "twenty-two" and "zwei und zwanzig" (two and twenty) in German, etc.
Let's name that hash table myNumberWords
. Then you would simply convert your digits as follows:
function getWordsFromNumber(num:Number) : String {
return myNumberWords[num.toString()];
}
If you want to go higher than 99, add a hash for the words hundred, thousand, million, billion, etc., then split your whole number into an array and place the appropriate units after every 3rd number, counting from the top of the stack. You'll also have to have zero values and double-zero values counted as empty strings ("") except when there is only one digit and it is a zero, etc.