Solved

How to handle strings

Posted on 2014-01-08
3
175 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

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

Suggested Solutions

Title # Comments Views Activity
Crystal Report for VS2013 17 77
Showdialog 8 29
More on Time zones in vb 2010 12 37
Vb.net dynamic formulas in runtime 11 61
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

911 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

24 Experts available now in Live!

Get 1:1 Help Now