I imported a table in mathematica using Import["..file","table"] now I cant use the numbers in the table as they are in string formta, can someone please explain how can i convert them from string to number again?
Another approach is to use Read
. This is useful if you have numbers in "E" form scientific notation:
Read[StringToStream[#], Number] &/@{ "1" ,"1.5" , "1E-20" , "2.E10" }
{1, 1.5, 1.5*10^-20, 2.*10^10}
Note ToExpression
gets these wrong:
ToExpression /@ {"1", "1.5", "1.5E-20", "2.E10"}
{1, 1.5, -15.9226, 2. E10}
"1.5E-20" is evaluated as 1.5 * 2.71828-20 in the last case the "E10" is taken as a new symbol..
ToExpression
is however faster if you can use it..
The intrinsic function ToExpression
will convert its argument to an expression; if the argument is the string representation of a number the function will return the number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With