首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

CString与double的互转,该如何解决

2012-09-14 
CString与double的互转原本做CString与float互转的,后来发现精度有问题,改成做CString与double互转,仍然没

CString与double的互转
原本做CString与float互转的,后来发现精度有问题,改成做CString与double互转,仍然没有解决。
兄弟帮忙看一下。

CString strBuffer("3203.45651");
double dValue=atof((LPCTSTR)strBuffer);
//dValue=strtod((LPCTSTR)strBuffer,NULL);
CString strOutput;
strOutput.Format("%lf",dValue);
MessageBox(strOutput);

vc6 MFC编译提示消息框内容是"3203.456543".
发现精度仍然只有8位,
怀疑atof转不了double,就使用strtod,精度同样仍然为8位。

怎么能真正实现double的精度的互相转换呢?


[解决办法]

C/C++ code
#include "StdAfx.h"#include <windows.h>int main(void){    char buf[20] = {0};    CString strBuffer("3203.45651");    sprintf(buf,"%.5lf",atof(strBuffer.GetBuffer(0)) ) ;    cout<< buf <<endl;} 

热点排行