Windows Develop Bookmark and Share   
 index > Windows Forms General > Convert money value to text.
 

Convert money value to text.

Hi everyone, 
I would like a feature in my program where the program will change the money value into readable text...for example..
$200.50 ............it will display as Two Hundred dollar and fifty cents.... 

I know the hard way of doing it..but havent started...
I just want to know is there anyway in .NET where I can easily do it..like using Globalization class etc... or anyone has done it before...would like to share with me....
Thank You...
MigrationUser 1  Friday, April 23, 2004 5:56 AM
Here is some old VBA code that I use in an Access application.  It doesn't look like it would be that hard to convert it to .NET

Tony



Function ConvertMoneyToWords(ByVal curMoney As Currency) As String

    Dim strMoney As String
    Dim strTempDollars As String
    Dim strTempCents As String
    Dim strDollars As String
    Dim strCents As String
    Dim lngDecPlc As Long
    Dim intCount As Integer
    Dim strPlace(6) As String
    
    strPlace(2) = " Thousand"
    strPlace(3) = " Million"
    strPlace(4) = " Billion"
    strPlace(5) = " Trillion"
    
    'Convert curMoney to a string, trimming extra spaces.
    strMoney = Trim$(Str(curMoney))
    
    'Find decimal place.
    lngDecPlc = InStr(strMoney, ".")
    
    'If we find decimal place...
    If lngDecPlc > 0 Then
        'Append trailing zeros.
        strTempCents = Left$(Mid$(strMoney, lngDecPlc + 1) & "00", 2)
        'Convert cents.
        If Left$(strTempCents, 1) <> "0" Then
            strCents = ConvertTens(strTempCents)
        Else
            strCents = ConvertDigit(Right$(strTempCents, 1))
        End If
        'Strip off cents from remainder to convert.
        strMoney = Trim$(Left$(strMoney, lngDecPlc - 1))
    End If
    
    intCount = 1
    
    Do While strMoney <> ""
        'Convert last 3 digits of strMoney to English dollars.
        strTempDollars = ConvertHundreds(Right$(strMoney, 3))
        If strTempDollars <> "" Then
            strDollars = strTempDollars & strPlace(intCount) & strDollars
        End If
        If Len(strMoney) > 3 Then
            'Remove last 3 converted digits from strMoney.
            strMoney = Left$(strMoney, Len(strMoney) - 3)
        Else
            strMoney = ""
        End If
        intCount = intCount + 1
    Loop
    
    'Clean up dollars.
    Select Case strDollars
        Case "":     strDollars = " Zero Dollars"
        Case " One": strDollars = " One Dollar"
        Case Else:   strDollars = strDollars & " Dollars"
    End Select
    
    'Clean up cents.
    Select Case strCents
        Case "":      strCents = " and Zero Cents"
        Case " One ": strCents = " and One Cent"
        Case Else:    strCents = " and" & strCents & " Cents"
    End Select
    
    ConvertMoneyToWords = Mid$(strDollars & strCents, 2)

End Function

MigrationUser 1  Friday, April 23, 2004 3:02 PM
Checkout the <strong>NumberFormatInfo</strong> it also has info over displaying <strong>Currency</strong>
Basiclly one can override the <strong>ToString()</strong> method if one needs a format not specfied.
MigrationUser 1  Friday, April 23, 2004 3:13 PM
Thank you.
MigrationUser 1  Saturday, April 24, 2004 5:57 AM

The code you posted uses a "ConvertTens" routine that is not included in your code.  e.g.

            strCents = ConvertTens(strTempCents)

Can you post the code for this missing routine (and any others that I have overlooked).

Thanks in advance...fab

P.S.  I'm surprised Microsoft doesn't provide this format (currency to english for check printing).  Seems to me like it would be used enough.

drofdarb  Sunday, December 25, 2005 4:13 PM

You can use google to search for other answers

Custom Search

More Threads

• User Control not dropping into TabControl
• Excel-like control
• image.fromfile() method.
• Is there anyone who knows why DataGridView of winform does not provide Paging Property different from GridView of webform?
• How can I customise the default OpenFileDialog appearance.
• MMC snap-in template
• custom controls in C#
• ListView selection disapearing when losing focus.
• Multi select checkbox in datagridview in windows application..URGENT PLZ
• convert base64 to image