|
我的源码,解决小写转大写,包括负数'金额大写转换
Public Function gMONEY(ByVal smallnum As Double) As String '金额小写变大写
Dim cmoney As String, cnumber As String, cnum As String, cnum_end As String, _
cmon As String, cno, snum As String, sno As String
Dim snum_len As Integer, sint_len As Integer, cbegin As Integer, _
zflag As Integer, i As Integer
If smallnum > 1000000000000# Or smallnum < -99999999999# Or smallnum = 0 Then
gMONEY = ""
Exit Function
End If
cmoney = "仟佰拾亿仟佰拾万仟佰拾元角分" ' 大写人民币单位字符串
cnumber = "壹贰叁肆伍陆柒捌玖" ' 大写数字字符串
cnum = "" ' 转换后的大写数字字符串
cnum_end = "" ' 转换后的大写数字字符串的最后一位
cmon = "" ' 取大写人民币单位字符串中的某一位
cno = "" ' 取大写数字字符串中的某一位
snum = LTrim(Format(smallnum, "############.00")) ' 小写数字字符串
snum_len = Len(snum) ' 小写数字字符串的长度
sint_len = snum_len - 2 ' 小写数字整数部份字符串的长度
sno = "" ' 小写数字字符串中的某个数字字符
cbegin = 15 - snum_len ' 大写人民币单位中的汉字位置
zflag = 1 ' 小写数字字符是否为0(0=0)的判断标志
i = 0 ' 小写数字字符串中数字字符的位置
If snum_len > 15 Then
gMONEY = ""
Exit Function
End If
For i = 1 To snum_len
If i = sint_len Then
GoTo LoopEnd
End If
cbegin = cbegin + 1
cmon = Mid(cmoney, cbegin, 1)
sno = Mid(snum, i, 1)
If sno = "-" Then 'sno
cnum = cnum + "负"
GoTo LoopEnd
ElseIf sno = "0" Then
cnum_end = Right(cnum, 2)
If cbegin = 4 Or (cbegin = 8 And StrComp(cnum_end, "亿", 0) <> 0) Or cbegin = 12 Then
cnum = cnum + cmon
If InStr(1, cnumber, cnum_end, 0) > 0 Then
zflag = 1
Else
zflag = 0
End If 'cnum_end
Else
zflag = 0
End If 'cbegin
GoTo LoopEnd
ElseIf sno <> "0" And zflag = 0 Then
cnum = cnum + "零"
zflag = 1
End If 'sno
cno = Mid(cnumber, Val(sno), 1)
cnum = cnum + cno + cmon
LoopEnd:
Next i
If Right(snum, 1) = "0" Then
gMONEY = cnum + "整"
Else
gMONEY = cnum
End If
End Function
|
|