将数字翻译成纯英文书写方式

Private Sub Form_Load() Debug.Print num2EngStr("1") & Chr(13) Debug.Print num2EngStr("21") & Chr(13) Debug.Print num2EngStr("321") & Chr(13) Debug.Print num2EngStr("4321") & Chr(13) Debug.Print num2EngStr("54321") & Chr(13) Debug.Print num2EngStr("654321") & Chr(13) Debug.Print num2EngStr("7654321") & Chr(13) Debug.Print num2EngStr("87654321") & Chr(13) Debug.Print num2EngStr("987654321") & Chr(13) Debug.Print num2EngStr("10987654321") & Chr(13) Debug.Print num2EngStr("210987654321") & Chr(13) Debug.Print num2EngStr("3210987654321") & Chr(13) Debug.Print num2EngStr("43210987654321") & Chr(13) Debug.Print num2EngStr("543210987654321") & Chr(13) Debug.Print num2EngStr("6543210987654321") & Chr(13) Debug.Print num2EngStr("76543210987654321") & Chr(13) Debug.Print num2EngStr("876543210987654321") & Chr(13) End Sub '以下只适用于正整数 Private Function num2EngStr(ByVal strNum As String) As String Dim aNum As String,bNum As String,cNum As String,dNum As String,fNum As String Dim aNums() As String,bNums() As String,cNums() As String,dNums() As String,fNums() As String aNum = "0,1,2,3,4,5,6,7,8,9" bNum = "zero,one,two,three,four,five,six,seven,eight,nine" '个位 cNum = "ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen," '十几 dNum = "twenty,thirty,fourty,fifty,sixty,seventy,eighty,ninety" fNum = ",hundred,thousand,million,billion,trillion," '2--十 3--百 4--千 7--百万 10--10十亿 13--万亿 aNums = Split(aNum,",vbTextCompare) bNums = Split(bNum,vbTextCompare) cNums = Split(cNum,vbTextCompare) dNums = Split(dNum,vbTextCompare) fNums = Split(fNum,vbTextCompare) Dim lenNum As Integer,i As Integer,strC As String,index As Integer,isTenbit As Boolean Dim strs As String,strAll As String,strCut As String lenNum = Len(strNum) ' If lenNum > 16 Then MsgBox "超出范围" For i = lenNum To 1 Step -1 strs = "" index = Int(Mid(strNum,lenNum - i + 1,1)) strC = aNums(index) Select Case i Case 1 strs = " " & IIf(isTenbit,cNums(index),bNums(index)) Case 2 If Int(strC) > 1 Then strs = dNums(index - 2) ElseIf Int(strC) = 1 Then isTenbit = True End If Case Else If fNums(i - 1) = "" Then strCut = strCut & strC Else If strCut <> "" Then strCut = num2EngStr(strCut & strC) strs = strCut & " " & fNums(i - 1) & IIf(fNums(i - 1) = "hundred"," and "," ") '只有百位与十位相连才要and strCut = "" Else strs = bNums(index) & " " & fNums(i - 1) & IIf(fNums(i - 1) = "hundred"," ") '只有百位与十位相连才要and End If End If End Select strAll = strAll & strs Next num2EngStr = strAll End Function 输出结果: one twenty one three hundred and twenty one four thousand three hundred and twenty one fifty four thousand three hundred and twenty one six hundred and fifty four thousand three hundred and twenty one seven million six hundred and fifty four thousand three hundred and twenty one eighty seven million six hundred and fifty four thousand three hundred and twenty one nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one three trillion two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one fourty three trillion two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one five hundred and fourty three trillion two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one six thousand five hundred and fourty three trillion two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one seventy six thousand five hundred and fourty three trillion two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one eight hundred and seventy six thousand five hundred and fourty three trillion two hundred and ten billion nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twenty one

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...