MathGroup Archive 2007

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

Search the Archive

Re: String to number


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