?
Solved

How to handle strings

Posted on 2014-01-08
3
Medium Priority
?
183 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 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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