[vb]代码库
Function CapsMoney(curMoney As Currency) As String '转换中文大写金额函数
Dim curMoney1 As Long
Dim i1 As Long '保存整数部分(元部分)
Dim i2 As Integer '保存十分位(角部分)
Dim i3 As Integer '保存百分位(分部分)
Dim s1 As String, s2 As String, s3 As String '保存转换后的字符串
curMoney1 = Round(curMoney * 100) '将金额扩大100倍,并进行四舍五入
i1 = Int(curMoney1 / 100) '获取整数部分
i2 = Int(curMoney1 / 10) - i1 * 10 '获取十分位
i3 = curMoney1 - i1 * 100 - i2 * 10 '获取百分位
s1 = Application.WorksheetFunction.Text(i1, "[dbnum2]") '将整数部分转为中文大写
s2 = Application.WorksheetFunction.Text(i2, "[dbnum2]") '将十分位转为中文大写
s3 = Application.WorksheetFunction.Text(i3, "[dbnum2]") '将百分位转为中文大写
s1 = s1 & "元" '整数部分
If i3 <> 0 And i2 <> 0 Then '分和角都不为0
s1 = s1 & s2 & "角" & s3 & "分"
If i1 = 0 Then '元部分为0
s1 = s2 & "角" & s3 & "分"
End If
End If
If i3 = 0 And i2 <> 0 Then '分为0,角不为0
s1 = s1 & s2 & "角整"
If i1 = 0 Then '元部分为0
s1 = s2 & "角整"
End If
End If
If i3 <> 0 And i2 = 0 Then '分不为0,角为0
s1 = s1 & s2 & s3 & "分"
If i1 = 0 Then '元为0
s1 = s3 & "分"
End If
End If
If Right(s1, 1) = "元" Then s1 = s1 & "整" '为"元"后加上一个"整"字
CapsMoney = s1
End Function
初级程序员
by: 云代码会员 发表于:2015-09-30 17:42:23 顶(0) | 踩(0) 回复
求积分
回复评论