早教吧 育儿知识 作业答案 考试题库 百科 知识分享

vb阿拉伯数字变汉字a=1996现在要编写一个函数,把变量a变成一千九百九十六也就是阿拉伯数字变小写汉字!

题目详情
vb 阿拉伯数字变汉字
a=1996
现在要编写一个函数,把变量a变成 一千九百九十六
也就是阿拉伯数字变小写汉字!
▼优质解答
答案和解析
Function xx_to_dx(xx As Double) As String '小写转大写
Dim dx As String '大写输出
Dim dw As String
Dim su As String
Dim t As Integer
dw = "角元拾佰仟万拾佰仟亿拾佰仟"
su = "壹贰叁肆伍陆柒捌玖"
Dim s As String
s = Format(xx * 100, "0")
If Len(s) > 14 Then MsgBox ("数位超过千亿,不能转为大写.")
'初始输出字符串
If Right(s, 1) "0" Then
dx = Mid$(su, Val(Right(s, 1)), 1) + "分"
Else
dx = "正"
End If
s = Left(s, Len(s) - 1)
d = 1
Do While (s "")
t = Val(Right(s, 1)): s = Left(s, Len(s) - 1)
If t = 0 Then
dx = "零" + dx
Do
If d = 2 Or d = 6 Or d = 10 Then dx = Mid$(dw, d, 1) + dx
d = d + 1
t = Val(Right(s, 1)): s = Left(s, Len(s) - 1)
Loop Until (t 0)
End If
dx = Mid$(su, t, 1) + Mid$(dw, d, 1) + dx
d = d + 1
Loop
If Right(dx, 2) = "零正" Then dx = Left(dx, Len(dx) - 2) + "正"

xx_to_dx = dx
End Function
Private Sub Form_Load()
MsgBox xx_to_dx(1999)
End Sub