MathGroup Archive 2011

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123360] Re: how to get string in sci. notation to a number?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 3 Dec 2011 04:13:39 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 12/2/11 at 7:21 AM, ralph.dratman at 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}}




  • Prev by Date: Transparent textures from images
  • Next by Date: How to get elements satisfying specific condition from a list
  • Previous by thread: Re: how to get string in sci. notation to a number?
  • Next by thread: Re: Mixing multiple manipulate objects