conti..previous post - numbers into words

# Thread: conti..previous post - numbers into words

1. Senior Member
Join Date
Dec 1969
Posts
468

## conti..previous post - numbers into words

code to convert numbers into words is as below(taken from Bill w&#039;s demo).<BR><BR>Dim UnitNames, TeenNames, DecadeNames<BR>UnitNames = Array(" zero"," one"," two"," three"," four", _<BR> " five"," six"," seven"," eight"," nine" )<BR>TeenNames = Array(" ten"," eleven"," twelve"," thirteen"," fourteen", _<BR> " fifteen"," sixteen"," seventeen"," eighteen"," nineteen" )<BR>DecadeNames = Array(" zero"," ten"," twenty"," thirty"," forty", _<BR> " fifty"," sixty"," seventy"," eighty"," ninety" )<BR><BR>Function NumberAsWord( num )<BR> Dim millions, thousands, hundreds, decades, result<BR><BR> If Not isNumeric( num ) Then<BR> NumberAsWord = "&#060;i&#062;That is NOT a valid number!&#060;/i&#062;"<BR> Exit Function<BR> End If<BR><BR> result = ""<BR> num = CDbl(num)<BR><BR> If num = 0 Then<BR> NumberAsWord = "zero"<BR> Exit Function<BR> End If<BR><BR> If num &#060; 0 Then<BR> num = - num<BR> result = "&#060;i&#062;NEGATIVE&#060;/i&#062; "<BR> End If<BR><BR> millions = 999999<BR><BR> On Error Resume Next<BR> millions = num 1000000<BR> num = CLng( num MOD 1000000 )<BR> On Error GoTo 0<BR><BR> If millions &#062; 0 Then<BR> If millions &#062; 999 Then<BR> NumberAsWord = result & "BILLIONS and BILLIONS"<BR> Exit Function<BR> End If<BR> result = result & NumberAsWord( millions ) & " million"<BR> If num = 0 Then<BR> NumberAsWord = result<BR> Exit Function<BR> End If<BR> End If<BR> <BR> thousands = num 1000<BR> num = num MOD 1000<BR> If thousands &#062; 0 Then<BR> result = result & NumberAsWord( thousands ) & " thousand"<BR> If num = 0 Then<BR> NumberAsWord = result<BR> Exit Function<BR> End If<BR> End If<BR> <BR> hundreds = num 100<BR> num = num MOD 100 <BR> If hundreds &#062; 0 Then<BR> result = result & UnitNames( hundreds ) & " hundred"<BR> End If<BR> <BR> decades = num 10<BR> num = num MOD 10<BR> If decades = 1 Then<BR> result = result & TeenNames( num ) <BR> Else<BR> If decades &#062; 1 Then<BR> result = result & DecadeNames( decades )<BR> End If<BR> If num &#062; 0 Then<BR> result = result & UnitNames( num )<BR> End If<BR> End If<BR><BR> NumberAsWord = result<BR>End Function<BR><BR>It is rounding cents. I need to convert words of Currency field which is stored in the datbase.<BR><BR>for eg: <BR>4500.39 <BR>so it has to be shown as four thousand five hundred and thrity nine cents.<BR><BR>Thanks to all who replied to my earlier post. It takes lot of time and effort to answer these questions.

2. Senior Member
Join Date
Dec 1969
Posts
5,955

## Why don't you call the function...

...twice - once for the dollars and again for the cents:<BR><BR>Dim dPrice, sDollars, sCents, sAll<BR><BR>dPrice = 4300.39<BR><BR>sDollars = NumberAsWords(CLng(dPrice))<BR>sCents = NumberAsWords((dPrice * 100) Mod 100)<BR><BR>sAll = sDollars & " AND " & sCents<BR><BR>Well, something like the above anyway. You might have to rejig it a little.<BR><BR>Oliver.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•