国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > VBScript > 正文

VBS 數(shù)字轉(zhuǎn)英文代碼

2020-06-26 18:21:53
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
Excel 中將數(shù)值轉(zhuǎn)換為英文單詞
 
如何創(chuàng)建名為 SpellNumber 的示例函數(shù) 
啟動(dòng) Microsoft Excel。 
按 Alt+F11 啟動(dòng) Visual Basic 編輯器。 
在“插入”菜單上,單擊“模塊”。 
在模塊表中鍵入下面的代碼。
復(fù)制代碼代碼如下:

Option Explicit 
'Main Function 
Function SpellNumber(ByVal MyNumber) 
Dim Dollars, Cents, Temp 
Dim DecimalPlace, Count 
ReDim Place(9) As String 
Place(2) = " Thousand " 
Place(3) = " Million " 
Place(4) = " Billion " 
Place(5) = " Trillion " 
' 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) & _ 
"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) 
Else 
MyNumber = "" 
End If 
Count = Count + 1 
Loop 
Select Case Dollars 
Case "" 
Dollars = "No Dollars" 
Case "One" 
Dollars = "One Dollar" 
Case Else 
Dollars = Dollars & " Dollars" 
End Select 
Select Case Cents 
Case "" 
Cents = " and No Cents" 
Case "One" 
Cents = " and One Cent" 
Case Else 
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 
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)) 
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 Val(TensText) 
Case 10: Result = "Ten" 
Case 11: Result = "Eleven" 
Case 12: Result = "Twelve" 
Case 13: Result = "Thirteen" 
Case 14: Result = "Fourteen" 
Case 15: Result = "Fifteen" 
Case 16: Result = "Sixteen" 
Case 17: Result = "Seventeen" 
Case 18: Result = "Eighteen" 
Case 19: Result = "Nineteen" 
Case Else 
End Select 
Else ' If value between 20-99... 
Select Case Val(Left(TensText, 1)) 
Case 2: Result = "Twenty " 
Case 3: Result = "Thirty " 
Case 4: Result = "Forty " 
Case 5: Result = "Fifty " 
Case 6: Result = "Sixty " 
Case 7: Result = "Seventy " 
Case 8: Result = "Eighty " 
Case 9: Result = "Ninety " 
Case Else 
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 Case Val(Digit) 
Case 1: GetDigit = "One" 
Case 2: GetDigit = "Two" 
Case 3: GetDigit = "Three" 
Case 4: GetDigit = "Four" 
Case 5: GetDigit = "Five" 
Case 6: GetDigit = "Six" 
Case 7: GetDigit = "Seven" 
Case 8: GetDigit = "Eight" 
Case 9: GetDigit = "Nine" 
Case Else: GetDigit = "" 
End Select 
End Function 

如何使用 SpellNumber 示例函數(shù) 
要使用該示例函數(shù)將某數(shù)字更改為書(shū)面文本,請(qǐng)使用下列示例中演示的方法之一: 
回到頂端 
方法 1:直接輸入 
通過(guò)將下面的公式輸入單元格中,可以將 32.50 更改為“Thirty Two Dollars and Fifty Cents”: 
=SpellNumber(32.50) 
回到頂端 
方法 2:?jiǎn)卧褚?nbsp;
可以引用工作簿中的其他單元格。例如,在單元格 A1 中輸入數(shù)字 32.50,然后在另一單元格中鍵入下面的公式: 
=SpellNumber(A1) 
回到頂端 
方法 3:粘貼函數(shù)或插入函數(shù) 
可以使用“粘貼函數(shù)”(在 Excel 2000 和 Excel 2002 中)或“插入函數(shù)”(在 Excel 2003 中)來(lái)將自定義函數(shù)輸入工作表中。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 秦安县| 宿州市| 五家渠市| 晴隆县| 仲巴县| 桂平市| 镇赉县| 南川市| 伊吾县| 鄂托克前旗| 石家庄市| 绥德县| 广汉市| 民县| 新余市| 宁城县| 建阳市| 濮阳县| 新建县| 阿克| 安仁县| 景宁| 阳新县| 吉木乃县| 开化县| 台南市| 鲜城| 临海市| 元江| 卓尼县| 大荔县| 宝兴县| 佛学| 彝良县| 博爱县| 和政县| 彩票| 沁水县| 左云县| 绥宁县| 吉隆县|