| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:初来,发一个函数!
取消只看楼主 加入收藏
满江红
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-2-16
收藏
 问题点数:0 回复次数:1 
初来,发一个函数!
'将小写金额转换成大写金额
Public Function ToChinMoney(pStrEng As String) As String
On Error GoTo Err
pStrEng = ToChinNum(CStr(Round(CDec(pStrEng), 2)))
Dim intLen As Integer
intLen = InStr(pStrEng, "点")
If intLen <= 0 Then
pStrEng = pStrEng & "元整"
Else
pStrEng = Replace(pStrEng, "点", "元")
pStrEng = Left(pStrEng, intLen + 1) & "角" & Right(pStrEng, Len(pStrEng) - intLen - 1)
If Right(pStrEng, 1) = "角" Then
pStrEng = pStrEng & "整"
Else
pStrEng = pStrEng & "分"
End If
End If
If pStrEng <> "零元整" Then
pStrEng = Replace(pStrEng, "零元", "")
End If
ToChinMoney = pStrEng
Exit Function
Err:
ToChinMoney = ""
End Function
2006-02-16 12:06
满江红
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-2-16
收藏
得分:0 
'将小写数字转换成大写数字:
Public Function ToChinNum(pStrEng As String) As String
On Error GoTo Err
If Not IsNumeric(pStrEng) Then
ToChinNum = ""
Exit Function
End If
Dim strEng2Ch As String, strSeqCh1 As String, strSeqCh2 As String
Dim strCh As String, strTempCh As String, strTempXs As String
Dim intLen As Integer, i As Integer
strEng2Ch = "零壹贰叁肆伍陆柒捌玖"
strSeqCh1 = " 拾佰仟 拾佰仟 拾佰仟 拾佰仟"
strSeqCh2 = " 万亿兆"
pStrEng = CStr(CDec(pStrEng))
If Left(pStrEng, 1) = "-" Then '是负数
strCh = "负"
pStrEng = Right(pStrEng, Len(pStrEng) - 1)
End If
intLen = InStr(pStrEng, ".")
If intLen > 0 Then '有小数
strTempXs = Right(pStrEng, Len(pStrEng) - intLen)
pStrEng = Left(pStrEng, intLen - 1)
End If
intLen = Len(pStrEng)
For i = 1 To intLen
strTempCh = Mid(strEng2Ch, Val(Mid(pStrEng, i, 1)) + 1, 1)
If strTempCh = "零" And intLen <> 1 Then
If Mid(pStrEng, i + 1, 1) = "0" Or (intLen - i + 1) Mod 4 = 1 Then
strTempCh = ""
End If
Else
strTempCh = strTempCh & Trim(Mid(strSeqCh1, intLen - i + 1, 1))
End If
If (intLen - i + 1) Mod 4 = 1 Then
strTempCh = strTempCh & Mid(strSeqCh2, (intLen - i + 1) \ 4 + 1, 1)
If i > 3 Then
If Mid(pStrEng, i - 3, 4) = "0000" Then strTempCh = Left(strTempCh, Len(strTempCh) - 1)
End If
End If
strCh = strCh & Trim(strTempCh)
Next
intLen = Len(strTempXs)
If intLen > 0 Then
If strCh = "" Or strCh = "负" Then
strCh = strCh & "零"
End If
strCh = strCh & "点"
For i = 1 To intLen
strCh = strCh & Mid(strEng2Ch, Val(Mid(strTempXs, i, 1)) + 1, 1)
Next
End If
ToChinNum = strCh
Exit Function
Err:
ToChinNum = ""
End Function
2006-02-16 12:07
快速回复:初来,发一个函数!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038463 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved