Converting float (not double) to char *

I've tried to convert with _ecvt,_gcvt and it great up to
0.0001 for example but when I've tried to convert 0.00001
it all mess up.
So my question is which function can convert float
or how can I convert float to double



  • Can you give a better example of what you are trying to accomplish?

    float nNumA = 2002.0702;

    double nNumB = static_cast(nNumA);

  • Here the function if any error can be found

    Try to Change a =0.01

    It's Not the same and it very importent to me to receive
    the same value every time

    thanks again

    char Buf[20];

    char * Convert(const float &Num)

    return Buf;

    void main()

    float a=0.001;

    for (int i=1;i<10;++i)
    cout <<Convert(a)<<endl;


  • I have not used _gcvt(). What is the reason for returning a char * if you want to convert a float value to a double value?

  • I've tried to create String from float but any function
    (that I've found) that convert to string is using double
    and not float.
    Thats why I need to convert float to double.
    If look at the _gcvt function or if you check the convertion
    after its occure you'll see the number has changed.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion