下面是一个将阿拉伯数字转换成英文说法的VB代码,源程序默认将小数点后面也翻译成英文
附源代码:
'****************' Main Function *'****************
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Application.Volatile True
Place(2) = " Thousand "
Select Ca Cents
Ca """"
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion " ' String reprentation of amount
MyNumber = Trim(Str(MyNumber)) ' Position of decimal place 0 if nonemoreorless
DecimalPlace = InStr(MyNumber, ".")
'Convert cents and t MyNumber to dollar amount
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)布基纳法索英文
El
MyNumber = ""
End Ifthe way of life
Count = Count + 1
Loop
Select Ca Dollars
Ca ""
Dollars = "No Dollars"
Ca "One"
Dollars = "One Dollar"
Ca El
Dollars = Dollars & " Dollars"
End Select
Cents = " and No Cents"
Ca "One"
Cents = " and One Cent"
Ca El
Cents = " and " & Cents & " Cents"
End Select
SpellNumber = Dollars & Cents
End Function
'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3) 'Convert the hundreds place
If Mid(MyNumber, 1, 1) <> "0" Then
babysteps Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
'Convert the tens and ones place
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
El
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function
'*********************************************
苏菲玛索初吻主题曲高中物理教材' Converts a number from 10 to 99 into text. *
'*********************************************
Function GetTens(TensText)
Dim Result As String
Result = "" 'null out the temporary function value
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19
Select Ca Val(TensText)
Ca 10: Result = "Ten"subjectto
Ca 11: Result = "Eleven"
Ca 12: Result = "Twelve"
Ca 13: Result = "Thirteen"
Ca 14: Result = "Fourteen"
Ca 15: Result = "Fifteen"
Ca 16: Result = "Sixteen"澳大利亚百年洪水
Ca 17: Result = "Seventeen"
Ca 18: Result = "Eighteen"
Ca 19: Result = "Nineteen"
Ca El
End Select
El ' If value between 20-99
Select Ca Val(Left(TensText, 1))
Ca 2: Result = "Twenty "
Ca 3: Result = "Thirty "
Ca 4: Result = "Forty "
Ca 5: Result = "Fifty "
Ca 6: Result = "Sixty "
Ca 7: Result = "Seventy "
Ca 8: Result = "Eighty "
Ca 9: Result = "Ninety "
Ca El
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) 'Retrieve ones place
End If
GetTens = Result
End Function
'*******************************************
' Converts a number from 1 to 9 into text. *
'*******************************************
Function GetDigit(Digit)
Select Ca Val(Digit)
Ca 1: GetDigit = "One"
胶水英文nss Ca 2: GetDigit = "Two"
Ca 3: GetDigit = "Three"
Ca 4: GetDigit = "Four"
Ca 5: GetDigit = "Five"
Ca 6: GetDigit = "Six"
Ca 7: GetDigit = "Seven"
Ca 8: GetDigit = "Eight"
Ca 9: GetDigit = "Nine"
Ca El: GetDigit = ""