• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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