|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Parsing double precision numbersAfter 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
Show quote
"marathoner" <rajk2***@msn.com.invalid> wrote in message -0.417597000000000D+06 is invalid (the D should be an e or E to be valid), 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 > where did you get this from? Willy. marathoner wrote:
> After reading the string representation of a double precision What is the D in your number? If that is supposed to mean exponent, the > 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. correct representation is e (or E). -- Tom Porterfield 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")); 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 >
Show quote
"Ignacio Machin ( .NET/ C# MVP )" wrote: Looks like an old fortran output...> 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...
Other interesting topics
|
|||||||||||||||||||||||