Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Numbers into Language Equivalent

Status
Not open for further replies.

Hartsoe

Programmer
Nov 17, 2001
1
US
For a Finacial programm it is necesary to convert numbers into their English Language Equivalent.
(e.g. $ 123.45 = Onehundred-twenty-three Dollar fourty-five Cents)
Are there any suggestions how to start?
 
This has been (extensively) discussed . Please use the search facillity.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Here Hartsoe is the code far turning numbers into text when writting checks.

Injoy!

Charles

Public Function CurrencyToText(curValue As Currency) As String
Static Ones(10) As String
Static Teens(10) As String
Static Tens(10) As String
Static Thousands(3) As String
Dim i As Integer, nPosition As Integer
Dim nNumber As Integer, nStars As Integer
Dim bZeroValue As Boolean
Dim stResult As String, stTemp As String, stStars As String
Dim stBuffer As String
If curValue > 999999.99 Then
MsgBox "The limit of this function is 999999.99", vbExclamation, "Danger, Danger Will Robinson"
Exit Function
End If
Ones(0) = "zero"
Ones(1) = "one"
Ones(2) = "two"
Ones(3) = "three"
Ones(4) = "four"
Ones(5) = "five"
Ones(6) = "six"
Ones(7) = "seven"
Ones(8) = "eight"
Ones(9) = "nine"
Teens(0) = "ten"
Teens(1) = "eleven"
Teens(2) = "twelve"
Teens(3) = "thirteen"
Teens(4) = "fourteen"
Teens(5) = "fifteen"
Teens(6) = "sixteen"
Teens(7) = "seventeen"
Teens(8) = "eighteen"
Teens(9) = "nineteen"
Tens(0) = ""
Tens(1) = "ten"
Tens(2) = "twenty"
Tens(3) = "thirty"
Tens(4) = "forty"
Tens(5) = "fifty"
Tens(6) = "sixty"
Tens(7) = "seventy"
Tens(8) = "eighty"
Tens(9) = "ninty"
Thousands(0) = ""
Thousands(1) = "thousand"

stResult = "and " & Format((curValue - Int(curValue)) * 100, "00") & "/100"
stTemp = CStr(Int(curValue))
For i = Len(stTemp) To 1 Step -1
nNumber = Val(Mid(stTemp, i, 1))
'Check the position(column) of this digi
nPosition = (Len(stTemp) - i) + 1
Select Case (nPosition Mod 3)
Case 1 'Ones position
bZeroValue = False
If i = 1 Then
stBuffer = Ones(nNumber) & " "
ElseIf Mid(stTemp, i - 1, 1) = "1" Then
stBuffer = Teens(nNumber) & " "
i = i - 1 'Skip tens position
ElseIf nNumber > 0 Then
stBuffer = Ones(nNumber) & " "
Else
bZeroValue = True
If i > 1 Then
If Mid(stTemp, i - 1, 1) <> &quot;0&quot; Then
bZeroValue = False
End If
End If
If i > 2 Then
If Mid(stTemp, i - 2, 1) <> &quot;0&quot; Then
bZeroValue = False
End If
End If
stBuffer = &quot;&quot;
End If
If bZeroValue = False And nPosition > 1 Then
stBuffer = stBuffer & Thousands(nPosition / 3) & &quot; &quot;
End If
stResult = stBuffer & stResult
Case 2 'Tens position
'Numbers like twenty-five need to be hyp
'Check if the digit has a value other th
'digit to see if it has a value other th
If nNumber > 0 And Val(Mid(stTemp, i + 1, 1)) = 0 Then
stResult = Tens(nNumber) & &quot; &quot; & stResult
ElseIf nNumber > 0 And Val(Mid(stTemp, i + 1, 1)) > 0 Then
stResult = Tens(nNumber) & &quot;-&quot; & stResult
End If
Case 0 'Hundreds position
If nNumber > 0 Then
stResult = Ones(nNumber) & &quot; hundred &quot; & stResult
End If
End Select
Next i
If Len(stResult) > 0 Then
stResult = UCase(Left(stResult, 1)) & Mid(stResult, 2)
End If
nStars = 125 - Len(stResult)
For i = 0 To nStars
stStars = stStars + &quot;*&quot;
Next
CurrencyToText = stResult & &quot; &quot; & stStars
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top