Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how i convert the text in a textbox to a double?

Status
Not open for further replies.

tougo

Technical User
Sep 9, 2002
27
GB
i tried the textbox1->text.todouble(); that i was used in using in c++builder but unfornately it doen't work.
 
This is two questions it seems

1) How to get text from a textbox
2) How to convert text to double

1)
If your textbox control has a Resource ID MY_TEXT
CEdit* pEd = (CEdit*)CDialog::GetDialogItem(MY_TEXT);
CString edStr;
pEd->GetWindowText(edStr);


2)
double dNumber = atof( edStr);

Good luck
-pete
 
So i got the text from the textbox and i converted it to double and manipulated it...
stupid question i know but how i convert double to text to display it in another textbox?
same way?
 
Code:
CString doubleText;
doubleText.Format("%f", dNumber);

CEdit* pEd = (CEdit*)CDialog::GetDialogItem(MY_TEXT);
pEd->SetWindowText(doubleText);

That should convert the double to a string with up to 6 decimal places of precision, and display it on the CEdit resource with the identifier 'MY_TEXT'.

I've always liked Borland's OWL over MFC. It provides a much more robust and useful wrapper over the Windows API, and is a lot more object-oriented and C++ based (rather than C based) than MFC. That's why its so much more code to do relatively simple things like this :p.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top