稍微改一下。 Private Sub Command1_Click() Label1.Caption = rmb(Val(Text1.Text)) End SubPrivate Function rmb(s As Currency) As String Dim s2 As String s1 = LTrim(Str(Abs(s))) l = Len(s1) Select Case l - InStrRev(s1, ".") Case l s2 = s1 + ".00" Case 1 s2 = s1 + "0" Case 2 s2 = s1 End Select l = Len(s2) dx = "" c1 = "零壹贰叁肆伍陆柒捌玖“" c2 = "分角 元拾佰仟万拾佰仟亿拾佰”" Do While l >= 1 x = Mid(s2, Len(s2) - l + 1, 1) dx = dx + IIf(x <> ".", Mid(c1, Val(x) + 1, 1) + Trim(Mid(c2, (l - 1) + 1, 1)), "") l = l - 1 Loop rmb = dx End Function
算法很多:'函数说明:大小写金额转换 '参数说明:需要转换的阿拉伯数字,最长为14位,可以有负数 '返回值说明:转换后的大写汉字 Public Function Int2Chn(ByVal L_num As Integer) As String Dim n_data, num, c_data, n_str As String Dim i, j, k, l As Long num = L_num n_data = String(14 - Len(Trim(CStr(Abs(num * 100)))), " ") + Trim(CStr(Abs(num) * 100)) For i = 1 To 14 Step 1 n_str = Mid(n_data, i, 1) If n_str <> " " Then If Mid(n_data, i, 2) = "00" Or (n_str = "0" And (i = 4 Or i = 8 Or i = 12 Or i = 14)) Then Else c_data = c_data + Trim(Mid("零壹贰叁肆伍陆柒捌玖", CInt(n_str) + 1, 1)) End If If n_str = "0" And i <> 4 And i <> 8 And i <> 12 Then Else c_data = c_data + Trim(Mid("仟佰拾亿仟佰拾万仟佰拾圆角分", i, 1)) End If If Right(c_data, 4) = "亿万" Then c_data = Left(c_data, Len(c_data) - 1) End If Next If num < 0 Then c_data = "(负数)" + c_data If num = 0 Then c_data = "零圆" If n_str = "0" Then c_data = c_data + "整" Int2Chn = c_data End Function
这个也很经典 ----------------------------------------dim chap(21, 1)初始化: chap(0, 0) = "万": chap(0, 1) = 10000 chap(1, 0) = "仟": chap(1, 1) = 1000 chap(2, 0) = "佰": chap(2, 1) = 100 chap(3, 0) = "拾": chap(3, 1) = 10 chap(4, 0) = "元": chap(4, 1) = 1 chap(5, 0) = "角": chap(5, 1) = 0.1 chap(6, 0) = "分": chap(6, 1) = 0.01 chap(11, 0) = "壹": chap(11, 1) = 1 chap(12, 0) = "贰": chap(12, 1) = 2 chap(13, 0) = "叁": chap(13, 1) = 3 chap(14, 0) = "肆": chap(14, 1) = 4 chap(15, 0) = "伍": chap(15, 1) = 5 chap(16, 0) = "陆": chap(16, 1) = 6 chap(17, 0) = "柒": chap(17, 1) = 7 chap(18, 0) = "捌": chap(18, 1) = 8 chap(19, 0) = "玖": chap(19, 1) = 9 chap(20, 0) = "零": chap(20, 1) = 0 chap(21, 0) = "亿": chap(21, 1) = 100000000function subtochinese(price as integer) '转化千百十 dim i as integer dim num(15) as integer i = 1 do until price = 0 num(i) = int(price / chap(i, 1)) if num(i) <> 0 then subtochinese = subtochinese & chap(num(i) + 10, 0) & chap(i, 0) price = price - num(i) * chap(i, 1) else if subtochinese <> "" and right(subtochinese, 1) <> "零" then subtochinese = subtochinese & "零" end if end if i = i + 1 loop if right(subtochinese, 1) = "元" then subtochinese = left(subtochinese, len(subtochinese) - 1) end if end functionfunction pricetochinese(price as double) if price >= 100000000 then '大于1亿 pricetochinese = pricetochinese & pricetochinese(int(price / 100000000)) & "亿" price = price - int(price / 100000000) * 100000000 end if if price >= 10000 then pricetochinese = pricetochinese & subtochinese(int(price / 10000)) & "万" price = price - int(price / 10000) * 10000 end if if int(price) <> 0 then '如果万与千间无数,则应添零 if pricetochinese <> "" and int(price) < 1000 then pricetochinese = pricetochinese & "零" end if pricetochinese = pricetochinese & subtochinese(int(price)) price = price - int(price) end if if pricetochinese <> "" then pricetochinese = pricetochinese & "元" if price = 0 then '到元为止 pricetochinese = pricetochinese & "整" else price = int(price * 100) if int(price / 10) <> 0 then pricetochinese = pricetochinese & chap(int(price / 10) + 10, 0) & "角" price = price - int(price / 10) * 10 end if if price <> 0 then pricetochinese = pricetochinese & chap(int(price) + 10, 0) & "分"
end if end if end function 调用时:pricetochinese(123432435.345)
Private Sub Command1_Click()
Label1.Caption = rmb(Val(Text1.Text))
End SubPrivate Function rmb(s As Currency) As String
Dim s2 As String
s1 = LTrim(Str(Abs(s)))
l = Len(s1)
Select Case l - InStrRev(s1, ".")
Case l
s2 = s1 + ".00"
Case 1
s2 = s1 + "0"
Case 2
s2 = s1
End Select
l = Len(s2)
dx = ""
c1 = "零壹贰叁肆伍陆柒捌玖“"
c2 = "分角 元拾佰仟万拾佰仟亿拾佰”"
Do While l >= 1
x = Mid(s2, Len(s2) - l + 1, 1)
dx = dx + IIf(x <> ".", Mid(c1, Val(x) + 1, 1) + Trim(Mid(c2, (l - 1) + 1, 1)), "")
l = l - 1
Loop
rmb = dx
End Function
'参数说明:需要转换的阿拉伯数字,最长为14位,可以有负数
'返回值说明:转换后的大写汉字
Public Function Int2Chn(ByVal L_num As Integer) As String
Dim n_data, num, c_data, n_str As String
Dim i, j, k, l As Long
num = L_num
n_data = String(14 - Len(Trim(CStr(Abs(num * 100)))), " ") + Trim(CStr(Abs(num) * 100))
For i = 1 To 14 Step 1
n_str = Mid(n_data, i, 1)
If n_str <> " " Then
If Mid(n_data, i, 2) = "00" Or (n_str = "0" And (i = 4 Or i = 8 Or i = 12 Or i = 14)) Then
Else
c_data = c_data + Trim(Mid("零壹贰叁肆伍陆柒捌玖", CInt(n_str) + 1, 1))
End If
If n_str = "0" And i <> 4 And i <> 8 And i <> 12 Then
Else
c_data = c_data + Trim(Mid("仟佰拾亿仟佰拾万仟佰拾圆角分", i, 1))
End If
If Right(c_data, 4) = "亿万" Then c_data = Left(c_data, Len(c_data) - 1)
End If
Next
If num < 0 Then c_data = "(负数)" + c_data
If num = 0 Then c_data = "零圆"
If n_str = "0" Then c_data = c_data + "整"
Int2Chn = c_data
End Function
----------------------------------------dim chap(21, 1)初始化: chap(0, 0) = "万": chap(0, 1) = 10000
chap(1, 0) = "仟": chap(1, 1) = 1000
chap(2, 0) = "佰": chap(2, 1) = 100
chap(3, 0) = "拾": chap(3, 1) = 10
chap(4, 0) = "元": chap(4, 1) = 1
chap(5, 0) = "角": chap(5, 1) = 0.1
chap(6, 0) = "分": chap(6, 1) = 0.01
chap(11, 0) = "壹": chap(11, 1) = 1
chap(12, 0) = "贰": chap(12, 1) = 2
chap(13, 0) = "叁": chap(13, 1) = 3
chap(14, 0) = "肆": chap(14, 1) = 4
chap(15, 0) = "伍": chap(15, 1) = 5
chap(16, 0) = "陆": chap(16, 1) = 6
chap(17, 0) = "柒": chap(17, 1) = 7
chap(18, 0) = "捌": chap(18, 1) = 8
chap(19, 0) = "玖": chap(19, 1) = 9
chap(20, 0) = "零": chap(20, 1) = 0
chap(21, 0) = "亿": chap(21, 1) = 100000000function subtochinese(price as integer)
'转化千百十
dim i as integer
dim num(15) as integer
i = 1
do until price = 0
num(i) = int(price / chap(i, 1))
if num(i) <> 0 then
subtochinese = subtochinese & chap(num(i) + 10, 0) & chap(i, 0)
price = price - num(i) * chap(i, 1)
else
if subtochinese <> "" and right(subtochinese, 1) <> "零" then
subtochinese = subtochinese & "零"
end if
end if
i = i + 1
loop
if right(subtochinese, 1) = "元" then
subtochinese = left(subtochinese, len(subtochinese) - 1)
end if
end functionfunction pricetochinese(price as double)
if price >= 100000000 then '大于1亿
pricetochinese = pricetochinese & pricetochinese(int(price / 100000000)) & "亿"
price = price - int(price / 100000000) * 100000000
end if
if price >= 10000 then
pricetochinese = pricetochinese & subtochinese(int(price / 10000)) & "万"
price = price - int(price / 10000) * 10000
end if
if int(price) <> 0 then '如果万与千间无数,则应添零
if pricetochinese <> "" and int(price) < 1000 then
pricetochinese = pricetochinese & "零"
end if
pricetochinese = pricetochinese & subtochinese(int(price))
price = price - int(price)
end if
if pricetochinese <> "" then pricetochinese = pricetochinese & "元"
if price = 0 then '到元为止
pricetochinese = pricetochinese & "整"
else
price = int(price * 100)
if int(price / 10) <> 0 then
pricetochinese = pricetochinese & chap(int(price / 10) + 10, 0) & "角"
price = price - int(price / 10) * 10
end if
if price <> 0 then
pricetochinese = pricetochinese & chap(int(price) + 10, 0) & "分"
end if
end if
end function
调用时:pricetochinese(123432435.345)