Solved

VB.net format a string that contains a number

Posted on 2013-06-02
5
327 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 62

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 62

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 62

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now