[转] 各种数据类型转换
来源:互联网 发布:怎么找到我的淘宝店铺 编辑:程序博客网 时间:2024/04/30 10:56
1、CString转char*
(LPTSTR)(LPCTSTR)str,即为char*类型”
char* sz = str.GetBuffer(str.GetLength());
char* pBuf = str.GetBuffer(0);
2、CString 转int
ansi环境,使用atoi
unicode环境,使用_ttoi
CString str = "";
long m_count = atoi(str.GetBuffer(str.GetLength());
int i;
i=atoi(str); //如果str="123",那么现在i的值就是 123;
3、float 整数,小数部分分开
只计算3位小数的话,加上0.0005即可。令建议你使用函数modf。例:
include <math.h>
void main()
{
float a,a_f,a_i;
int m,n;
a=1.234;
a_f = modf(a, &a_i);
m=a_i;
n=(a_f+0.0005)*1000;
printf("m=%d/nn=%d/n",m,n);
}
4
CString转float的方法:
float i = (float)atof(str.GetBuffer(str.GetLength()));
如果转换成double,就不用float强制转换了。
float转成 CString 是不是 str.format("%.1f",i) //保留1位小数
5、double 转float
double a=2.22;
CString str;
str.Format("%.2lf",a);
- [转] 各种数据类型转换
- 转: symbian c++ 各种数据类型转换
- 各种数据类型转换
- 各种数据类型的转换
- 各种数据类型转换
- Qt 各种数据类型转换
- Qt 各种数据类型转换
- 各种数据类型的转换
- C#各种数据类型转换
- 各种数据类型转换
- 各种数据类型转换
- VC++各种数据类型转换
- symbian c++ 各种数据类型转换
- Qt 各种数据类型的转换
- Qt各种数据类型的转换
- 各种数据类型的相互转换
- 各种数据类型的相互转换
- delphi 各种数据类型转换总结
- linux 网上淘的经验_默认启动级别_更改Linux与Windows的默认启动
- [转]unresolved external symbol _main解决办法
- linux使用经验
- 网上淘的mysql技巧
- 我喜欢这种默契!
- [转] 各种数据类型转换
- 2009年11月29日(mysql_3)
- 2009年11月29日(mysql_3)
- [转]Visual Assist X设置
- 清华大学今天的讲座归来
- 带信号量的生产者消费者问题
- 第一篇日志
- 【转】使用gdb
- Go