Why is the remainder (35.10) is -5 when the remainder (25.10) is 5 in the oracle?

I am running the following query in oracle 11g using Sql Developer.

SELECT remainder(25,10),remainder(35,10) FROM dual; 

Exit

 REMAINDER(25,10) REMAINDER(35,10) ---------------------- ---------------------- 5 -5 

I can use MOD () to get the desired result, but my question is why it returns +5 for one and -5 for others?

+7
sql oracle rounding oracle11g
source share
1 answer

According to the documentation, REMAINDER(m, n) is defined as

m - (n * X), ​​where X is an integer, the nearest m / n

Oracle seems to apply the β€œround to even” when the division result 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 
+7
source share

All Articles