• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Converting string to double

How does one convert a string from a text box and convert it to a double value or integer? Need to get a double number from a text box and assign it to a double argument.

double myVal;

txtBoxName->Text->ToDouble( myVal );

0
Mr_Crabs
Asked:
Mr_Crabs
1 Solution
 
mpf1748Commented:
You can use the Double (Int32) Parse methods or the System.Convert class.
0
 
mactep13Commented:
Try either atof(const char*) or atoi(const char*).

So, you will get something like this:

extern CEdit textBox;
CString strText;
double dVal = 0;
textBox->GetLine(0, strText);
dVal = atof(strText);

Assuming the textBox is a CEdit ctrl declared somewhere in your code.

Hope this helps,

Mactep
0
 
Mr_CrabsAuthor Commented:
double myVal;

myVal = Convert::ToDouble( txtBoxNumber->Text );

Oh, i did not understand all of that so I looked it up at msdn.
It is also alot easier that what mactep13 suggested, whatever that was.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemConvertClassToDoubleTopic.asp
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now