Office中国论坛/Access中国论坛
标题:
上次看到朋友发了一个金额数字转成大写的代码,现在我发一个转成英语大写的代码,用
[打印本页]
作者:
jetplayer
时间:
2005-7-7 21:55
标题:
上次看到朋友发了一个金额数字转成大写的代码,现在我发一个转成英语大写的代码,用
Function SAY(数量 As Long) As String
Dim buff As String, done As String
Static units(10) As String, teens(10) As String
Static tens(10) As String, denoms(4) As String
Dim length As Integer, i As Integer, passes As Integer, temp As Integer
units(1) = "ONE ": units(2) = "TWO ": units(3) = "THREE "
units(4) = "FOUR ": units(5) = "FIVE ": units(6) = "SIX "
units(7) = "SEVEN ": units(8) = "EIGHT ": units(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(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) = "NINETY"
denoms(1) = "HUNDRED ": denoms(2) = "THOUSAND ": denoms(3) = "MILLION "
buff = Format$(数量, "#########")
length = Len(buff)
temp = 0
Do While (length > 0)
Select Case (length Mod 3)
Case 0
If Len(done) > 0 Then
done = done & denoms(length / 3 + 1)
End If
If Mid$(buff, 1, 1) <> "0" Then
i = Val(Mid$(buff, 1, 1))
done = done & units(i)
done = done & denoms(1)
End If
Case 1
If Mid$(buff, 1, 1) <> "0" Then
i = Val(Mid$(buff, 1, 1))
If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" And temp = 0 Then
done = done & "AND "
End If
done = done & units(i)
End If
Case 2
If Mid$(buff, 1, 1) = "1" Then
i = Val(Mid$(buff, 2, 1))
If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" Then
done = done & "AND "
End If
done = done & teens(i)
length = length - 1
buff = Mid$(buff, 2)
Else
i = Val(Mid$(buff, 1, 1))
If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" Then
done = done & "AND "
End If
done = done & tens(i)
If Mid$(buff, 1, 1) <> "0" And Mid$(buff, 2, 1) <> "0" Then
done = done & "-"
temp = 1
Else
If Mid$(buff, 1, 1) > "1" And Mid$(buff, 2, 1) = "0" Then
done = done & " "
End If
temp = 0
End If
End If
End Select
length = length - 1
buff = Mid$(buff, 2)
Loop
If 数量 < 1000000000 Then
SAY = done
Else
SAY = "大于等于拾亿"
End If
End Function
作者:
海狸先生
时间:
2005-7-7 22:46
不支持小数点哦
作者:
jetplayer
时间:
2005-7-13 17:18
呵呵,给老外开发票,基本上我们都开整数了。
作者:
secowu
时间:
2005-8-17 16:44
海狸给整个: 金额转换成大写人民币和大写英语的吧 这个模块很实用
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3