Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

RE: String to number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73192] RE: [mg73174] String to number
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Wed, 7 Feb 2007 04:58:04 -0500 (EST)
  • References: <200702060819.DAA24596@smc.vnet.net>

Hi Jose,

> 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?

There is 

	ToExpression[String]

And you can also

	Read[StringToStream[String], Number]

So, given how easy the first option is, why would you use the second?

Try

	b = "12e3";
	ToExpression@b
	Read[StringToStream@b, Number]
	Head[#] & /@ {%, %%}

You can also use

	First@Import[StringToStream["12"], "List"]

Regards,

Dave.


  • Prev by Date: Re: String to number
  • Next by Date: Passing a list as seperate parameters?
  • Previous by thread: Re: String to number
  • Next by thread: Re: String to number