怎么转换小数到字符串 就是想把小数转成字符串用SetDlgItemText();来显示小数可能是4.355,也可能是45.478这样的,意思是说整数部分可以很多位,但小数就只有三位用fcvt不行,返回值不对这里有参考:http://www.cppblog.com/charles/archive/2006/06/25/8458.html先谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString::Format. sprintf..... double num = 123.1234234CString strText;strText.Format("%.3f", num); float num = 23.122char strText[256];sprintf(strText,"%.3f", num); CString::Format和sprintf都可以达到效果。。关键是%f的处理http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_printf.2c_.wprintf.asp #include<iostream>#include<string>#include<sstream>using namespace std;string ftos(float f) // 将float转换成string{ stringstream s; s << f; return s.str();} #include<iostream>#include<string>#include<sstream>using namespace std;template<class T>string dtos(T const f) // 将float转换成string{ stringstream s; s << f; return s.str();}这是模板函数,可以转换整数和浮点数的。 大牛,救救我吧~~~~~~~~~~~mfc http连接 请问各位大侠: 在vc2005上,process viewer在哪里? (我想看多线程下的线程信息) 急救:variant数据传输,不能正确接受 如何实现屏幕截取 论坛里没有出现过的问题,还请高人指点一二(在新建文档时在视图中加入提示问题) Exe文件运行时怎么对它进行修改? 用过Open Inventor SDK的请指导 我的EditView中文件内容怎么保存不下来? 请教一个关于MSDN的问题: 不用MFC的VC编程? listctrl和richedit 的问题 使用SHFileOperation的疑问?
CString strText;
strText.Format("%.3f", num);
char strText[256];
sprintf(strText,"%.3f", num);
和sprintf都可以达到效果。。关键是%f的处理http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_printf.2c_.wprintf.asp
#include<string>
#include<sstream>
using namespace std;
string ftos(float f) // 将float转换成string
{
stringstream s;
s << f;
return s.str();
}
#include<string>
#include<sstream>
using namespace std;template<class T>
string dtos(T const f) // 将float转换成string
{
stringstream s;
s << f;
return s.str();
}
这是模板函数,可以转换整数和浮点数的。