设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1831|回复: 5
打印 上一主题 下一主题

[其它] [分享]人民币小写转换大写

[复制链接]
跳转到指定楼层
1#
发表于 2007-3-17 01:23:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
       这几天在这里学到不少东西,所以也想给大家分享点。


[此贴子已经被作者于2007-3-16 17:28:53编辑过]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2007-3-17 01:29:00 | 只看该作者
给你些建议:

1.可以写成函数的形式

2.代码太整齐了,相反不太好认,最好有合理的缩进。

3.支持转换的数字太小,上亿就会出现错误。

4.对于一个程序而言,错误处理是必要的。

5.前缀不一定都需要,可以设置成参数,让用户自己定义。



[此贴子已经被作者于2007-3-16 17:42:03编辑过]

3#
发表于 2007-3-17 02:38:00 | 只看该作者
给你修改成函数了:

'***********************************代码开始***********************************
Public Function CMoneyToCnCap(Money As Double) As String
On Error GoTo CMoneyToCnCap_Err
Dim strTemp As String
Dim intDigit As Integer
Dim strCnTempDigit As String
Dim strCnTemp As String
Dim intLen As Integer
Dim i As Integer
Dim strCnTempNum As String
Dim strDeno As String

    If Money > (1 * 10 ^ 13) Or Money < (-1 * 10 ^ 13) Then
        MsgBox "输入的数值的整数位数不能超过 13 位。", vbOKOnly
        Exit Function
    End If
   
    strCnTempNum = "零壹贰叁肆伍陆柒捌玖拾"
    strDeno = "分角元拾佰仟万拾佰仟亿拾佰仟万拾佰"
    strTemp = CStr(Abs(Round(Money, 2) * 100))
    intLen = Len(strTemp)
  
    If Money = 0 Then
        CMoneyToCnCap = "零元整"
        Exit Function
    End If
   
    For i = intLen To 1 Step -1
        intDigit = Mid(strTemp, intLen - i + 1, 1)
        strCnTempDigit = Mid(strCnTempNum, intDigit + 1, 1)
        strCnTemp = strCnTemp & strCnTempDigit & Mid(strDeno, i, 1)
    Next
   
    strCnTemp = Replace(strCnTemp, "零拾", "零")
    strCnTemp = Replace(strCnTemp, "零佰", "零")
    strCnTemp = Replace(strCnTemp, "零仟", "零")
    strCnTemp = Replace(strCnTemp, "零零零", "零")
    strCnTemp = Replace(strCnTemp, "零零", "零")
    strCnTemp = Replace(strCnTemp, "零角零分", "整")
    strCnTemp = Replace(strCnTemp, "零分", "整")
    strCnTemp = Replace(strCnTemp, "零角", "零")
    strCnTemp = Replace(strCnTemp, "零亿零万", "亿")
    strCnTemp = Replace(strCnTemp, "零亿零万零元", "亿元")
    strCnTemp = Replace(strCnTemp, "亿零万零元", "亿元")
    strCnTemp = Replace(strCnTemp, "零亿零万", "亿")
    strCnTemp = Replace(strCnTemp, "零万零元", "万元")
    strCnTemp = Replace(strCnTemp, "万零元", "万元")
    strCnTemp = Replace(strCnTemp, "零亿", "亿")
    strCnTemp = Replace(strCnTemp, "零万", "万")
    strCnTemp = Replace(strCnTemp, "零元", "元")
    strCnTemp = Replace(strCnTemp, "零零", "零")

    If Money > 0 Then
        CMoneyToCnCap = strCnTemp
    Else
        CMoneyToCnCap = "负" & strCnTemp
    End If
     
CMoneyToCnCap_Exit:
    Exit Function
   
CMoneyToCnCap_Err:
    MsgBox Err.Description
    Resume CMoneyToCnCap_Exit
   
End Function
'***********************************代码结束***********************************
4#
 楼主| 发表于 2007-3-17 03:03:00 | 只看该作者
    多谢版主指点!
5#
发表于 2007-3-17 18:58:00 | 只看该作者
学习斑竹致电!
6#
发表于 2007-3-18 03:16:00 | 只看该作者
论坛上有不少这样的函数,但都有点问题,大家可以试试,如果数字比较大,中间的零比较多,那就出问题了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-17 01:52 , Processed in 0.093857 second(s), 31 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表