Visual C++ round / rint ????

This is a discussion on Visual C++ round / rint ???? within the C++ Programming forums, part of the General Programming Boards category; Hi, how can I round double in Visual C++ ? In Dev-Cpp works: #include <math.h> int myInt; myInt = int ...

  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 09:55 PM.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,307
    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, 04: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, 09:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21