Currency capitalization conversion function Update!

Source: Internet
Author: User
Tags integer
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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.