注册 登录
Office中国论坛/Access中国论坛 返回首页

kangking的个人空间 http://www.office-cn.net/?35653 [收藏] [复制] [分享] [RSS]

日志

人民币小写转换为大写的函数

已有 2698 次阅读2009-4-8 15:12 |

闲来无事,写一个人民币小写转换为大写的函数,可以转换13位数据。这个与我之前写的函数,要简单易懂得多。
我虽然对这个函数做过反复的检查,但还是不敢保证其完全正确,有兴趣的爱好者可以进行进一步的测试,使用者也应该对完全此明了。
 
下面是这个函数的代码。
 
'---------------------------------------------------------------------------------------
' 函数    : X2D
' 作者    : kangking
' 日期    : 2009-4-8
' 目的    :小写金额数据转换为大写金额数据
' 参数    :isInvoice 为真时,按发票格式输出大写金额数据,否则按标准格式输出大写金额数据
' 使用方法:?X2D(123.45)     按标准格式输出大写金额数据
'         :或?X2D(123.45,1) 按发票格式输出大写金额数据
'---------------------------------------------------------------------------------------
Public Function X2D(je As Currency, Optional isInvoice As Boolean = False) As String
    Dim l As String
    Const w As String = "兆仟佰拾亿仟佰拾万仟佰拾元角分"
    Const h As String = "零壹贰叁肆伍陆柒捌玖"
    Dim i As Integer
    Dim s As String
    Dim j As Integer
    Dim isN As Boolean
    On Error GoTo errmsg
    j = Len(w)
    isN = False
    l = Trim(Str(Round(je * 100, 0)))
    If Left(l, 1) = "-" Then
        l = Mid(l, 2)
        isN = True
    End If
    For i = Len(l) To 1 Step -1
        s = Mid(l, i, 1) & Mid(w, j, 1) & s
        j = j - 1
    Next
    For i = 0 To 9
        s = Replace(s, i, Mid(h, i + 1, 1))
    Next
    If isInvoice Then
        X2D = s
        Exit Function
    End If
    s = Replace(s, "零仟", "零")
    s = Replace(s, "零佰", "零")
    s = Replace(s, "零拾", "零")
    Do While InStr(1, s, "零零") <> 0
        s = Replace(s, "零零", "零")
    Loop
    s = Replace(s, "零兆", "兆")
    s = Replace(s, "零亿", "亿")
    s = Replace(s, "零万", "万")
    s = Replace(s, "兆亿", "兆")
    s = Replace(s, "亿万", "亿")
    s = Replace(s, "兆万", "兆")
    s = Replace(s, "零元", "元")
    s = Replace(s, "零角零分", "整")
    s = Replace(s, "零分", "")
    s = Replace(s, "零角", "零")
    If isN Then
        X2D = "负" & s
    Else
        X2D = s
    End If
errexit:       Exit Function
errmsg:
    X2D = "溢出!"
    Resume errexit
End Function
 
 

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

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

GMT+8, 2024-11-25 07:53 , Processed in 0.071815 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部