Solved

String To double conversion...

Posted on 2009-05-15
3
600 Views
Last Modified: 2013-12-17
I am trying to convert a String type of an engineering value to double. i.e. 1.1234E12
Every time I try an sort of conversion whether it be using Convert.ToDouble or Double.Parse I've tried it using System.Globalization.CultureInfo.InvariantCulture. So far nothing.... I keep getting the error 'System.FormatException'

Here is some code.
//configMessage.coeff[] is a Double
//txtCoeff[] is an array of textboxes where the user has input Double precision floating point numbers which can be of various formats. 1234.123463; 12; 1.2345E12;                 
     
configMessage.coeff[i] = Convert.ToDouble(uiControl.GetText(txtCoeff[i]),System.Globalization.CultureInfo.InvariantCulture);

Open in new window

0
Comment
Question by:EAK31640GW
3 Comments
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 250 total points
ID: 24397543
           double num;
            
            if (double.TryParse("1234.123463", out num) == true)
                  Console.WriteLine("Success: {0}", num);
          else
                  Console.WriteLine("Can't convert");
0
 
LVL 27

Assisted Solution

by:nmarun
nmarun earned 250 total points
ID: 24397562
What is the exact value in the textbox when this exception is thrown?

Also, why can't you just do:

configMessage.coeff[i] = Double.Parse(txtCoeff[i].Text);
0
 

Author Comment

by:EAK31640GW
ID: 24397706
Sorry guys! Thanks so much for the posts!!!
Realized that the problems resided in what I was displaying in text boxes in the first place. My format string was incorrect. I had "0.0###+E0#" instead of "0.0###E+0#"
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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