CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Round in C++ ??

  1. #1
    Join Date
    Mar 2003
    Location
    Lisbon
    Posts
    165

    Question Round in C++ ??

    Hello, I'm a rookie in C++. Is there any function that rounds a number (ex. 5.67-->6)

    Thanks

  2. #2
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Don't feel like a rookie, I don't know the C++ way either (or maybe I'm a rookie myself )

    The "C" way is to use something like the following:
    Code:
    #include <math.h>
    
    long round(double val)
    {
      return static_cast<long>(floor(val + 0.5));
    }
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  3. #3
    Join Date
    Mar 2003
    Location
    Lisbon
    Posts
    165
    Originally posted by Yves M
    Don't feel like a rookie, I don't know the C++ way either (or maybe I'm a rookie myself )

    The "C" way is to use something like the following:
    Code:
    #include <math.h>
    
    long round(double val)
    {
      return static_cast<long>(floor(val + 0.5));
    }
    Thanks for the tip!! See ya!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured