|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Option Base 1
Public Function NumberToChinese(阿拉伯數字 As String, 中文大寫 As Boolean, 中阿混寫 As Boolean, 補零 As Boolean, 貨幣 As Boolean, Optional 貨幣符號 As String) As String
Application.Volatile
Dim 中文數字陣列 As Variant
Dim 中文大寫數字陣列 As Variant
Dim 數字小單位陣列 As Variant
Dim 大寫數字小單位陣列 As Variant
Dim 數字大單位陣列 As Variant
Dim 小數單位陣列 As Variant
Dim K As Long
Dim N As Long
Dim SMALL1 As String
Dim SMALL2 As String
Dim TEMP1 As String
Dim TEMP2 As String
Dim TEMP3 As String
Dim 正整數 As String
Dim 小數 As String
Dim 組數 As Long
Dim 零值 As String
Dim 補零值 As Long
Dim 組補零值 As Long
On Error GoTo line
中文數字陣列 = Array("○", "一", "二", "三", "四", "五", "六", "七", "八", "九")
中文大寫數字陣列 = Array("零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖")
數字小單位陣列 = Array("", "十", "百", "千")
大寫數字小單位陣列 = Array("", "拾", "佰", "仟")
數字大單位陣列 = Array("", "萬", "億", "兆", "京", "垓")
小數單位陣列 = Array("分", "角")
If 中文大寫 = True Then
零值 = "零"
Else
零值 = "○"
End If
小數 = Fix(阿拉伯數字)
If 小數 = 0 And 阿拉伯數字 < 0 Then
小數 = Len(小數) + 1
Else
小數 = Len(小數)
End If
If Len(阿拉伯數字) = 小數 Then
If 貨幣 = True Then
NumberToChinese = IIf(中文大寫 = True, "圓整", "元整")
End If
GoTo line1
End If
小數 = Mid(阿拉伯數字, 小數 + 2, Len(阿拉伯數字) - 小數 - 1)
If 中阿混寫 = True Then
If 貨幣 = True Then
NumberToChinese = IIf(中文大寫 = True, "圓", "元") & 小數
Else
NumberToChinese = "點" & 小數
End If
Else
If 貨幣 = True Then
If Len(小數) > 1 Then
小數 = Mid(小數, 1, 2)
Else
小數 = 小數 * 10
End If
SMALL2 = ""
補零值 = 0
For N = 1 To Len(小數)
If Mid(小數, Len(小數) - N + 1, 1) = 0 Then
If N = 1 Then
補零值 = 補零值 + 1
SMALL1 = ""
Else
[ 本帖最后由 linyancheng 于 2009-8-19 14:22 编辑 ] |
|