Howdy, Stranger!

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

Categories

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

thanks

Comments

  • 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);
    -----

    Kuphryn
  • 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

    #include
    char Buf[20];

    char * Convert(const float &Num)
    {

    _gcvt(Num,8,Buf);
    return Buf;
    }

    void main()
    {


    float a=0.001;

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


    }





  • 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?

    Kuphryn
  • 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,496 ✭✭

    _________ || http://forcoder.org || 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.