?
Solved

String To double conversion...

Posted on 2009-05-15
3
Medium Priority
?
605 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
[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 16

Accepted Solution

by:
ToddBeaulieu earned 1000 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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