将CString转换为double(或float)的3种方法
来源:互联网 发布:雷军回应miui广告知乎 编辑:程序博客网 时间:2024/05/13 16:18
CString strFloat;
float flt;
//method1:
flt = (float)atof((char *)(LPTSTR)(LPCTSTR)mstrFloat);
//method2:
flt = (float)atof((char *)m_eps.GetBuffer(strFloat.GetLength()));
strFloat.ReleaseBuffer();
//method3:
//Convert CString to double
static BOOL _AtlSimpleFloatParse(LPCTSTR lpszText, double& d)
{
ATLASSERT(lpszText != NULL);
while (*lpszText == ' '|| *lpszText == '/t')
{
lpszText++;
}
TCHAR chFirst = lpszText[0];
d = _tcstod(lpszText,(LPTSTR*)&lpszText);
if (d == 0.0 && chFirst != '0')
{
return FALSE; //could not convert
}
while (*lpszText == ' '|| *lpszText == '/t')
{
lpszText++;
}
if (*lpszText != '/0')
{
return FALSE; //not terminated properly
}
return TRUE;
}
float flt;
//method1:
flt = (float)atof((char *)(LPTSTR)(LPCTSTR)mstrFloat);
//method2:
flt = (float)atof((char *)m_eps.GetBuffer(strFloat.GetLength()));
strFloat.ReleaseBuffer();
//method3:
//Convert CString to double
static BOOL _AtlSimpleFloatParse(LPCTSTR lpszText, double& d)
{
ATLASSERT(lpszText != NULL);
while (*lpszText == ' '|| *lpszText == '/t')
{
lpszText++;
}
TCHAR chFirst = lpszText[0];
d = _tcstod(lpszText,(LPTSTR*)&lpszText);
if (d == 0.0 && chFirst != '0')
{
return FALSE; //could not convert
}
while (*lpszText == ' '|| *lpszText == '/t')
{
lpszText++;
}
if (*lpszText != '/0')
{
return FALSE; //not terminated properly
}
return TRUE;
}
不过前面两种方法在VS2005下运行结果不正确,在VC6.0开发环境下是可以的。
CString 转为int型
CString str= "1234 ";
int i = atoi((char*)LPCTSTR(str));
参考:http://blog.csdn.net/benny5609/article/details/1810110
- 将CString转换为double(或float)的3种方法
- 将CString转换为double(或float)的3种方法
- 将CString转换为float或int的最简单的方法
- 将CString类型转换为double类型的方法
- 怎样将double强制转换为float
- 如何将CString转换为double VS2005
- 将int转换为CString的方法
- double 转换为CString
- MFC----Cstring 与 int、float、double 数据类型的相互转换
- IOS将Int64转换为Int,Double,Float等类型
- CString 到 float 的转换 小方法
- float--->double 的转换
- CString 转换为 double 类型
- 将float保留一定的精度转换成CString
- int、long转换为float、double的区别
- Swift中string转换float/double的若干方法
- VC 中 Cstring 与 int、float、double、char、string数据类型的相互转换
- VC++中string、Cstring、char*、wchar*、float、int、double之间的转换
- Linux 内存文件系统
- 解决man命令中的乱码问题
- 二维数组作实参的传递方法
- for while 与 until的 差别
- 第九章 异常处理
- 将CString转换为double(或float)的3种方法
- 伪随机数的生成
- Java Collection Framework 源码阅读笔记
- 动态口令(OTP)认证技术概览
- CListCtrl的使用完全指南
- [USACO 1.4] Summary of Section 1.4
- 孙鑫:第十五讲 多线程聊天室程序创建
- python 文件路径操作方法
- 一个小程序员的日记