MathGroup Archive 2011

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

Search the Archive

Re: Is there ToNumber?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119613] Re: Is there ToNumber?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Mon, 13 Jun 2011 05:17:55 -0400 (EDT)

On 6/12/11 at 7:00 PM, hmichel at cox.net (Hans Michel) wrote:

>The request is less trivial than ToExpression["1+1"] since, for
>example, typical number format cannot be read into Mathematica
>without the rather involved trick reported by Ted Sariyski. As an
>example,

>ToExpression["1e3"] ==> e3

The difficulty here is this string is ambiguous. While it is a
common way to write numbers in exponential format, there are
other possible interpretations.

>ch = StringToStream["1e3"];
>timeNum = Read[ch, Number];
>Close[ch];
>timeNum
>==> 1000

>I feel this complication as rather unfortunate, unless I am also
>missing a simpler way to read in numbers.

Simpler is always in the eye of the beholder. An alternative
would be

ToExpression[StringReplace["1e3","e"->" 10^"]]



  • Prev by Date: Re: Is there ToNumber?
  • Next by Date: Matrix/tensor algebra shortcuts?
  • Previous by thread: Aw: mathematica 8 and psfrag
  • Next by thread: Re: Is there ToNumber?