在VC++6.0中如何把CString类型变量转换为double型?

来源:百度知道 编辑:UC知道 时间:2024/05/07 01:01:22
比如使用编辑框或读取文件时,如何将得到的CString类型变量转换为数字类型,比如double型,我没找到哪个库函数能解决这个问题,如果自己编,感觉小数点不好处理啊。

下面这个例子供参考:
CString strValue("1.234");
double dblValue;
dblValue = atof((LPCTSTR)strValue);
下面这个例子:
char *s; double x;
s = " -2309.12E-15";
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );

运行结果为:
atof test: ASCII string: -2309.12E-15 float: -2.309120e-012
你自己对照着试试吧

应该可以强制转换吧!
double temp=double("123");
你试试,我机上没有C,也好久没用了!

函数 atof:

double aa=99.99;
CString str;
str.Format("%f",aa);
double uu;
uu=atof(str);

结果:uu=99.99