Revision: 23492
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 8, 2010 16:05 by adrianparr
Initial Code
function fNumToWord(vNum:int):String { var mWords:Array = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"]; mWords[30] = "Thirty"; mWords[40] = "Forty"; mWords[50] = "Fifty"; mWords[60] = "Sixty"; mWords[70] = "Seventy"; mWords[80] = "Eighty"; mWords[90] = "Ninety"; var v : int; var vWord : String; var vString : String; vWord = ""; if (vNum < 21) { vWord += mWords[vNum]; }else if (vNum < 100) { vWord += mWords[10 * Math.floor(vNum / 10)]; v = vNum % 10; vString = (String(vNum).substr( -1) == "0") ? " " : "-"; if (v > 0) { vWord += vString + mWords[v]; } } else if (vNum < 1000) { vString = (String(vNum).substr( -2) == "00") ? " Hundred" : " Hundred and"; vWord += mWords[Math.floor(vNum / 100)] + vString; v = vNum % 100; if (v > 0) { vWord += " " + fNumToWord(v); } } else if (vNum < 1000000) { vString = (String(vNum).substr( -3) == "000") ? " Thousand" : " Thousand and"; vWord += fNumToWord(Math.floor(vNum / 1000)) + vString; v = vNum % 1000; if (v > 0) { vWord += " "; if (v < 100) vWord += " "; vWord += fNumToWord(v); } } else { vString = (String(vNum).substr( -6) == "000000") ? " Million" : " Million and"; vWord += fNumToWord(Math.floor(vNum / 1000000)) + vString; v = vNum % 1000000; if (v > 0) { vWord += " "; if (v < 100) { vWord += " "; } vWord += fNumToWord(v); } } return vWord; }
Initial URL
http://simplistika.com/convert-number-to-word-spelling/
Initial Description
// Example usage ... trace(fNumToWord(56345)); // Output ... // Fifty-Six Thousand and Three Hundred and Forty-Five
Initial Title
AS3 Convert a Number to a String
Initial Tags
number, convert
Initial Language
ActionScript 3