Thread: Using Doubles

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    15

    Using Doubles

    Iv created a calculator but it is only working for integers below is a function for adding 2 numbers
    Code:
    num2 = atoi(buffer);
    SetWindowText(hwndEdit,itoa(num1 + num2,buffer,10));
    num1 was read in earlier and num2 has been converted to an int from buffer which has just been read in.

    but i would like to use doubles any suggestions please

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Code:
    double atof(const char*); //std
    char* _gcvt(double, int, char*); // non-std
    http://msdn.microsoft.com/

    Since you are already using non-standard itoa I figured you might look into _gcvt if it or one of it's brothers are available.
    Last edited by MrWizard; 03-21-2005 at 03:09 PM.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    15
    So my code would be like this???
    Code:
    num2 = atof(buffer);                           //convert the string to a double
    SetWindowText(hwndEdit,ftoa(num1 + num2,buffer,10));        //convert the double back to a String

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    15
    i tried using that code and i had no luck any suggestions?

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Quote Originally Posted by jay kay
    So my code would be like this???
    Code:
    num2 = atof(buffer);                           //convert the string to a double
    SetWindowText(hwndEdit,ftoa(num1 + num2,buffer,10));        //convert the double back to a String
    Where did ftoa come from? I mentioned _gcvt not ftoa. Mind the order of the parameters too.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Outputting a list of squared Doubles
    By dnguyen1022 in forum C++ Programming
    Replies: 13
    Last Post: 01-19-2009, 01:24 PM
  2. problem w/ doubles in friend's program
    By mkylman in forum C Programming
    Replies: 16
    Last Post: 11-22-2008, 10:45 AM
  3. parse doubles from socket read?
    By willy in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:32 AM
  4. sscanf with doubles
    By ufsargas in forum C Programming
    Replies: 1
    Last Post: 06-28-2006, 03:05 PM
  5. Passing array of doubles to ATL COM dll
    By wakeup in forum C++ Programming
    Replies: 3
    Last Post: 04-11-2006, 02:53 AM