# KOO#2 : Number to Word Conversion

**URL:** <https://forum.kirupa.com/t/koo-2-number-to-word-conversion/175740>\
**Category:** contests\
**Created:** [January 17, 2006, 12:14pm UTC](https://forum.kirupa.com/t/koo-2-number-to-word-conversion/175740 "2006-01-17T12:14:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kookaburra](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@kookaburra](https://forum.kirupa.com/u/kookaburra)\
**Post date:** [January 17, 2006, 12:14pm UTC](https://forum.kirupa.com/t/koo-2-number-to-word-conversion/175740/1 "2006-01-17T12:14:07Z")

</div>

New And improved

Hope you all like it…

[AS]  
arr = [["", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine "], ["ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", “nineteen “, “”], [””, “”, "twenty ", "thirty ", "forty ", “fifty “, “sixty “, “seventy “, “eighty “, “ninety “], [“septillion”, “sextillion”, “quintillion”, “quadrillion”, “trillion”, “billion”, “million”, “thousand”]];  
//1  
this.createTextField(“input”, 1, 50, 50, 200, 20).type = “input”;  
//2  
this.createTextField(“output”, input.maxChars=27, 50, 80, 200, 15).text = “Type a number in the above box…”;  
//3  
output.wordWrap = output.html=output.autoSize=true;  
//4  
input.restrict = “0-9”;  
//5  
input.border = output.border=true;  
//6  
input.onChanged = function() {  
L = this.text.split(””);  
//7  
(this.text.length\>3) ? fn3More() : output.htmlText=“Type a number in the above box…”;  
//8  
(this.text.length == 3) ? output.htmlText=fn3(L[0], L[1], L[2], “hundred \<i\>and\</i\> “) : null;  
//9  
(this.text.length == 1) ? output.htmlText=fn1(this.text) : null;  
//10  
(this.text.length == 2) ? output.htmlText=fn2(L[0], L[1]) : null;  
//11  
Number(this.text) == 0 ? output.htmlText=”\<b\>zero\</b\>” : null;  
//12  
};  
function fn1(One) {  
return arr[0][Number(One)];  
//13  
}  
function fn2(d, u):String {  
return Number(d) == 1 ? arr[1][Number(u)]+”” : arr[2][Number(d)]+””+fn1(u);  
//14  
}  
//function fn3(One:String, Two:String, Three:String, HUN:String) {  
function fn3(One, Two, Three, HUN:String) {  
HUN = ((One != “0” && Two == “0” && Three == “0”) || Two == “0” || Two == “1”) ? “hundred " : HUN;  
//15  
return (fn1(One) == “”) ? fn2(Two, Three) : fn1(One)+HUN+fn2(Two, Three);  
//16  
}  
function fn3More() {  
for (var no:String = input.text, i = 0; (i\<(input.maxChars-input.text.length) && input.text.length\<=input.maxChars); i++) {  
//17  
no = “0”+no;  
//18  
}  
for (i=0, str1=””, a4index=0; i\<no.length-3; i=i+3, a4index++) {  
//19  
str1 += (no.substr(i, 3) == “000”) ? “” : fn3(no.charAt(i), no.charAt(i+1), no.charAt(i+2), “”)+”\<b\>”+arr[3][a4index]+”\</b\> , ";  
//20  
}  
output.htmlText = str1+(fn3(no.charAt(input.maxChars-3), no.charAt(input.maxChars-2), no.charAt(input.maxChars-1), "\<b\>hundred\</b\> \<i\>and\</i\> "));  
//21  
}  
\_root.\_xscale = \_root.\_yscale=200;  
//redundant code. can be removed if exeeds 25 lines  
//22

[/AS]
