如何实现人民币的数字形式转换成大写形式
编号:QA001571
建立日期: 1999年8月23日 最后修改日期:1999年8月30日
所属类别:
Riptide:
VB
Win98
如何实现人民币的数字形式转换成大写形式?
回答:
使用下面这个函数,如Print ChineseFormat(11.4)。
Function ChineseFormat(n As Variant)
Dim s As String, sFormat As String
Dim i As Integer, c As String
Const sString = "分角元拾佰仟万拾佰仟亿拾佰仟万"
Const sNumber = "零壹贰叁肆伍陆柒捌玖"
s = Format(Int(n * 100))
sFormat = ""
For i = Len(s) To 1 Step -1
c = Mid(s, i, 1)
sFormat = Mid(sNumber, Val(c) _
+ 1, 1) + Mid(sString, Len(s) - i + 1, 1) _
+ sFormat
Next
ChineseFormat = sFormat
End Function
对于数字中出现0的情况,如
Print ChineseFormat(2008.04)
这个函数的输出结果是“贰仟零佰零拾捌元零角肆分”,如果希望结果是“贰仟零捌元零角肆分”。可以修改函数为:
Function ChineseFormat(n As Variant)
Dim s As String, sFormat As String
Dim i As Integer, c As String
Const sString = "分角元拾佰仟万拾佰仟亿拾佰仟万"
Const sNumber = "零壹贰叁肆伍陆柒捌玖"
s = Format(Int(n * 100))
sFormat = ""
For i = Len(s) To 1 Step -1
c = Mid(s, i, 1)
If c = "0" Then
Select Case Len(s) - i
Case Is <= 1 ' 0在元之后
sFormat = "零" + Mid(sString, Len(s) - i + 1, 1) _
+ sFormat
Case 2 ' 元
sFormat = "元" + sFormat
Case Else
If Mid(s, i + 1, 1) <> "0" Then sFormat = "零" + sFormat
End Select
Else
sFormat = Mid(sNumber, Val(c) _
+ 1, 1) + Mid(sString, Len(s) - i + 1, 1) _
+ sFormat
End If
Next
ChineseFormat = sFormat
End Function
相关问题:
QA001363 "如何将数字转换成英文的说法"
此问题由李海回答。
| |
|
|
| |
|
|