c# - How to integer-divide round negative numbers *down*? -
It seems that whenever I split negative int from positive int, let me down (Side-), not towards 0. But rounds towards both C # and C ++
So I think that I need a dividendown () method. I can write it in some lines with a test for negative and others, but my thoughts seem to be a kulji. That's why I am thinking that I am missing something and if you have the "elegant" way of moving down the negative segmentation.
WARNING: This post produces wrong result for input with one = 1. Please see other answers. -CAM
[c ++]
It's possible that what you are saying to 'clothes', but this is what I came up with I am;)
int divideDown (int a, int b) {int r = a / b; If (R & LT; 0 & R * B! = A) Return R-1; Return r; }
If in the statement, I am R & lt; Put 0 - though I'm not sure if you want to do that. If you (if & lt; 0 & amp; b & gt; 0)
will be consistent with your description, "when Also, I split a negative int from a positive int .
Comments
Post a Comment