Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6915 > unrolled thread

Re: how to get string in sci. notation to a number?

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-12-03 10:09 +0000
Last post2011-12-03 10:09 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: how to get string in sci. notation to a number? Bill Rowe <readnews@sbcglobal.net> - 2011-12-03 10:09 +0000

#6915 — Re: how to get string in sci. notation to a number?

FromBill Rowe <readnews@sbcglobal.net>
Date2011-12-03 10:09 +0000
SubjectRe: how to get string in sci. notation to a number?
Message-ID<jbcsgs$bvv$1@smc.vnet.net>
On 12/2/11 at 7:21 AM, ralph.dratman@gmail.com (Ralph Dratman) wrote:

>But that is so easy with pattern replacement. More experienced
>people will surely manage it without using StringReplace, but I get
>flummoxed on which kind of Hold to use.

>In[652]:= flpnumsStr =
>ToString[{{"4.998865e+000", "9.564453e-006"}, {"5.630450e+000",
>"9.194384e-006"}, {"6.113276e+000", "8.134170e-006"}}]

>Out[652]= "{{4.998865e+000, 9.564453e-006}, {5.630450e+000,
>9.194384e-006}, {6.113276e+000, 8.134170e-006}}"

>In[653]:= ToExpression[StringReplace[flpnumsStr, "e" -> "*10^"]]

>Out[653]= {{4.99887, 9.56445*10^-6}, {5.63045,
>9.19438*10^-6}, {6.11328, 8.13417*10^-6}}

I assume you really didn't manually enter the strings in the
form of Mathematica lists. So, let me start by putting the
output of your ToString above into something that likely
resembles the original data, i.e.,

In[5]:= p =
  StringReplace[
   StringTake[
    ToString[{{"4.998865e+000", "9.564453e-006"}, {"5.630450e+000",
       "9.194384e-006"}, {"6.113276e+000",
       "8.134170e-006"}}], {3, -3}], "}, {" -> "\n"]

Out[5]= 4.998865e+000, 9.564453e-006
5.630450e+000, 9.194384e-006
6.113276e+000, 8.134170e-006

Now, these can be read in as numbers simply by using ImportString

In[6]:= ImportString[p, "CSV"]

Out[6]= {{4.998865, 9.564453*^-6}, {5.63045, 9.194384*^-6},
    {6.113276, 8.13417*^-6}}

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web