Solved

String To double conversion...

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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