<% ss = "one,two,three,four,five,six,seven,eight,nine" ds = "ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen," & _ "seventeen,eighteen,nineteen" ts = "twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety" qs = ",thousand,million,billion" Function nnn2words(iNum) a = split(ss,",") i = iNum mod 10 if i > 0 then s = a(i-1) ii = int(iNum mod 100)\10 if ii = 1 then s = split(ds,",")(i) elseif ((ii>1) and (ii<10)) then s = split(ts,",")(ii-2) & " " & s end if i = (iNum \ 100) mod 10 if i > 0 then s = a(i-1) & " hundred " & s nnn2words = s End Function Function num2words(iNum) i = iNum if i < 0 then b = true: i = i*-1 if i = 0 then s="zero" elseif i <= 2147483647 then a = split(qs,",") for j = 0 to 3 iii = i mod 1000 i = i \ 1000 if iii > 0 then s = nnn2words(iii) & _ " " & a(j) & " " & s next else s = "out of range value" end if if b then s = "negative " & s num2words = trim(s) End Function ' let's kick the tires: Response.Write num2words(0)&"<br>" Response.Write num2words(196)&"<br>" Response.Write num2words(789)&"<br>" Response.Write num2words(-32768)&"<br>" Response.Write num2words(999999)&"<br>" Response.Write num2words(1000000)&"<br>" Response.Write num2words((2^16)-1)&"<br>" Response.Write num2words(2^16)&"<br>" Response.Write num2words(2147483647)&"<br>" %> |