C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Comma Separated Amount


Posted Date: 10 Dec 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: Lalit Vasant PatilMember Level: Gold    
Rating: 1 out of 5Points: 15



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(-_-)



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Comma Separated Amount  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ASP Script to Sort XML
Previous Resource: Round up amount
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use