Thread: Visual C++ round / rint ????

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    24

    Visual C++ round / rint ????

    Hi,

    how can I round double in Visual C++ ?

    In Dev-Cpp works:

    #include <math.h>
    int myInt;
    myInt = int (round(45.65445));

    , but in Visual C++:

    #include <cmath>
    int myInt;
    myInt = int (round(45.65445));

    gives -> error C2065: 'round' : undeclared identifier

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    round was introduced by C99, which MSVC doesn't implement. However, you can achieve the same result (for positive numbers):
    Code:
    myInt = int (45.65445 + 0.5);
    For something that will work with negatives, try this post.
    Last edited by anonytmouse; 12-09-2005 at 10:55 PM.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    AFAIK, round() is not a standard function. floor() and ceil(), which are in the standard C library and declared in <math.h>, can probably be used in combination to achieve what you want. In C++, and alternative would be based on std::floor() and std::ceil() in <cmath>.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    24
    okidoki

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM