阿拉伯数字转大写数字的代码实例-chenhang
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


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

发表时间:2021/1/19 22:13:41 评论(0) 浏览(4352)  评论 | 加入收藏 | 复制
   
摘 要:阿拉伯数字转大写数字。
正 文:

      学了点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群(群号:198465573)
 
 相关文章
大写金额转换为数字  【VictorDuane  2007/10/9】
将金额数字转换汉字大写   【yuab  2004/11/10】
套打大写金额  【andymark  2010/4/9】
【access源码示例】金额小写转中文大写数字\转中文大写金额的示...  【红尘如烟  2011/7/6】
excel中,怎样才能把数字转换成中文大写金额格式  【赵文斌  2013/3/20】
中文大写金额转阿拉伯数字  【轻风  2016/11/4】
数值金额转英文大写函数  【宏鹏  2019/10/5】
常见问答
技术分类
相关资源
文章搜索
关于作者

chenhang

文章分类

文章存档

友情链接