Click to See Complete Forum and Search --> : casting into a short


rowgram
November 21st, 2005, 07:36 PM
I've got a variable x that is a short.
I receive a char array y, for example "-12.000".
I want to take the value of this array & make that the value of x.
Any suggestions - I've tried different things & nothing works - I must be doing something wrong.

For example, I've tried :

x = (short) Convert:ToInt16(y);

x = (short) (y);

There has to be many ways to do this - I just need one :)

Can anybody help me ?

ak

darwen
November 22nd, 2005, 12:09 AM
Try this:


short MyClass::GetShort(char aCharacters __gc [])
{
String *sString = new String(aCharacters);
return Int16::Parse(sString);
}


The thing is "-12.000" is a floating point number : you might be better off getting a double instead : just as easy, just call


return Double::Parse(sString);


in the above example instead (and change the function declaration of course).

Darwen.

rowgram
November 22nd, 2005, 06:35 PM
the Double::Parse function does the trick -- thanks for the help

ak