$10 to Ten Dollar

georgepatotk

Well-known member
Joined
Mar 1, 2004
Messages
431
Location
Malaysia
Any one can suggest to me any libraby to be used in order to convert numeric form of dollar into string form of dollar.

For example,

$10 => Ten Dollar,
$10.50, Ten Dollar and Fifty Cents

Thanks in advance
 
YEs, that the one.
Unfortunately, I had created my own one. just to share with you. so, i am pasting it here.

just pass the value into CurrencyToWord, it will convert it for you.
Dollas and cent sign can be change accordingly.

DollarPro = "Dollar " pronuosation of $
CentPro = "Cent " pronuosation of Cent


________________________________________________________________
Module Convertion
Dim Digit(100) As String
Dim strDollar As String
Dim strCent As String
Dim Result As String
Dim DollarPro As String
Dim CentPro As String

Function CurrencyToWord(ByVal Num) As String
DollarPro = "Dollar " pronuosation of $
CentPro = "Cent " pronuosation of Cent

Digit(1) = "One "
Digit(2) = "Two "
Digit(3) = "Three "
Digit(4) = "Four "
Digit(5) = "Five "
Digit(6) = "Six "
Digit(7) = "Seven "
Digit(8) = "Eigth "
Digit(9) = "Nine "
Digit(10) = "Ten "
Digit(11) = "Eleven "
Digit(12) = "Twelve "
Digit(13) = "Thirteen "
Digit(14) = "Forteen "
Digit(15) = "Fifteen "
Digit(16) = "Sixteen "
Digit(17) = "Seventeen "
Digit(18) = "Eighteen "
Digit(19) = "Nineteen "
Digit(20) = "Twenty "
Digit(30) = "Thirty "
Digit(40) = "Forty "
Digit(50) = "Fifty "
Digit(60) = "Sixty "
Digit(70) = "Seventy "
Digit(80) = "Eighty "
Digit(90) = "Ninety "

If Len(strDollar) > 6 Then
MessageBox.Show("Number too long", "Information", MessageBoxButtons.OK)
Exit Function
End If

Num = Format(Num, "###0.00")
strDollar = Num
strCent = Right(strDollar, 2)
strDollar = Mid(strDollar, 1, Len(strDollar) - 3)

CurrencyToWord = CalculateNotes(strDollar) & DollarPro & CalculateCoins(strCent) & CentPro

End Function

Function CalculateNotes(ByVal notes As String) As String
If Len(notes) = 1 Then
Result = Digit(Val(notes))
End If

If Len(notes) = 2 Then
If Left(notes, 1) = "1" Then
Result = Digit(Val(notes))
Else
Result = Digit(Val(Left(notes, 1) & "0"))
If Right(notes, 1) <> "0" Then
Result = Result & Digit(Val(Right(notes, 1)))
End If
End If
End If

If Len(notes) = 3 Then
Result = Digit(Val(Left(notes, 1))) & "Hundred "
Result = Result & CalculateNotes(Val(Right(notes, 2)))
End If

If Len(notes) = 4 Then
Result = Digit(Val(Left(notes, 1))) & "Thousand "
Result = Result & CalculateNotes(Val(Right(notes, 3)))
End If

If Len(notes) = 5 Then
Result = CalculateNotes(Val(Left(notes, 2))) & "Thousand "
Result = Result & CalculateNotes(Val(Right(notes, 3)))
End If

If Len(notes) = 6 Then
Result = CalculateNotes(Val(Left(notes, 3))) & "Thousand "
Result = Result & CalculateNotes(Val(Right(notes, 3)))
End If

CalculateNotes = Result
End Function

Function CalculateCoins(ByVal coins As String) As String

If Len(coins) = 1 Then
Result = "and " & Digit(Val(coins))
End If

If Len(coins) = 2 Then
If Left(coins, 1) = "1" Then
Result = "and " & Digit(Val(coins))
ElseIf coins = "00" Then
Result = "and Zero "
Else
Result = "and " & Digit(Val(Left(coins, 1) & "0"))
If Right(coins, 1) <> "0" Then
Result = Result & Digit(Val(Right(coins, 1)))
End If
End If
End If
CalculateCoins = Result
End Function

End Module
 
Last edited by a moderator:
Back
Top