Purpose
The REMAINDER function returns the remainder of x divided by y.
Notice
Both the REMAINDER (x,y) and MOD (x,y) functions use the formula result=x-y*(x/y). The difference lies in the method used to calculate x/y. In the REMAINDER (x,y) function, ROUND(x/y) is used, while in the MOD (x,y) function, FLOOR(x/y) is used.
In the REMAINDER function, if the fractional part of ROUND(x/y) is exactly 0.5, the function rounds to the nearest even integer. For example, ROUND(1.5)=2, ROUND(2.5)=2, ROUND(3.5)=4, and ROUND(4.5)=4.
Syntax
REMAINDER (x, y)
Parameters
Parameter |
Description |
|---|---|
| x | The dividend. It is a numeric expression of type NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE. |
| y | The divisor. It is a numeric expression of type NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE. Notice The parameter y cannot be 0. |
Return type
The return type is the data type of the numeric parameter with the higher precedence.
Examples
Use the MOD and REMAINDER functions to return the remainder of 1.5 divided by 1.
obclient> SELECT MOD(1.5,1),REMAINDER(1.5,1) FROM DUAL;
+------------+------------------+
| MOD(1.5,1) | REMAINDER(1.5,1) |
+------------+------------------+
| .5 | -.5 |
+------------+------------------+
1 row in set
