Solved

String To double conversion...

Posted on 2009-05-15
3
598 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

21 Experts available now in Live!

Get 1:1 Help Now