Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

阿拉伯数字转大写数字的代码实例

时 间:2021-01-19 22:13:41
作 者:强联财务室   ID:77261  城市:北京
摘 要:阿拉伯数字转大写数字。
正 文:

      学了点vba基础,动手练习敲代码,完成了阿拉伯数字向大写数字的功能,分享源代码如下:

----------------------------------------------------------------

Public Function Numtostr(Getnum) As String
    Dim Num, z, x, c
    Dim n, m, i, Point As Integer
    Dim Str As String
    Num = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖")
    z = Array("", "拾", "佰", "仟")
    x = Array("", "万", "亿", "万亿")
    c = Array("", "角", "分")
    If InStr(Getnum, ".") = 0 Then
        n = Len(Getnum)
        For i = 1 To n
            m = Mid(Getnum, i, 1)
            Str = Str + Num(m)
            
            If m > 0 Then Str = Str + z((n - i) Mod 4)
            
            Str = Replace(Str, Num(0) & Num(0), Num(0))
            If ((n - i) Mod 4) = 0 And Right(Str, 1) = Num(0) Then Str = Left(Str, Len(Str) - 1)
            If ((n - i) Mod 4) = 0 Then Str = Str + x(Int((n - i) / 4))
        Next i
        Str = Str & "元整"
    Else
        Point = InStr(Getnum, ".") - 1
        Getnum = Replace(Getnum, ".", "")
        
         For i = 1 To Point
         
            m = Mid(Getnum, i, 1)
            Str = Str + Num(m)
            
            If m > 0 Then Str = Str + z((Point - i) Mod 4)
            
            Str = Replace(Str, Num(0) & Num(0), Num(0))
            If ((Point - i) Mod 4) = 0 And Right(Str, 1) = Num(0) Then Str = Left(Str, Len(Str) - 1)
            If ((Point - i) Mod 4) = 0 Then Str = Str + x(Int((Point - i) / 4))
        Next i
        Str = Str & "元"
        For i = 1 To Len(Getnum) - Point
            Str = Str + Num(Mid(Getnum, i + Point, 1))
            If Num(Mid(Getnum, i + Point, 1)) = Num(0) Then
                Str = Left(Str, Len(Str) - 1)
            Else
                Str = Str + c(i)
            End If
        Next i
    End If
    Numtostr = Str
    
End Function


可以在立即窗口中输入?Numtostr(1000100)看下结果。



Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助