设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

數字轉英文(金額轉換)源碼

[复制链接]
跳转到指定楼层
1#
发表于 2002-10-12 01:49:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Public Function x(num As String) As String
Select Case num
       Case "0": x = ""
       Case "1": x = "one"
       Case "2": x = "two"
       Case "3": x = "three"
       Case "4": x = "four"
       Case "5": x = "five"
       Case "6": x = "six"
       Case "7": x = "seven"
       Case "8": x = "eight"
       Case "9": x = "nine"
End Select
End Function
Public Function xxa(num As String) As String
Select Case num
       Case "2": xxa = "twenty"
       Case "3": xxa = "thirty"
       Case "4": xxa = "forty"
       Case "5": xxa = "fifty"
       Case "6": xxa = "sixty"
       Case "7": xxa = "seventy"
       Case "8": xxa = "eighty"
       Case "9": xxa = "ninety"
End Select
End Function
Public Function xxb(num As String) As String
Select Case num
       Case "10": xxb = "ten"
       Case "11": xxb = "eleven"
       Case "12": xxb = "twelve"
       Case "13": xxb = "thirteen"
       Case "14": xxb = "fourteen"
       Case "15": xxb = "fivteen"
       Case "16": xxb = "sixteen"
       Case "17": xxb = "seventeen"
       Case "18": xxb = "eighteen"
       Case "19": xxb = "nineteen"
End Select
End Function
Public Function xx_2(num As String) As String
If CInt(num) < 10 Then
  xx_2 = x(num)
  Else
    If CInt(num) < 20 Then
      xx_2 = xxb(num)
      Else
       xx_2 = xxa(Left(num, 1)) + " " + x(Right(num, 1))
    End If
End If
End Function
Public Function xx_3(num As String) As String
If IsNull(num) Then
Exit Function
End If

If CInt(num) < 999 And CInt(num) >= 100 Then
  xx_3 = x(Left(num, 1)) + " hundred " + xx_2(Right(num, 2))
Else
  If CInt(num) < 100 Then
    xx_3 = xx_2(num)
  End If
End If
End Function
Public Function xx_m(num As Currency) As String

Dim str_dollars As String
Dim str_cents As String
Dim str_dollars_len As Integer
Dim str_result As String
str_cents = Right(Format(num, ".00"), 2)
str_dollars = Left(Format(num, ".00"), Len(Format(num, ".00")) - 3)
str_dollars_len = Len(str_dollars)

If str_dollars_len <= 3 Then
  xx_m = xx_3(str_dollars) + " dollars and " + xx_3(str_cents) + " cents"
Else
  If (str_dollars_len Mod 3) <> 0 Then
     If str_dollars_len < 6 And str_dollars_len <> 6 Then
      xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " dollars and " + xx_3(str_cents) + " cents"
      Else
      If str_dollars_len < 9 And str_dollars_len <> 9 Then
        xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " million " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
        Else
        If str_dollars_len < 12 And str_dollars <> 12 Then
          xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " billion " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " million " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3, 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3 + 3 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
          Else
          If str_dollars_len < 15 And str_dollars <> 15 Then
             xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " trillion " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " billion " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3, 3)) + " million " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3 + 3, 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3 + 3 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents "
          End If
        End If
       End If
     End If
  End If
End If
'-------------------------------------------------
If (str_dollars_len > 3) And ((str_dollars_len Mod 3) = 0) Then
     If str_dollars_len = 6 Then
      xx_m = xx_3(Left(str_dollars, 3)) + " thousand " + xx_3(Mid(str_dollars, 1 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
      Else
      If str_dollars_len = 9 Then
        xx_m = xx_3(Left(
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-15 00:59 , Processed in 0.083316 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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