How to integer-divide round negative numbers *down*?

Posted by Conrad Albrecht on Stack Overflow See other posts from Stack Overflow or by Conrad Albrecht
Published on 2010-06-15T00:58:10Z Indexed on 2010/06/15 1:02 UTC
Read the original article Hit count: 314

Filed under:
|

Seems like whenever I divide a negative int by a positive int, I need it to round down (toward -inf), not toward 0. But both C# and C++ round toward 0.

So I guess I need a DivideDownward() method. I can write it in a few lines with a test for negative and so on, but my ideas seem klugey. So I'm wondering if I'm missing something and if you have an "elegant" way to round negative division downward.

© Stack Overflow or respective owner

Related posts about c#

Related posts about c++