Solved

How to handle strings

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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 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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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