设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1113|回复: 3
打印 上一主题 下一主题

[与其它组件] 上次看到朋友发了一个金额数字转成大写的代码,现在我发一个转成英语大写的代码,用

[复制链接]
跳转到指定楼层
1#
发表于 2005-7-7 21:55:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Function SAY(数量 As Long) As String

  Dim buff As String, done As String

  Static units(10) As String, teens(10) As String

  Static tens(10) As String, denoms(4) As String

  Dim length As Integer, i As Integer, passes As Integer, temp As Integer

      

  units(1) = "ONE ": units(2) = "TWO ": units(3) = "THREE "

  units(4) = "FOUR ": units(5) = "FIVE ": units(6) = "SIX "

  units(7) = "SEVEN ": units(8) = "EIGHT ": units(9) = "NINE "

  

  teens(0) = "TEN ": teens(1) = "ELEVEN ": teens(2) = "TWELVE ": teens(3) = "THIRTEEN "

  teens(4) = "FOURTEEN ": teens(5) = "FIFTEEN ": teens(6) = "SIXTEEN "

  teens(7) = "SEVENTEEN ": teens(8) = "EIGHTEEN ": teens(9) = "NINETEEN "

  

  tens(1) = "TEN": tens(2) = "TWENTY": tens(3) = "THIRTY"

  tens(4) = "FORTY": tens(5) = "FIFTY": tens(6) = "SIXTY"

  tens(7) = "SEVENTY": tens(8) = "EIGHTY": tens(9) = "NINETY"

  

  denoms(1) = "HUNDRED ": denoms(2) = "THOUSAND ": denoms(3) = "MILLION "

  

  buff = Format$(数量, "#########")

  length = Len(buff)

  temp = 0

  

  Do While (length > 0)

    Select Case (length Mod 3)

      Case 0

        If Len(done) > 0 Then

          done = done & denoms(length / 3 + 1)

        End If

        If Mid$(buff, 1, 1) <> "0" Then

          i = Val(Mid$(buff, 1, 1))

          done = done & units(i)

          done = done & denoms(1)

        End If

      Case 1

        If Mid$(buff, 1, 1) <> "0" Then

          i = Val(Mid$(buff, 1, 1))

          If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" And temp = 0 Then

            done = done & "AND "

          End If

          done = done & units(i)

        End If

      Case 2

        If Mid$(buff, 1, 1) = "1" Then

          i = Val(Mid$(buff, 2, 1))

          If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" Then

            done = done & "AND "

          End If

          done = done & teens(i)

          length = length - 1

          buff = Mid$(buff, 2)

        Else

          i = Val(Mid$(buff, 1, 1))

          If Len(done) > 0 And Mid$(buff, 1, 1) <> "0" Then

            done = done & "AND "

          End If

          done = done & tens(i)

          If Mid$(buff, 1, 1) <> "0" And Mid$(buff, 2, 1) <> "0" Then

            done = done & "-"

            temp = 1

          Else

            If Mid$(buff, 1, 1) > "1" And Mid$(buff, 2, 1) = "0" Then

              done = done & " "

            End If

            temp = 0

          End If

        End If

    End Select

    length = length - 1

    buff = Mid$(buff, 2)

  Loop

  If 数量 < 1000000000 Then

    SAY = done

  Else

    SAY = "大于等于拾亿"

  End If

End Function
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-7-7 22:46:00 | 只看该作者
不支持小数点哦
3#
 楼主| 发表于 2005-7-13 17:18:00 | 只看该作者
呵呵,给老外开发票,基本上我们都开整数了。
4#
发表于 2005-8-17 16:44:00 | 只看该作者
海狸给整个:       金额转换成大写人民币和大写英语的吧     这个模块很实用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-3 05:34 , Processed in 0.082092 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表