' --------------------------------------------

' Convert number to text string
' --------------------------------------------
[loop]
print "Gimme a number! ";
input n
print numText$(n)
print "---------------------------------------------------------------------------"
goto [loop]
wait

FUNCTION numText$(number)
if 0 = number then
numText$ = "zero"
goto [exitFunction]
end if

DIM small$(19)
DIM tens$(7)
DIM big$(5)


smallData$ = "one,two,three,four,five,six,seven,eight,nine,ten," + _
"eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen"
for i = 1 to 19
small$(i) = word$(smallData$,i,",")
next i

tensData$ = "twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety"
for i = 1 to 7
tens$(i) = word$(tensData$,i,",")
next i

bigData$ = "thousand,million,billion,trillion,quadrillion,quintillion"
for i = 1 to 5
big$(i) = word$(bigData$,i,",")
next i

unit = 1
num = ABS(number)

while num > 0
tmp1 = num MOD 100
if tmp1 > 0 and tmp1 < 20 then numText$ = small$(tmp1) + " " + numText$
if tmp1 > 20 and tmp1 < 100 then
tmp2 = tmp1 MOD 10
if tmp2 = 0 then
numText$ = tens$((tmp1 / 10) - 1) + " " + numText$
else
numText$ = tens$((tmp1 / 10) - 1) + "-" + small$(tmp2) + " " + numText$
end if
end if

tmp1 = (num MOD 1000) / 100
if tmp1 then numText$ = small$(tmp1) + " hundred " + numText$

num = int(num / 1000)
tmp1 = num MOD 1000
if tmp1 then numText$ = big$(unit) + " " + numText$

unit = unit + 1
WEND

IF number < 0 THEN numText$ = "negative " + numText$
[exitFunction]
numText$ = trim$(numText$)
END FUNCTION

wait