Solved

How to handle strings

Posted on 2014-01-08
3
174 Views
Last Modified: 2014-01-08
I have a string that returns for example a "1" and another case where it returned a "1.2"

In the first case I handle the case base that if  mystring does not contains  (".") then I add in a ".00" to it making that "1" a "1.00"   in the second case how can I return a "1.20" if mystring is "1.2" keep in mind that I still could get strings such as "1.34" and I dont want them to turn into "1.3400" or "1.340"

Thanks
0
Comment
Question by:cmdolcet
3 Comments
 
LVL 1

Expert Comment

by:BullfrogSoftware
ID: 39765209
'Your string is 18934.1879

Dim doubleNumber As Double
doubleNumber = Double.TryParse("18934.1879")

String formattedNumber = doubleNumber.ToString("F", CultureInfo.InvariantCulture)

'formattedNumber is now 18934.19
0
 
LVL 7

Accepted Solution

by:
Steve earned 300 total points
ID: 39765210
By using a Len(gth) statement on your result you would know how many characters you need to add.
0
 
LVL 40
ID: 39765428
Do not add zeros. Let the Format method handle the formatting for you:

CDbl(yourString).ToString("###.00###")

Add as many # as needed to cover the biggest value you expect on the integer and on the decimal portion of the number.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

13 Experts available now in Live!

Get 1:1 Help Now