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
|