Convert numbers to uppercase letters

Source: Internet
Author: User
'The process is written by the western people. I would like to recommend it to you.
 
 
*'****************
Function sayusd (byval mynumber)
Dim dollars, cents, temp
Dim decimalplace, count
Redim place (9) as string
Application. Volatile true
Place (2) = "Thousand"
Place (3) = "million"
Place (4) = "billion"
Place (5) = "trillion" 'string representation of amount
Mynumber = trim (STR (mynumber) 'position of decimal place 0 if none
Decimalplace = instr (mynumber ,".")
'Convert cents and set mynumber to dollar amount
If decimalplace> 0 then
Cents = gettens (left (mid (mynumber, decimalplace + 1) & "00", 2 ))
Mynumber = trim (left (mynumber, decimalplace-1 ))
End if
Count = 1
Do While mynumber <> ""
Temp = gethundreds (right (mynumber, 3 ))
If temp <> "" Then dollars = temp & PLACE (count) & dollars
If Len (mynumber)> 3 then
Mynumber = left (mynumber, Len (mynumber)-3)
Else
Mynumber = ""
End if
Count = count + 1
Loop
Select case dollars
Case ""
Dollars = "No dollars"
Case "one"
Dollars = "one dollar"
Case else
Dollars = dollars & "Dollars"
End select
Select case cents
Case ""
Cents = ""
Case "one"
Cents = "and one cent"
Case else
Cents = "and" & cents & "cents"
End select
Sayusd = dollars & cents
End Function
'*************************************** ****
'Converts a number from 100-999 into text *
'*************************************** ****
Function gethundreds (byval mynumber)
Dim result as string
If Val (mynumber) = 0 Then exit function
Mynumber = right ("000" & mynumber, 3) 'convert the hundreds place
If mid (mynumber, 1, 1) <> "0" then
Result = getdigit (mid (mynumber, 1, 1) & "Hundred"
End if
'Convert the TENs and ones place
If mid (mynumber, 2, 1) <> "0" then
Result = Result & gettens (mid (mynumber, 2 ))
Else
Result = Result & getdigit (mid (mynumber, 3 ))
End if
Gethundreds = Result
End Function
'*************************************** ******
'Converts a number from 10 to 99 into text .*
'*************************************** ******
Function gettens (tenstext)
Dim result as string
Result = "" 'null out the temporary function value
If Val (left (tenstext, 1) = 1 then' if value between 10-19
Select case Val (tenstext)
Case 10: result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case else
End select
Else 'if value between 20-99
Select case Val (left (tenstext, 1 ))
Case 2: Result = "Twenty"
Case 3: Result = "Thirty"
Case 4: Result = "Forty"
Case 5: Result = "ty"
Case 6: Result = "Sixty"
Case 7: Result = "Seventy"
Case 8: Result = "Eighty"
Case 9: Result = "Ninety"
Case else
End select
Result = Result & getdigit _
(Right (tenstext, 1) 'retrieve ones place
End if
Gettens = Result
End Function
'*************************************** ****
'Converts a number from 1 to 9 into text .*
'*************************************** ****
Function getdigit (DIGIT)
Select case Val (DIGIT)
Case 1: getdigit = "one"
Case 2: getdigit = "two"
Case 3: getdigit = "three"
Case 4: getdigit = "four"
Case 5: getdigit = "five"
Case 6: getdigit = "six"
Case 7: getdigit = "seven"
Case 8: getdigit = "Eight"
Case 9: getdigit = "Nine"
Case else: getdigit = ""
End select
End Function

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.