Re: Severe ToExpression Fault?
- To: mathgroup at smc.vnet.net
- Subject: [mg42901] Re: [mg42892] Severe ToExpression Fault?
- From: jmt <jmt at dxdydz.net>
- Date: Sat, 2 Aug 2003 04:12:25 -0400 (EDT)
- References: <200308010526.BAA09833@smc.vnet.net>
- Reply-to: jmt at dxdydz.net
- Sender: owner-wri-mathgroup at wolfram.com
Your expression is evaluated as : -1.97 E -4 where E is the base of natural logarithms. Depending on the format of your string, you can use StringReplace, StringPosition, StringReplacePart to modify your string and have "-1.97 Power[10,-4]" ToExpression will give therefore a correct result. For instance : evaluator[v_String] := Module[{s, e, exp, mant}, s = First@First@StringPosition[v, "E"]; e = StringLength[v]; exp = ToExpression@StringTake[v, {s + 1, e}]; mant = StringTake[v, s - 1]; mant = ToExpression@StringReplace[mant, "," -> "."]; mant Power[10, exp] ] evaluator[-1,97E-04"] -0.000197 On Friday 01 August 2003 07:26, Nils Theune wrote: > Hi folks, > > running Mathematica 4.0.1 I am stuck with the following problem: > > 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. > > I am greatful for any kind of comments on this problem/bug. > > regards > Nils
- References:
- Severe ToExpression Fault?
- From: nils@theune.com (Nils Theune)
- Severe ToExpression Fault?