Howdy, Stranger!

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


Converting float (not double) to char *

plotoploto Member Posts: 68
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



  • kuphrynkuphryn Member Posts: 266
    Can you give a better example of what you are trying to accomplish?

    float nNumA = 2002.0702;

    double nNumB = static_cast(nNumA);

  • plotoploto Member Posts: 68
    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;


  • kuphrynkuphryn Member Posts: 266
    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?

  • plotoploto Member Posts: 68
    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.

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _________ || || free ebooks and video tutorials about | PHP, Visual Basic, Assembly, PL/SQL, Delphi, C, Objective-C, R, MATLAB, Visual Basic .NET, Ruby, JavaScript, C#, Perl, Java, Scratch, Python, Swift, Go, C++ Logo, Kotlin, Rust, Transact-SQL, Julia, COBOL, Apex, FoxPro, Awk, Fortran, Clojure, Erlang, Scala, D, ABAP, Lisp, Prolog, F#, Scheme, LabVIEW, Alice, Ada, VBScript, Dart, Crystal, Bash, Hack, Lua, SAS, ML | ________

Sign In or Register to comment.