|
用这个也行
Function Etoc(thenumber)
Dim Money, i, String1, String2, length, checkp '定义变量
Dim one(), onestr() '定义数组
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分厘毫"
checkp = InStr(thenumber, ".") '判断是否含有小数位
If checkp <> 0 Then
thenumber = Replace(thenumber, ".", "") '去除小数位
End If
length = Len(thenumber) '取得数据长度
ReDim one(length - 1) '重新定义数组大小
ReDim onestr(length - 1) '重新定义数组大小
For i = 0 To length - 1
one(i) = Mid(thenumber, i + 1, 1) '循环取得每一位的数字
one(i) = Mid(String1, one(i) + 1, 1) '循环取得数字对应的大写
If checkp = 0 Then
'不含有小数的数据其数字对应的单位
onestr(i) = Mid(String2, 14 - length + i, 1)
Else
'含有小数的数据其数字对应的单位
onestr(i) = Mid(String2, 15 - length + i + Len(thenumber) - checkp, 1)
End If
one(i) = one(i) & onestr(i) '将数字与单位组合
Next
Money = Replace(Join(one), " ", "") '取得数组中所有的元素,并连接起来
Money = Replace(Money, "零元", "元")
Money = Replace(Money, "零万", "万")
Money = Replace(Money, "零亿", "亿")
Money = Replace(Money, "零仟", "零")
Money = Replace(Money, "零佰", "零")
Money = Replace(Money, "零拾", "零")
Do While Not InStr(Money, "零零") = 0
Money = Replace(Money, "零零", "零")
Loop
Etoc = Money
Debug.Print Money
End Function |
|