Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.net format a string that contains a number

Posted on 2013-06-02
5
Medium Priority
?
337 Views
Last Modified: 2013-06-04
Lets say I have a textbox.text that contains = "10050"

How do I display/format it so it shows "100.50"
0
Comment
Question by:keith1001
  • 3
  • 2
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 39214944
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
 

Author Comment

by:keith1001
ID: 39214968
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
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 2000 total points
ID: 39215105
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
 

Author Comment

by:keith1001
ID: 39220753
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
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39220928
Change ToString("n2") to ToString("F2") will remove the commas.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question