|
-
Nov 15th, 2002, 04:02 PM
#1
Thread Starter
Junior Member
text numbers
is there a way to change numbers to text strings?
Let me explain:
I have an application that shows an invoice in a Crystal Report
I have so far the total as, for example: $ 1526.73
is there a way to get this value on the fly and create a variable that shows the text?
such as: (one thousand five hundred and twenty six 73/100)
Thanx .
... on a steel horse I ride, I'm wanted dead or... Dead!...
-
Nov 15th, 2002, 04:20 PM
#2
I did a search of our forums for thousand and came up with a lot of hits including this thread. The code in that thread from BuggyProgrammaer looks like it works, but I haven't tested it.
-
Nov 15th, 2002, 04:30 PM
#3
This should do the job too:
VB Code:
Option Explicit
Public Function ToWords(ByVal nAmount As Currency) As String
Dim vSingle As Variant
Dim vTen As Variant
Dim sWords As String
Dim nNew As Currency
vSingle = Split("One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen", ",")
vTen = Split("Ten,Twenty,Thirty,Fourty,Fifty,Sixty,Seventy,Eighty,Ninety", ",")
Do While (nAmount > 0)
If nAmount > 1000000 Then
nNew = Int(nAmount / 1000000)
sWords = sWords & ToWords(nNew) & "MILLION, "
nAmount = nAmount - (Int(nAmount / 1000000) * 1000000)
ElseIf nAmount > 1000 Then
nNew = Int(nAmount / 1000)
sWords = sWords & ToWords(nNew) & "THOUSAND, "
nAmount = nAmount - (Int(nAmount / 1000) * 1000)
ElseIf nAmount > 100 Then
nNew = Int(nAmount / 100)
sWords = sWords & ToWords(nNew) & "HUNDRED AND "
nAmount = nAmount - (Int(nAmount / 100) * 100)
ElseIf nAmount > 10 Then
nNew = Int(nAmount / 10)
If nNew > 1 Then
sWords = sWords & vTen(nNew - 1) & " "
Else
sWords = sWords & vSingle(nAmount - 1) & " "
nAmount = 0
End If
nAmount = nAmount - (Int(nAmount / 10) * 10)
ElseIf nAmount > 0 Then
sWords = sWords & vSingle(nAmount - 1) & " "
nAmount = 0
End If
Loop
If Right(sWords, 2) = ", " Then
sWords = Left(sWords, Len(sWords) - 2)
ElseIf Right(sWords, 5) = " AND " Then
sWords = Left(sWords, Len(sWords) - 5)
End If
ToWords = UCase(sWords)
End Function
-
Nov 15th, 2002, 04:45 PM
#4
Need-a-life Member
-
Nov 15th, 2002, 05:13 PM
#5
Thread Starter
Junior Member
thnx guys I'll probe and tell ya
... on a steel horse I ride, I'm wanted dead or... Dead!...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|