MathGroup Archive 2003

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

Search the Archive

Re: Severe ToExpression Fault?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42906] Re: Severe ToExpression Fault?
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Sat, 2 Aug 2003 04:12:30 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/1/03 at 1:26 AM, nils at theune.com (Nils Theune) wrote:

> Input:
> Print["-1,97E-04"];
> Print[StringReplace["-1,97E-04", {"," -> "."}]];
> Print[ToExpression[StringReplace["-1,97E-04", {"," -> "."}]]];

> Output:
> -1,97E-04
> -1.97E-04
> -9.35502

> Can somebody explain this to me? Why does the ToExpression Function
> not make the decimal -1.97E-04 out of the String "-1.97E-04". What in
> the hell is going wrong (-9.35502->"Where does this number come
> from?") and what can be done to circumvent the ToExpression function.

E is predefined to have the value 2.71828.... So the number 1.97E-04 is interpreted as -1.97 times 2.718.... minus 4 which equals -9.35502. The point is ToExpression does not understand E-04 to be 10^-4.

There are at least two ways this can be addressed. First you could use StringReplace to replace E with " 10^" and then use ToExpression. Alternatively, you could use StringToStream to convert the string to a stream and use ReadList to convert that to a number. ReadList does understand E-04 to be 10^-4


  • Prev by Date: RE: Severe ToExpression Fault?
  • Next by Date: Re: Severe ToExpression Fault?
  • Previous by thread: RE: Severe ToExpression Fault?
  • Next by thread: RE: Severe ToExpression Fault?