The below TCL proc converts a Number (Eg: 5, 55, 89) to the word corresponding to that number (Eg: Five, FiftyFive, EightyNine)
proc NumberToWord {n} {
if {[expr $n / 10] == 0} {
switch $n {
1 { return "One" }
2 {return "Two" }
3 {return "Three"}
4 {return "Four"}
5 {return "Five"}
6 {return "Six"}
7 {return "Seven"}
8 {return "Eight"}
9 {return "Nine"}
0 {return "Zero"}
}
} elseif {[expr $n / 100] == 0} {
if {[expr [expr $n / 10] % 10] == 1} {
switch $n {
11 { return "Eleven" }
12 {return "Twelve" }
13 {return "Thirteen" }
15 {return "Fifteen"}
10 {return "Ten"}
default { return "[NumberToWord [expr $n % 10]]teen"}
}
} else {
switch [expr $n / 10] {
2 {if {[expr $n % 10] == 0} {return "Twenty"} else {return "Twenty[NumberToWord [expr $n % 10]]" }}
3 {if {[expr $n % 10] == 0} {return "Thirty"} else {return "Thirty[NumberToWord [expr $n % 10]]"}}
4 {if {[expr $n % 10] == 0} {return "Fourty"} else {return "Fourty[NumberToWord [expr $n % 10]]"}}
5 {if {[expr $n % 10] == 0} {return "Fifty"} else {return "Fifty[NumberToWord [expr $n % 10]]"}}
6 {if {[expr $n % 10] == 0} {return "Sixty"} else {return "Sixty[NumberToWord [expr $n % 10]]"}}
7 {if {[expr $n % 10] == 0} {return "Seventy"} else {return "Seventy[NumberToWord [expr $n % 10]]"}}
8 {if {[expr $n % 10] == 0} {return "Eighty"} else {return "Eighty[NumberToWord [expr $n % 10]]"}}
9 {if {[expr $n % 10] == 0} {return "Ninety"} else {return "Ninety[NumberToWord [expr $n % 10]]"}}
}
}
} elseif {[expr $n / 1000] == 0} {
return "[NumberToWord [expr $n / 100]]Hundred[NumberToWord [expr $n % 100]]"
} elseif {[expr $n / 1000000] == 0} {
return "[NumberToWord [expr $n /1000]]Thousand[NumberToWord [expr $n % 1000]]"
} else {
return "Number must be less than OneMillion"
}
}
proc NumberToWord {n} {
if {[expr $n / 10] == 0} {
switch $n {
1 { return "One" }
2 {return "Two" }
3 {return "Three"}
4 {return "Four"}
5 {return "Five"}
6 {return "Six"}
7 {return "Seven"}
8 {return "Eight"}
9 {return "Nine"}
0 {return "Zero"}
}
} elseif {[expr $n / 100] == 0} {
if {[expr [expr $n / 10] % 10] == 1} {
switch $n {
11 { return "Eleven" }
12 {return "Twelve" }
13 {return "Thirteen" }
15 {return "Fifteen"}
10 {return "Ten"}
default { return "[NumberToWord [expr $n % 10]]teen"}
}
} else {
switch [expr $n / 10] {
2 {if {[expr $n % 10] == 0} {return "Twenty"} else {return "Twenty[NumberToWord [expr $n % 10]]" }}
3 {if {[expr $n % 10] == 0} {return "Thirty"} else {return "Thirty[NumberToWord [expr $n % 10]]"}}
4 {if {[expr $n % 10] == 0} {return "Fourty"} else {return "Fourty[NumberToWord [expr $n % 10]]"}}
5 {if {[expr $n % 10] == 0} {return "Fifty"} else {return "Fifty[NumberToWord [expr $n % 10]]"}}
6 {if {[expr $n % 10] == 0} {return "Sixty"} else {return "Sixty[NumberToWord [expr $n % 10]]"}}
7 {if {[expr $n % 10] == 0} {return "Seventy"} else {return "Seventy[NumberToWord [expr $n % 10]]"}}
8 {if {[expr $n % 10] == 0} {return "Eighty"} else {return "Eighty[NumberToWord [expr $n % 10]]"}}
9 {if {[expr $n % 10] == 0} {return "Ninety"} else {return "Ninety[NumberToWord [expr $n % 10]]"}}
}
}
} elseif {[expr $n / 1000] == 0} {
return "[NumberToWord [expr $n / 100]]Hundred[NumberToWord [expr $n % 100]]"
} elseif {[expr $n / 1000000] == 0} {
return "[NumberToWord [expr $n /1000]]Thousand[NumberToWord [expr $n % 1000]]"
} else {
return "Number must be less than OneMillion"
}
}