算作散分吧 超级简单问题:如何把浮点数转换成字符串。有没有和 itoa 类似的函数? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 _fcvtConverts a floating-point number to a string.char *_fcvt( double value, int count, int *dec, int *sign );这个函数可以。 Example/* FCVT.C: This program converts the constant * 3.1415926535 to a string and sets the pointer * *buffer to point to that string. */#include <stdlib.h>#include <stdio.h>void main( void ){ int decimal, sign; char *buffer; double source = 3.1415926535; buffer = _fcvt( source, 7, &decimal, &sign ); printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n", source, buffer, decimal, sign );}Outputsource: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0 我喜欢用cstring 的format,嘿嘿 STL way:#include <sstream>#include <string>#include <iostream>using namespace std;void main(){ stringstream ss; ss<<3.14; cout<<ss.str()<<endl;} sprintf或者CString 的format都可以CString sStr;sStr.Format("%f",3.14f) 请问关于头文件 关于颜色取舍的算法 文档指针问题探究? _bstr_t 变量赋值不完整怎么办? 请高手指教!!一定加分!!! 怎么样改变LISTCTRL里面的字体和高度??急 关于ATL Com 实现全局钩子的问题(在线) WSAAsyncSelect如何使用? CImageList 问题 (在线等待) 请问浏览器控件怎么使用post方法? 请教TCHAR.H 和 WINNT.H 头文件的区别,以及_UNICODE 和 UNICODE 宏的区别 wndclass.cbClsExtra和wndclass.cbWndExtra有什么区别 关于ADO的应用程序配置问题
Converts a floating-point number to a string.char *_fcvt( double value, int count, int *dec, int *sign );
这个函数可以。
* 3.1415926535 to a string and sets the pointer
* *buffer to point to that string.
*/#include <stdlib.h>
#include <stdio.h>void main( void )
{
int decimal, sign;
char *buffer;
double source = 3.1415926535; buffer = _fcvt( source, 7, &decimal, &sign );
printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n",
source, buffer, decimal, sign );
}
Outputsource: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0
#include <string>
#include <iostream>
using namespace std;
void main()
{
stringstream ss;
ss<<3.14;
cout<<ss.str()<<endl;
}
CString sStr;
sStr.Format("%f",3.14f)