Hi,
Below code is used to convert amount into comma separated amount
e.g i/p 123456789 then o/p 123,456,789 OR i/p 123456789.98 then o/p 123,456,789.98
Note: this code will not excute if user input more than 12 digit amount.
Now,Follow below steps: 1.Drag one textbox on web form & set Textbox Id to "TextBox1" and MaxLength to 12. 2.Drag on button on web form. 3.Paste below CommaSeparatedAmt()into code-behind file.
Private Sub CommaSeparatedAmt() Dim strAmt As String = "" Dim s As String = "" Dim s1 As String = "" Dim s2 As String = ""
Dim strArr As String() = Split(TextBox1.Text, ".")
Select Case strArr(0).Length Case Is < 4 strAmt = strArr(0) Case 4 s = strArr(0).ToString.Substring(0, 1) s1 = strArr(0).ToString.Substring(1, 3) strAmt = s + "," + s1 Case 5 s = strArr(0).ToString.Substring(0, 2) s1 = strArr(0).ToString.Substring(2, 3) strAmt = s + "," + s1 Case 6 s = strArr(0).ToString.Substring(0, 1) s1 = strArr(0).ToString.Substring(1, 2) s2 = strArr(0).ToString.Substring(3, 3) strAmt = s + "," + s1 + "," + s2 Case 7 s = strArr(0).ToString.Substring(0, 1) s1 = strArr(0).ToString.Substring(1, 3) s2 = strArr(0).ToString.Substring(4, 3) strAmt = s + "," + s1 + "," + s2 Case 8 s = strArr(0).ToString.Substring(0, 2) s1 = strArr(0).ToString.Substring(2, 3) s2 = strArr(0).ToString.Substring(5, 3) strAmt = s + "," + s1 + "," + s2 Case 9
s = strArr(0).ToString.Substring(0, 3) s1 = strArr(0).ToString.Substring(3, 3) s2 = strArr(0).ToString.Substring(6, 3) strAmt = s + "," + s1 + "," + s2
Case Else strAmt = strArr(0) End Select
If strArr.Length = 1 Then Response.Write(strAmt & ".00") Else Response.Write(strAmt & "." & strArr(1)) End If End Sub
4.Now call CommaSeparatedAmt () into Button1 Click Event.
e.g
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Call CommaSeparatedAmt() End Sub
-Hope you will follow all steps before using this code.
-Happy Codding(-_-)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|