I am running following query in oracle 11g using Sql Developer.
SELECT remainder(25,10),remainder(35,10) FROM dual;
Output
REMAINDER(25,10) REMAINDER(35,10)
---------------------- ----------------------
5 -5
I can use MOD() to get the desired result, but my question is why it is returning +5 for one and -5 for other?
According to the documentation, REMAINDER(m, n)
is defined as
m - (n * X) where X is the integer nearest m / n
Apparently, Oracle applies "round to even" when the result of the division is halfway between two numbers:
For REMAINDER(25, 10)
, you get
25 / 10 = 2.5 --> nearest integer is 2 (round to even)
25 - (10 * 2) = 5
For REMAINDER(35, 10)
, you get
35 / 10 = 3.5 --> nearest integer is 4 (round to even)
35 - (10 * 4) = -5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With