Excel 将金额转换成大写字母函数

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

展开阅读全文

没有更多推荐了,返回首页