开发者

Convert number into words using flex

I am trying to convert an entry using a numeric stepper 开发者_Go百科in flex into words to display in a textarea.

i.e a user uses the stepper to enter "89" as a value and in the text area the words "Eighty nine" are displayed.

After much searching i haven't found anything that helps - a few javascript functions but that is all.

any help sample code would be much appreciated.

thanks in advance.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜