Capital | functions | currency | Convert function Atoc (A as Currency) as String
' Description: This function is suitable for currency conversions under trillions, allowing a value of up to two decimal places
' defines two strings, where Chinese characters and numbers are calculated by one
Dim String1 as String ' is defined as
Dim String2 as String ' is defined as
Dim String3 as String ' the value taken from the original a value
Dim I as Integer ' Loop variable
Dim J as Integer ' a value multiplied by 100 string length
Dim Ch1 as String ' number of Chinese reading method
Dim Ch2 as String ' digit character reading method
Dim Nzero as Integer ' is used to compute the continuous non-zero is a few
String1 = "0 One and three Woolu Qi Ba Nine"
String2 = "thousand thousand hundred million thousand thousand hundred to collect the element angle cent"
' MsgBox CStr (A * 100)
If InStr (1, CSTR (A *), ".") <> 0 Then
Err. Raise 5000, "This function (ATOC ()) can only convert the number within two digits after the decimal point!" "
End If
J = Len (CStr (A * 100))
String2 = Right (String2, J) ' takes out the value of the STRING2 of the corresponding digits
For I = 1 to J
String3 = Mid (A *, I, 1) ' Remove the value of a bit that needs to be converted
If String3 <> "0" Then
CH1 = Mid (String1, Val (String3) + 1, 1)
CH2 = Mid (String2, I, 1)
Nzero = Nzero + 1 ' indicates the standard is Non-zero
Else
If Nzero <> 0 or i = J-9 or i = J-5 or i = J-1 Then
If Right (ATOC, 1) = "0" Then Atoc = Left (Atoc, Len (ATOC)-1)
CH1 = "0"
Else
CH1 = ""
End If
' If the converted value needs to be enlarged, you need to change the value of the expression I below.
If I = J-10 Then
CH2 = "billion"
ElseIf I = J-6 Then
If Nzero <> 0 Then
CH2 = "Million"
' Nzero = 0
End If
ElseIf I = J-2 Then
CH2 = "Yuan"
ElseIf I = J Then
CH2 = "whole"
Else
CH2 = ""
End If