Home All Groups Group Topic Archive Search About

Parsing double precision numbers

Author
27 Nov 2007 5:34 PM
marathoner
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

Author
27 Nov 2007 5:43 PM
Willy Denoyette [MVP]
Show quote
"marathoner" <rajk2***@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.
Author
27 Nov 2007 5:54 PM
Tom Porterfield
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
Author
27 Nov 2007 6:00 PM
Ignacio Machin ( .NET/ C# MVP )
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.
Show quote
"marathoner" <rajk2***@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
>
Author
27 Nov 2007 7:34 PM
Family Tree Mike
Show quote
"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" <rajk2***@msn.com.invalid> wrote in message
> news:O3Vy2uRMIHA.4308@TK2MSFTNGP05.phx.gbl...

Looks like an old fortran output...

AddThis Social Bookmark Button