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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString

Status
Not open for further replies.

DigitalOx

Programmer
Sep 29, 1998
41
0
0
US
How do I convert a CString data to a double?<br>
I need to perform calculations on string input.<br>
//This doesn't work - how to do it?<br>
CString string;<br>
double thedouble;<br>
thedouble = (double) string;<br>
<br>
DigitalOx<br>

 
You can cast a CString to LPCSTR, then use atof to convert it to a double. Just change your third line to:<br>
<br>
thedouble = atof((LPCSTR)string);<br>

 
It is a good idea to validate the string for proper format (i.e. valid numeric and '.' characters) before you pass it to the atof function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top