Convert a Number to Words/Text

Hi all,

I am developing a receipting system and I want to take the amount paid; let say

$157.57 and convert that into to words being:

One Hundred Fifty Seven Dollars and Fifity Seven Cents.....

Is there any way I accomplish this in VB or VBA...

Thanks for you eager response...

menkiz
menkizAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulCaswellCommented:
Hi menkiz,

Here's one:

http://www.ozgrid.com/VBA/ValueToWords.htm

Paul

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MilanKMCommented:
Also take a look at following samples done in VB6

http://www.vbexplorer.com/VBExplorer/tips/src36.asp
http://vbcity.com/forums/topic.asp?tid=6785

Hope this helps
MilanKM
menkizAuthor Commented:
Exactly what I needed......
Jaeger69Commented:
Here's a version I wrote up specificaly for Currency, supporting large numbers

Option Explicit
' Converts a String Dollar and Cents value like $123.45
' into a worded string value like One Hundred twenty-three dollars and Fourty-Five cents

'===================================================
' Function: CurrencyToWords
' Parameter: Amount To convert, a string representation of a currency amount (Dollars)
' Returns: A Enlish Text Word representation of the Currency value
'===================================================
Function CurrencyToWords(AmountToConvert)
    Dim TempString
    Dim AmountSplit
    Dim Dollars
    Dim Cents
   
   
    AmountSplit = Split(AmountToConvert, ".")
    If Left(AmountSplit(0), 1) = "$" Then AmountSplit(0) = Right(AmountSplit(0), Len(AmountSplit(0)) - 1) 'Remove the Dollar Sign
    Dollars = NumberToWords(AmountSplit(0))
    If (UBound(AmountSplit) - LBound(AmountSplit)) >= 1 Then
            Cents = NumberToWords(AmountSplit(1))
        Else
            Cents = ""
        End If
    If (Len(Dollars) > 0) Then TempString = Dollars & " Dollars"
    If (Len(Cents) > 0) Then
        If (Len(TempString) > 0) Then TempString = TempString & " and "
        TempString = TempString & Cents & " Cents"
        End If
    CurrencyToWords = TempString
    End Function

'==================================================
' Function NumberToWords
' Converts a Whole number into a word string representation
'==================================================
Function NumberToWords(NumbersToConvert)
    Dim TempString
    Dim TempNumbers
    Dim OnesPlace
    Dim TensPlace
    Dim HundresPlace
    Dim Numbers
    Dim Tens
    Dim Powers
    Dim PowersLoop
    Dim TempThousandsNum
    Dim TempThousandsWords

    Numbers = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen")
    Tens = Array("", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety")
    Powers = Array("", "Thousand", "Million", "Billion", "Trillion", "Quadrillion", "Quintillion", "Sextillion")

    TempNumbers = StrReverse(NumbersToConvert) ' Reverse the string so the numbers increase in String order
   
    For PowersLoop = 1 To (Len(TempNumbers)) Step 3 'Breaks the string up into Thousands
        TempThousandsNum = Mid(TempNumbers, PowersLoop, 3)
        OnesPlace = CInt(Mid(TempThousandsNum, 1, 1))
        TensPlace = 0
        HundresPlace = 0
       
        If (Len(TempThousandsNum) >= 2) Then
            TensPlace = CInt(Mid(TempThousandsNum, 2, 1))
            End If
        If (Len(TempThousandsNum) >= 3) Then
            HundresPlace = CInt(Mid(TempThousandsNum, 3, 1))
            End If
        TempThousandsWords = Numbers(OnesPlace)
        If (TensPlace > 1) Then
            TempThousandsWords = Tens(TensPlace) & "-" & TempThousandsWords
            Else
            TempThousandsWords = Numbers((TensPlace * 10) + OnesPlace)
            End If
        If (HundresPlace >= 1) Then TempThousandsWords = Numbers(HundresPlace) & " Hundred and " & TempThousandsWords
        TempThousandsWords = Trim(TempThousandsWords)
        If PowersLoop \ 3 > 0 Then TempThousandsWords = TempThousandsWords & " " & Powers(PowersLoop \ 3) & ","
        If (Len(TempThousandsWords) > 0) Then TempString = TempThousandsWords & " " & TempString
    Next
    NumberToWords = Trim(TempString)

End Function
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.