Digital to English (currency) capital

Source: Internet
Author: User
Tags exit integer trim
Capital | currency ' function module: Digital to English (currency) capital
' Public Function numbertostring (number as Double) as String
' Call form: Debug.Print numbertostring (1234.32)
' Description: Maximum support 12 digits, accurate two digits after the decimal point
' Procedure: Yang Xin Light (volitation)
Dim Strno as String
Dim Unit (8) as String
Dim Strtens (9) as String

Public Function numbertostring (number as Double) as String
Dim Str As String, Beforepoint as String, Afterpoint as String, tmpstr as String
Dim Point as Integer
Dim Nbit as Integer
Dim curstring as String
Call Init
'//Start processing
STR = CStr (Round (number, 2))
' STR = number
If InStr (1, Str, ".") = 0 Then
Beforepoint = Str
Afterpoint = ""
Else
Beforepoint = Left (str, INSTR (1, str, ".")-1)
Afterpoint = Right (str, Len (str)-INSTR (1, str, "."))
End If

If Len (beforepoint) > Then
numbertostring = "Too big."
Exit Function
End If
STR = ""
Do While Len (Beforepoint) > 0
Nnumlen = Len (beforepoint)
If Nnumlen Mod 3 = 0 Then
Curstring = Left (Beforepoint, 3)
Beforepoint = Right (Beforepoint, nNumLen-3)
Else
Curstring = Left (Beforepoint, (Nnumlen Mod 3))
Beforepoint = Right (Beforepoint, Nnumlen-(Nnumlen Mod 3))
End If
Nbit = Len (beforepoint)/3
Tmpstr = decodehundred (curstring)
If (Beforepoint = String (Len (beforepoint), "0") Or nbit = 0) and Len (curstring) = 3 Then
If CInt (Left (curstring, 1)) <> 0 and CInt (right (curstring, 2)) <> 0 Then
Tmpstr = Left (Tmpstr, InStr (1, TMPSTR, Unit (4)) + Len (unit (4)) & Unit (8) & "" & Right (Tmpstr, Len (TMPSTR)- (INSTR (1, TMPSTR, Unit (4)) + Len (unit (4)))
Else ' If CInt (left (curstring, 1)) <> 0 and CInt (right (curstring, 2)) = 0 Then
TMPSTR = Unit (8) & "" & Tmpstr
End If
End If

If nbit = 0 Then
str = Trim (str & "" & Tmpstr)
Else
str = Trim (str & "" & Tmpstr & "& Unit (Nbit))
End If
If left (str, 3) = Unit (8) Then Str = Trim (Right (str, Len (str)-3))
If beforepoint = String (Len (beforepoint), "0") Then Exit do
' Debug.Print Str
Loop
Beforepoint = Str

If Len (Afterpoint) > 0 Then
Afterpoint = Unit (6) & "" & Decodehundred (Afterpoint) & "& Unit (7)
Else
Afterpoint = Unit (5)
End If
numbertostring = Beforepoint & "" & Afterpoint
End Function
Private Function decodehundred (hundredstring As String) as String
Dim tmp as Integer
If Len (hundredstring) > 0 and Len (hundredstring) <= 3 Then
Select case Len (hundredstring)
Case 1
TMP = CINT (hundredstring)
IF tmp <> 0 Then decodehundred = Strno (TMP)
Case 2
TMP = CINT (hundredstring)
IF tmp <> 0 Then
IF (tmp <) Then
decodehundred = Strno (TMP)
Else
If CInt (Right (hundredstring, 1)) = 0 Then
decodehundred = Strtens (Int (TMP/10))
Else
decodehundred = Strtens (Int (TMP/10)) & "-" & Strno (CInt (Right (hundredstring, 1))
End If
End If
End If
Case 3
If CInt (Left (hundredstring, 1)) <> 0 Then
decodehundred = Strno (CInt (Left (hundredstring, 1)) & "" & Unit (4) & "& Decodehundred (Right (hundredstr ING, 2))
Else
decodehundred = decodehundred (Right (hundredstring, 2))
End If
Case Else
End Select
End If

End Function
Private Sub Init ()
If Strno (1) <> "one" Then
Strno (1) = "One"
Strno (2) = "Two"
Strno (3) = "Three"
Strno (4) = "Four"
Strno (5) = "Five"
Strno (6) = "Six"
Strno (7) = "Seven"
Strno (8) = "Eight"
Strno (9) = "Nine"
Strno (Ten) = "Ten"
Strno (one) = "Eleven"
Strno (a) = "Twelve"
Strno (+) = "Thirteen"
Strno = "Fourteen"
Strno = "Fifteen"
Strno = "Sixteen"
Strno (km) = "Seventeen"
Strno (km) = "Eighteen"
Strno = "Nineteen"

Strtens (1) = "Ten"
Strtens (2) = "Twenty"
Strtens (3) = "Thirty"
Strtens (4) = "Forty"
Strtens (5) = "Fifty"
Strtens (6) = "Sixty"
Strtens (7) = "Seventy"
Strtens (8) = "Eighty"
Strtens (9) = "Ninety"

Unit (1) = "thousand" ' first three-bit
Unit (2) = "million" ' second three-bit
Unit (3) = "billion" ' third three-bit
Unit (4) = "Hundred"
Unit (5) = "Only"
Unit (6) = "point"
Unit (7) = "Cent" is not currency, this value is empty
Unit (8) = "and"
End If
End Sub





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.