• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

用VB把数字转成中文字符串

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 237次 | 进入软件测试论坛讨论

领测软件测试网

根据数字的读法,写了一个把数字转成中文字符串的程序
参数一为数字
参数二为是不是反回人民币大写
参数三为是不是直接读数字,否则带有十百等单位
参数四为设置小数点后面的位数,默认为4
使用方法是
t=GetChinaNum(20005.000436, , , 7)´返回 “二千零五点零零零四三六”
t=GetChinaNum(2005.436, True, , 7)´返回“贰仟零伍元肆角肆分”
t=GetChinaNum(2005.436, , True, 7)´返加“二零零五点四三六”

下面是程序代码

Function GetChinaNum(otherNum As Double, Optional isRMB As Boolean, Optional numOption As Boolean, Optional dotNum As Integer) As String
    On Error Resume Next
    num = Trim(Str(Int(otherNum)))
   
    If isRMB Then
        numwei = "拾佰仟万拾佰仟亿拾佰仟"
        numshu = "零壹贰叁肆伍陆柒捌玖拾"
    Else
        numwei = "十百千万十百千亿十百千"
        numshu = "零一二三四五六七八九十"
    End If
    If otherNum < 20 And otherNum >= 10 Then
        num = Right(num, 1)
        GetChinaNum = Left(numwei, 1)
    End If
    For i = 1 To Len(num)
        bstr = Mid(num, i, 1)
        If numOption Then
            GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1)
           
        Else
            GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1)
            If bstr = "0" Then
                If Mid(numwei, Len(num) - i, 1) = "万" Or Mid(numwei, Len(num) - i, 1) = "亿" Then
                    Do While Right(GetChinaNum, 1) = "零"
                        GetChinaNum = Left(GetChinaNum, Len(GetChinaNum) - 1)
                    Loop
                    GetChinaNum = GetChinaNum + Mid(numwei, Len(num) - i, 1)
                End If
               
            Else

                GetChinaNum = GetChinaNum + Mid(numwei, Len(num) - i, 1)
            End If
            GetChinaNum = Replace(GetChinaNum, "零零", "零")
        End If
    Next i
    If numOption = False Then
        Do While Right(GetChinaNum, 1) = "零"
            GetChinaNum = Left(GetChinaNum, Len(GetChinaNum) - 1)
        Loop
    End If
    If isRMB Then
        numrmb = "元角分"
        GetChinaNum = GetChinaNum + Mid(numrmb, 1, 1)
        If Val(num) <> otherNum Then
            num = Trim(Str(Round(otherNum - Val(num), 2)))
            For i = 2 To Len(num)
                bstr = Mid(num, i, 1)
                GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1) + Mid(numrmb, i, 1)
            Next i
        Else
            GetChinaNum = GetChinaNum + "整"
        End If
    Else
        If Val(num) <> otherNum Then
            If dotNum = 0 Then dotNum = 4
            num = Trim(CStr(Round(otherNum - Val(num), dotNum)))
            If GetChinaNum = "" Then GetChinaNum = "零"
            GetChinaNum = GetChinaNum + "点"
            For i = 2 To Len(num)
                bstr = Mid(num, i, 1)
                GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1)
            Next i
        End If
    End If
End Function

 

 


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网