# How do we make a negative integer out of a string of a negative number and vice-versa?

Negative numbers are not taken into consideration by mathematica's built-in functions.

FromDigits["-2"]


Gives me this message:

FromDigits::nlst: The expression -2 is not a list of digits or a string of valid digits. >>


Also:

In[2]:=IntegerString[-2]


Gives:

Out[2]:="2"


I was wondering if someone had some code to do this. I'm currently making a small program in mma which will help me enter matrices manually because it's cumbersome to type in every single ,{} for each row/column. Here's what I had in mind:

enterMat[x_, y_] := MatrixForm[ReleaseHold[
Table[Hold[FromDigits[InputString[]]], {x}, {y}]]]


Gives me a series of popups in which I enter the value 1 by 1 pressing enter after each to pass to the next value. It's faster and more comfortable to do it this way since I can use the numpad instead. My only problem is that it just doesn't work with negative numbers!

If you have a solution or you know a great way to enter/scan/manipulate matrices, I would like to hear it. Thanks!

-
I think ToString and ToExpression are what you are looking for. As for your matrix-input, you might look at this question –  Albert Retey Feb 6 at 15:24
... and of course this questions and the corresponding answers might also be of interest... –  Albert Retey Feb 6 at 15:27
For conversion of strings themselves please see How do you convert a string containing a number in C scientific notation to a Mathematica number? There are a number of methods you might select between depending on the application, such as StringToDouble, Read, ReadList, ImportString, and ParseTable. If after reviewing the tutorial above you still have an application for these functions please describe it and I shall make a recommendation.