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

发布时间:2020-01-07 发布网站:大佬教程
大佬教程收集整理的这篇文章主要介绍了将数字翻译成纯英文书写方式大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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

大佬总结

以上是大佬教程为你收集整理的将数字翻译成纯英文书写方式全部内容,希望文章能够帮你解决将数字翻译成纯英文书写方式所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ群:277859234,请注明来意。