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;}