超级简单问题:
如何把浮点数转换成字符串。
有没有和 itoa 类似的函数?

解决方案 »

  1.   

    _fcvt
    Converts a floating-point number to a string.char *_fcvt( double value, int count, int *dec, int *sign );
    这个函数可以。
      

  2.   

    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
      

  3.   

    我喜欢用cstring 的format,嘿嘿
      

  4.   

    STL way:#include <sstream>
    #include <string>
    #include <iostream>
    using namespace std;
    void main()
    {
      stringstream ss;
      ss<<3.14;
      cout<<ss.str()<<endl;
    }
      

  5.   

    sprintf或者CString 的format都可以
    CString sStr;
    sStr.Format("%f",3.14f)