Solved

How to handle strings

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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