Solved

VB.net format a string that contains a number

Posted on 2013-06-02
5
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 63

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 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 500 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 63

Accepted Solution

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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