MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: ReadList, mix Words & Numbers?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30944] RE: [mg30934] Re: ReadList, mix Words & Numbers?
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
  • Date: Fri, 28 Sep 2001 03:54:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Robert Love [mailto:rlove at neosoft.com]
To: mathgroup at smc.vnet.net
> Sent: Thursday, September 27, 2001 8:17 AM
> Subject: [mg30944] [mg30934] Re: ReadList, mix Words & Numbers?
> 
> 
> Mariusz Jankowski  wrote :
> 
> >Robert, here is the solution. I used the following approach 
> - read the data
> >as a list of records and use string operations to locate the 
> numbers and
> >extract.
> 
> I didn't catch the error in this method until I tried it for 
> myself.  Every number generated from a string representing a 
> number in "Exponent" form fails to convert correctly.  For 
> example, a string of "  -0.7623174679E-008"  becomes -10.0722
> 
> Is there a way I can  correctly convert strings of the form I 
> have to numbers?
> 
> 

Robert,

ToExpression["  -0.7623174679E-008"]is essentially the same as when you type
to Mathematica:

In[12]:= -0.7623174679E-008 //Trace
Out[12]=
{{-0.762317 \[ExponentialE], -2.07219}, -2.07219 - 8, -10.0722}

The Trace shows that the Input is understood as
   -0.7623174679 * E -8

which gives the undesired result.

You can convert Fortran- or C-like numbers using the import functions, e.g.

In[21]:= ImportString["-0.7623174679E-008", "List"]
Out[21]= {-7.623174679*^-9}

It might be easier, however, to use Import on your file.

-- Hartmut



  • Prev by Date: Strange syntax errors when writing functions ?
  • Next by Date: RE: checking for a particular value in a matrix
  • Previous by thread: Re: Re: ReadList, mix Words & Numbers?
  • Next by thread: Use of Mathematica under UNIx