VB.net format a string that contains a number

Lets say I have a textbox.text that contains = "10050"

How do I display/format it so it shows "100.50"
keith1001Asked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
Change ToString("n2") to ToString("F2") will remove the commas.
0
 
Fernando SotoRetiredCommented:
Hi keith1001;

What are the rules for what is in the text box.

Will it always have a numeric values?
Will the last two digits always present and is the decimal part of the numeric value?
0
 
keith1001Author Commented:
Yes it will always contain numeric values.
Yes the last two digits will always be present.

Examples:
"12345"  want to format it to show "123.45"
"7645" want to format it to show "76.45"
0
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi keith1001;

Try this code snippet it should give you what you need

Dim FormattedStr As String = TextBox.Text

If Not String.IsNullOrEmpty(FormattedStr) Then
    FormattedStr = (Decimal.Parse(FormattedStr) / 100).ToString("n2")    
End If

Open in new window

0
 
keith1001Author Commented:
This worked thanks!

What would I change to get rid of coma in something like this:  123453  = 1,234.53 but i would like to dispaly 1234.53
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.