Solved

Converting of digits in dollars in numbers to words

Posted on 2006-06-27
5
733 Views
Last Modified: 2007-12-19
Hi,

I would like to know whats the most efficient way to convert digits to words i.e

12.00 to twelve dollars

12.34 to twelve dollars and thirty-four cents.

Thanks.
0
Comment
Question by:jedistar
5 Comments
 
LVL 6

Expert Comment

by:cubixSoftware
ID: 16993355
Hi

This is a Excel VBA function, but should be easy to convert over
http://xl.barasch.com/cCo11432.htm


or try this

http://www.vbcity.com/forums/topic.asp?tid=120553&#RID384555

0
 
LVL 15

Accepted Solution

by:
JackOfPH earned 250 total points
ID: 16997733
//**************************************
    //    
    // Name: Currency2Text
    // Description:This function converts am
    //     ount in words with supplied currency par
    //     ameters.
    (based on AmtToWords by Atul Alurkar)
    // By: Rohan Cragg
    //
    // Inputs:Amount As Double
    UnitCurr As String ' e.g. POUND, DOLLAR, EURO
    DecCurr As String ' e.g. PENNY, CENT
    UnitsCurr As String ' e.g. POUNDS, DOLLARS
    DecsCurr As String ' e.g. PENCE, CENTS, EUROS
    UpperCase as Boolean ' optional parameter to state if you want results in UpperCase or not
    //
    // Returns:The currency ammount in words
    //     (in English but you could easily change
    //     it to another language) e.g. Curr2Text(1
    //     2345.01, "POUND", "PENNY", "POUNDS", "PE
    //     NCE", True) will return "TWELVE THOUSAND
    //     THREE HUNDRED FORTY-FIVE POUNDS AND ONE
    //     PENNY ONLY"
    //
    // Assumes:maximum amount that can be co
    //     nverted by this function is 922,337,203,
    //     685,477
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=2136&lngWId=10    //for details.    //**************************************
    //    
   
    Public Function Curr2Text(ByVal amount As Double, _
    ByVal UnitCurr As String, _
    ByVal DecCurr As String, _
    ByVal UnitsCurr As String, _
    ByVal DecsCurr As String, _
    Optional ByVal UpperCase As Boolean = False) As String
    Dim new_amt, TRstring, BIstring, MIstring, THstring, HUstring, DEstring, Separator As String
    If amount = 0 Then
    Curr2Text = "NIL"
    Exit Function
    End If
    units(0) = ""
    units(1) = " ONE"
    units(2) = " TWO"
    units(3) = " THREE"
    units(4) = " FOUR"
    units(5) = " FIVE"
    units(6) = " SIX"
    units(7) = " SEVEN"
    units(8) = " EIGHT"
    units(9) = " NINE"
    units(10) = " TEN"
    units(11) = " ELEVEN"
    units(12) = " TWELVE"
    units(13) = " THIRTEEN"
    units(14) = " FOURTEEN"
    units(15) = " FIFTEEN"
    units(16) = " SIXTEEN"
    units(17) = " SEVENTEEN"
    units(18) = " EIGHTEEN"
    units(19) = " NINETEEN"
    teens(0) = ""
    teens(1) = " TEN"
    teens(2) = " TWENTY"
    teens(3) = " THIRTY"
    teens(4) = " FORTY"
    teens(5) = " FIFTY"
    teens(6) = " SIXTY"
    teens(7) = " SEVENTY"
    teens(8) = " EIGHTY"
    teens(9) = " NINETY"
    teens(10) = " HUNDRED"
    new_amt = Format(amount, "000000000000000.00")
    TRstring = Mid(new_amt, 1, 3)
    BIstring = Mid(new_amt, 4, 3)
    MIstring = Mid(new_amt, 7, 3)
    THstring = Mid(new_amt, 10, 3)
    HUstring = Mid(new_amt, 13, 3)
    DEstring = "0" & Mid(new_amt, 17, 2)
    Curr2Text = ""
    UnitCurr = IIf(CInt(Left(new_amt, 15)) = 0, "", UnitCurr).ToString
    DecCurr = IIf(CInt(Right(new_amt, 2)) = 0, "", DecCurr).ToString
    UnitCurr = IIf(CInt(Left(new_amt, 15)) > 1, UnitsCurr, UnitCurr).ToString
    DecCurr = IIf(CInt(Right(new_amt, 2)) > 1, DecsCurr, DecCurr).ToString
    Separator = IIf(Not UnitCurr.Equals(String.Empty) And Not DecCurr.Equals(String.Empty), " AND", String.Empty).ToString
    'Curr2Text = UnitCurr & Curr2Text
    Curr2Text &= IIf(CInt(TRstring) > 0, numconv(TRstring) & " TRILLION", "").ToString
    Curr2Text &= IIf(CInt(BIstring) > 0, numconv(BIstring) & " BILLION", "").ToString
    Curr2Text &= IIf(CInt(MIstring) > 0, numconv(MIstring) & " MILLION", "").ToString
    Curr2Text &= IIf(CInt(THstring) > 0, numconv(THstring) & " THOUSAND", "").ToString
    Curr2Text &= IIf(CInt(HUstring) > 0, numconv(HUstring), "").ToString
    Curr2Text &= " " & UnitCurr
    Curr2Text &= IIf(CInt(DEstring) > 0, Separator & numconv(DEstring), "").ToString
    Curr2Text = Curr2Text.Trim & IIf(Not DecCurr.Equals(String.Empty), " " & DecCurr.Trim, String.Empty).ToString
    Curr2Text &= " ONLY"
    If UpperCase = False Then
    Return Curr2Text.Substring(0, 1) & Curr2Text.Substring(1, Curr2Text.Length - 1).ToLower
    Else
    Return Curr2Text
    End If
    End Function
    Private Function numconv(ByVal amt As String) As String
    Dim aAmount, bAmount, cAmount, dAmount As Integer
    Dim hyphen As String
    aAmount = CInt(amt.Substring(1, 2))
    bAmount = CInt(amt.Substring(2, 1))
    cAmount = CInt(amt.Substring(1, 1))
    dAmount = CInt(amt.Substring(0, 1))
    If aAmount < 20 Then
    numconv = units(aAmount)
    Else
    numconv = units(bAmount)
    If bAmount > 0 And cAmount > 0 Then
    hyphen = "-"
    End If
    numconv = teens(cAmount) & hyphen & numconv.TrimStart
    End If
    If dAmount > 0 Then
    If numconv.Equals(String.Empty) Then
    numconv = units(dAmount) & " HUNDRED" & numconv
    Else
    numconv = units(dAmount) & " HUNDRED AND" & numconv
    End If
    End If
    End Function

The above code is from ...
http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=2136&lngWId=10
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net - How to check if current user is an administrator? 6 48
C# Single Form 8 42
VB.Net - KeyPress Event 4 37
Adding Existing Item to vb.net Project causes Errors 4 32
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question