Amount conversion algorithm

Source: Internet
Author: User
Tags split
Conversion | amount | algorithm | convert Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click

Dim Str as String
str = Me.TextBox1.Text.Trim
Dim Isfs as Boolean
If left (str, 1) = "-" Then
ISFS = True
str = str. Remove (0, 1)
Else
ISFS = False
End If
Dim Strpoint as String
Dim Point () as String
Dim J as Int16
Dim JJ () as String
Dim JJJ as String
JJJ = ""
If Str. IndexOf (".") <>-1 Then
Point = Split (str, ".",-1, CompareMethod.Text)
str = point (0)
Strpoint = Point (1)
ReDim JJ (Strpoint. LENGTH-1)
For j = 0 to Strpoint. Length-1
JJ (j) = Left (Strpoint, 1)
Strpoint = Right (Strpoint, Strpoint. LENGTH-1)
JJJ = JJJ + CONVERT (JJ (j))
Next
End If
Dim Strcode as String
Strcode = ""
While Strcode. Length <= str. Length
Strcode = strcode & "2345" & "2346"
End While
Strcode = "1" & Strcode
Strcode = Left (Strcode, str. Length)
Dim I as Int16
Dim A () as String
Dim Strcode1 as String
Dim Countstr as Int16
Dim Strcode2 as String
Countstr = Strcode. Length
ReDim A (strcode. LENGTH-1)
For i = 0 to Countstr-1
A (i) = Right (Strcode, 1)
Strcode = Left (Strcode, Strcode. LENGTH-1)
Strcode1 = Strcode1 & A (i)
Strcode2 = Strcode2 & "," & Mid (str, i + 1, 1) & Mid (strcode1, i + 1, 1)
Next
Strcode2 = Right (Strcode2, Strcode2. LENGTH-1)
Dim newstr () as String
Newstr = Split (Strcode2, ",",-1, CompareMethod.Text)
Dim II as Int16
Dim Laststr as String
Dim Strcode3 as String
Dim Leftstr as String
Dim Rightstr as String
For II = 0 to Newstr. Length-1
Strcode3 = NEWSTR (ii)
Leftstr = Left (strcode3, 1)
Rightstr = Right (strcode3, 1)
Rightstr = Replace (Rightstr, Rightstr, Convert2 (RIGHTSTR))
Leftstr = Replace (Leftstr, LEFTSTR, convert (LEFTSTR))
If leftstr = "0" and (rightstr = "Pick" or rightstr = "Bai" or rightstr = "thousand") Then
Rightstr = ""
End If
If leftstr = "0" and (rightstr = "million" Or Rightstr = "billion") Then
Leftstr = ""
End If
Strcode3 = leftstr & Rightstr
Laststr = laststr & Strcode3
Next
While Laststr. IndexOf ("Bai 0") <>-1
Laststr = Laststr. Replace ("0", "million")
End While
While Laststr. IndexOf ("Thousand 0") <>-1
Laststr = Laststr. Replace ("0", "million")
End While
While Laststr. IndexOf ("0") <>-1
Laststr = Laststr. Replace ("0", "0")
End While
While Laststr. IndexOf ("0") <>-1
Laststr = Laststr. Replace ("0", "billion")
End While
While Laststr. IndexOf ("00") <>-1
Laststr = Laststr. Replace ("00", "0")
End While
While right (LASTSTR, 1) = "0"
Laststr = Left (Laststr, Laststr. LENGTH-1)
End While
If Isfs = True Then
LASTSTR = "negative" & Laststr
End If
If JJJ = "" Then
TD2. InnerHtml = Laststr
Else
If laststr = "" Then
TD2. InnerHtml = "0 points" & JJJ
Else
TD2. InnerHtml = laststr & "dot" & JJJ
End If
End If

End Sub

Function convert (ByVal num as String)
Select Case num
Case "1"
convert = "one"



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.