TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Parsing double precision numbers

C#(C Sharp)


Reply
 
Thread Tools Display Modes
Old 27-11-2007, 10:31 PM   #1
marathoner
Guest
 
Posts: n/a
Parsing double precision numbers



After reading the string representation of a double precision
number, -0.417597000000000D+06, from a text file, I am unable to convert it
to a double precision number. Here is the code I am using:

string[] result = block.Split(charSeparators,
StringSplitOptions.RemoveEmptyEntries);
double temp1 = double.Parse(result[0]);

After the last statement, I get an unhandled exception.

Marathoner


  Reply With Quote
Old 27-11-2007, 10:31 PM   #2
Willy Denoyette [MVP]
Guest
 
Posts: n/a
Re: Parsing double precision numbers

"marathoner" <rajk2000@msn.com.invalid> wrote in message
news:O3Vy2uRMIHA.4308@TK2MSFTNGP05.phx.gbl...
>
>
> After reading the string representation of a double precision
> number, -0.417597000000000D+06, from a text file, I am unable to convert
> it to a double precision number. Here is the code I am using:
>
> string[] result = block.Split(charSeparators,
> StringSplitOptions.RemoveEmptyEntries);
> double temp1 = double.Parse(result[0]);
>
> After the last statement, I get an unhandled exception.
>
> Marathoner
>



-0.417597000000000D+06 is invalid (the D should be an e or E to be valid),
where did you get this from?

Willy.

  Reply With Quote
Old 27-11-2007, 10:31 PM   #3
Tom Porterfield
Guest
 
Posts: n/a
Re: Parsing double precision numbers

marathoner wrote:
> After reading the string representation of a double precision
> number, -0.417597000000000D+06, from a text file, I am unable to convert it
> to a double precision number. Here is the code I am using:
>
> string[] result = block.Split(charSeparators,
> StringSplitOptions.RemoveEmptyEntries);
> double temp1 = double.Parse(result[0]);
>
> After the last statement, I get an unhandled exception.


What is the D in your number? If that is supposed to mean exponent, the
correct representation is e (or E).
--
Tom Porterfield
  Reply With Quote
Old 27-11-2007, 11:31 PM   #4
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
Re: Parsing double precision numbers

Hi,


The D is incorrect, it should be an E.

Where are you reading these numbers from?

Anyway, use String.Replace
double temp1 = double.Parse(result[0].Replace("D","E"));
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"marathoner" <rajk2000@msn.com.invalid> wrote in message
news:O3Vy2uRMIHA.4308@TK2MSFTNGP05.phx.gbl...
>
>
> After reading the string representation of a double precision
> number, -0.417597000000000D+06, from a text file, I am unable to convert
> it to a double precision number. Here is the code I am using:
>
> string[] result = block.Split(charSeparators,
> StringSplitOptions.RemoveEmptyEntries);
> double temp1 = double.Parse(result[0]);
>
> After the last statement, I get an unhandled exception.
>
> Marathoner
>



  Reply With Quote
Old 28-11-2007, 12:31 AM   #5
Family Tree Mike
Guest
 
Posts: n/a
Re: Parsing double precision numbers



"Ignacio Machin ( .NET/ C# MVP )" wrote:

> Hi,
>
>
> The D is incorrect, it should be an E.
>
> Where are you reading these numbers from?
>
> Anyway, use String.Replace
> double temp1 = double.Parse(result[0].Replace("D","E"));
> --
> Ignacio Machin
> http://www.laceupsolutions.com
> Mobile & warehouse Solutions.
> "marathoner" <rajk2000@msn.com.invalid> wrote in message
> news:O3Vy2uRMIHA.4308@TK2MSFTNGP05.phx.gbl...


Looks like an old fortran output...

  Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 01:54 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional