Solved

VB.net format a string that contains a number

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

18 Experts available now in Live!

Get 1:1 Help Now