MathGroup Archive 2007

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

Search the Archive

Re: String to number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73193] Re: String to number
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 7 Feb 2007 05:02:06 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <eq9bnn$mrf$1@smc.vnet.net>

José Carlos Santos wrote:
> Hi all:
> 
> The ToString command generates a string from an expression. Is there a
> similar command which generates numbers from strings? What I mean by
> this is: is there a command (let's call it ToNumber) such that
> 
> ToNumber["12"]
> 
> generates the number 12?
> 
> Best regards,
> 
> Jose Carlos Santos
> 

Hi Jose Carlos,

ToExpression is what you are looking for. (Indeed, ToExpression does the 
reverse of ToString, think of them as inverse functions to each others.)

In[1]:=
ToExpression/@{"12","12/3","12/7","12.34"}

Out[1]=
         12
{12, 4, --, 12.34}
         7

In[2]:=
Head/@%

Out[2]=
{Integer,Integer,Rational,Real}

Regards,
Jean-Marc


  • Prev by Date: Re: String to number
  • Next by Date: RE: String to number
  • Previous by thread: Re: String to number
  • Next by thread: Re: String to number