|
數字轉英文(金額轉換)源碼
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(str_dollars, 3)) + " million " + xx_3(Mid(str_dollars, 1 + 3, 3)) + " thousand " + xx_3(Mid(str_dollars, 1 + 3 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
Else
If str_dollars_len = 12 Then
xx_m = xx_3(Left(str_dollars, 3)) + " billion " + xx_3(Mid(str_dollars, 1 + 3, 3)) + " million " + xx_3(Mid(str_dollars, 1 + 3 + 3, 3)) + " thousand " + xx_3(Mid(str |
|