用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧Delphi

货币大写转换函数的更新!

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:17:30
Function AtoC(a As Currency) As String
    ''说明:本函数适合于万亿以下的货币转换,允许A的值是最多两位小数
    ''定义两个字符串,此处汉字与数字均按一位计算
    Dim String1 As String   ''如下定义
    Dim String2 As String   ''如下定义
    Dim String3 As String   ''从原A值中取出的值
    Dim I As Integer        ''循环变量
    Dim J As Integer        ''A的值乘以100的字符串长度
    Dim Ch1 As String       ''数字的汉语读法
    Dim Ch2 As String       ''数字位的汉字读法
    Dim nZero As Integer    ''用来计算连续的非零数是几个
    
    String1 = "零壹贰叁肆伍陆柒捌玖"
    String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
    ''MsgBox CStr(a * 100)
    If InStr(1, CStr(a * 100), ".") <> 0 Then
        err.Raise 5000, , "此函数( AtoC() )只能转换小数点后有两位以内的数!"
    End If
    
    J = Len(CStr(a * 100))
    String2 = Right(String2, J)         ''取出对应位数的STRING2的值
    
    For I = 1 To J
        String3 = Mid(a * 100, I, 1)    ''取出需转换的某一位的值
        If String3 <> "0" Then
            Ch1 = Mid(String1, Val(String3) + 1, 1)
            Ch2 = Mid(String2, I, 1)
            nZero = nZero + 1           ''表示本位不为零
        Else
            
            If nZero <> 0 Or I = J - 9 Or I = J - 5 Or I = J - 1 Then
                If Right(AtoC, 1) = "零" Then AtoC = Left(AtoC, Len(AtoC) - 1)
                Ch1 = "零"
            Else
                Ch1 = ""
            End If
                        
            ''如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
            If I = J - 10 Then
                Ch2 = "亿"
            ElseIf I = J - 6 Then
                If nZero <> 0 Then
                    Ch2 = "万"
''                    nZero = 0
                End If
            ElseIf I = J - 2 Then
                Ch2 = "元"
             ElseIf I = J Then
                Ch2 = "整"
            Else
                Ch2 = ""
            End If
            nZero = 0
        End If
        
        AtoC = AtoC & Ch1 & Ch2
    Next I
    
    ''最后将多余的零去掉
        AtoC = Replace(AtoC, "零元", "元")
        AtoC = Replace(AtoC, "零万", "万")
        AtoC = Replace(AtoC, "零亿", "亿")
        AtoC = Replace(AtoC, "零整", "整")
    
    
End Function

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:2,921.87500 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号