08-27-2008, 05:18 PM
I worked out a bit on my own...I was really wondering if there was already one of those MSDN thingy's I tend to miss...
Function Number_to_Words
I'm sure this could be formatted a bit better. I only wrote it out to do thousands...but it would just repeat out to get bigger numbers.
Function Number_to_Words
str s="$3199.99"
s.trim("$")
double m=val(s 2)
s.format("%.2f" m)
ARRAY(str) arr
int i nt
nt = tok(s arr -1 ".")
str Change.format("%s/100" arr[1])
;Next
str Num=arr[0]
int l=len(Num)
strrev Num
if l=3
,Num.format("%s0" Num)
if l=2
,Num.format("%s00" Num)
if l=1
,Num.format("%s000" Num)
ARRAY(str) a.create(Num.len)
for(i 0 a.len) a[i].get(Num i 1)
,if a[0]=1
,,str Ones="One"
,if a[0]=2
,,Ones="Two"
,if a[0]=3
,,Ones="Three"
,if a[0]=4
,,Ones="Four"
,if a[0]=5
,,Ones="Five"
,if a[0]=6
,,Ones="Six"
,if a[0]=7
,,Ones="Seven"
,if a[0]=8
,,Ones="Eight"
,if a[0]=9
,,Ones="Nine"
,if a[0]=0
,,Ones=""
,if a[1]=0
,,str Tens=""
,if a[1]=1
,,if a[0]=0
,,,Tens="Ten"
,,,Ones=""
,,if a[0]=1
,,,Tens="Eleven"
,,,Ones=""
,,if a[0]=2
,,,Tens="Twelve"
,,,Ones=""
,,if a[0]=3
,,,Tens="Thirteen"
,,,Ones=""
,,if a[0]=4
,,,Tens="Fourteen"
,,,Ones=""
,,if a[0]=5
,,,Tens="Fifteen"
,,,Ones=""
,,if a[0]=6
,,,Tens="Sixteen"
,,,Ones=""
,,if a[0]=7
,,,Tens="Seventeen"
,,,Ones=""
,,if a[0]=8
,,,Tens="Eighteen"
,,,Ones=""
,,if a[0]=9
,,,Tens="Nineteen"
,,,Ones=""
,if a[1]=2
,,Tens="Twenty"
,if a[1]=3
,,Tens="Thirty"
,if a[1]=4
,,Tens="Forty"
,if a[1]=5
,,Tens="Fifty"
,if a[1]=6
,,Tens="Sixty"
,if a[1]=7
,,Tens="Seventy"
,if a[1]=8
,,Tens="Eighty"
,if a[1]=9
,,Tens="Ninety"
,int I=val(a[1])
,if I>0
,,Tens.format("%s-" Tens)
,if a[2]=1
,,str Hund="One"
,if a[2]=2
,,Hund="Two"
,if a[2]=3
,,Hund="Three"
,if a[2]=4
,,Hund="Four"
,if a[2]=5
,,Hund="Five"
,if a[2]=6
,,Hund="Six"
,if a[2]=7
,,Hund="Seven"
,if a[2]=8
,,Hund="Eight"
,if a[2]=9
,,Hund="Nine"
,if a[2]=0
,,Hund=""
,I=val(a[2])
,if I>0
,,Hund.format("%s Hundred " Hund)
,if a[3]=0
,,str Thou=""
,if a[3]=1
,,Thou="One"
,if a[3]=2
,,Thou="Two"
,if a[3]=3
,,Thou="Three"
,if a[3]=4
,,Thou="Four"
,if a[3]=5
,,Thou="Five"
,if a[3]=6
,,Thou="Six"
,if a[3]=7
,,Thou="Seven"
,if a[3]=8
,,Thou="Eight"
,if a[3]=9
,,Thou="Nine"
,if a[3]=0
,,Thou=""
,I=val(a[3])
,if I>0
,,Thou.format("%s Thousand, " Thou)
;OutPut
str Total.format("%s%s%s%s and %s Dollars" Thou Hund Tens Ones Change)
out Total
I'm sure this could be formatted a bit better. I only wrote it out to do thousands...but it would just repeat out to get bigger numbers.