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

Threaded View

  1. #1
    Join Date
    Sep 2016
    Posts
    22

    Question Rounding vs. truncation?

    Hello!

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int a = 9;
        int b = a/2;
        cout << b << endl;
    
        int c = 11;
        int d = c/6;
        cout << d << endl;
    
        return 0;
    }
    I see the result of such division referred to as "rounding down". This must be wrong, is it not? I think it should be pretty clear to anyone who had basic math education that you round up numbers that end on the digit 5 or above, and you round down numbers that end on the digit 4 or below.

    Why is 9/2 said to be "rounded down" to 4? Isn't this called truncation? It's truncated to 4, is it not? And 11/6 is truncated to 1? You don't "round down" 1.8333... do you?
    Last edited by cozySam; October 2nd, 2016 at 03:29 PM.

Tags for this Thread

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