阿拉伯数字转换成英文大写

萌到你眼炸
659次浏览
2021年02月24日 11:04
最佳经验
本文由作者推荐

-

2021年2月24日发(作者:一什么一什么的成语)


启动



Microsoft Excel






Alt+F11


启动



Visual Basic


编辑器。



在“插入”菜单上,单击“模块”




在模块表中键入下面的代码。



Option Explicit


'Main Function


Function SpellNumber(ByValMyNumber)






Dim Dollars, Cents, Temp






Dim DecimalPlace, Count


ReDimPlace(9) As String


Place(2) =


Place(3) =


Place(4) =


Place(5) =


' String representation of amount.


MyNumber = Trim(Str(MyNumber))


' Position of decimal place 0 if none.


DecimalPlace = InStr(MyNumber,


' Convert cents and set MyNumber to dollar amount.






If DecimalPlace> 0 Then










Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _





















MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))






End If






Count = 1






Do While MyNumber<>










Temp = GetHundreds(Right(MyNumber, 3))










If Temp <>










If Len(MyNumber) > 3 Then


MyNumber = Left(MyNumber, Len(MyNumber) - 3)










Else


MyNumber =










End If










Count = Count + 1






Loop






Select Case Dollars










Case














Dollars =










Case














Dollars =











Case Else














Dollars = Dollars &






End Select






Select Case Cents










Case














Cents =










Case














Cents =
















Case Else














Cents =






End Select


SpellNumber = Dollars & Cents


End Function



' Converts a number from 100-999 into text



Function GetHundreds(ByValMyNumber)






Dim Result As String






If Val(MyNumber) = 0 Then Exit Function


MyNumber = Right(


' Convert the hundreds place.






If Mid(MyNumber, 1, 1) <>










Result = GetDigit(Mid(MyNumber, 1, 1)) &






End If


' Convert the tens and ones place.






If Mid(MyNumber, 2, 1) <>










Result = Result &GetTens(Mid(MyNumber, 2))






Else










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 Case V


al(TensText)














Case 10: Result =














Case 11: Result =














Case 12: Result =














Case 13: Result =














Case 14: Result =














Case 15: Result =














Case 16: Result =














Case 17: Result =














Case 18: Result =














Case 19: Result =

-


-


-


-


-


-


-


-