All Products
Search
Document Center

REMAINDER

Last Updated: Jun 18, 2021

The REMAINDER function returns the remainder of x that is divided by y.

Notice

Difference between the REMAINDER function and the MOD function:

When the REMAINDER (x,y) and MOD (x,y) functions perform operations, the same formula result=x-y*(x/y) is used. The difference is that the processing methods are different when x/y is calculated. ROUND(x/y) is used in the REMAINDER (x,y) function, whereas FLOOR(x/y) is used in the MOD (x,y) function. Assume that the decimal part of the value of the x/y parameter in ROUND(x/y) is 0.5 in the REMAINDER function. If the integer part of the value of x/y is an even number, the value is rounded down to the nearest integer. If the integer part of the value of x/y is an odd number, the value is rounded up the nearest integer. For example, ROUND(1.5) is equal to 2, ROUND(2.5) is equal to 2, ROUND(3.5) is equal to 4, and ROUND(4.5) is equal to 4.

Syntax

REMAINDER (x, y)

Parameter

ParameterDescription

x,y

x and y are the expressions of the numeric types: NUMBER, FLOAT, BINARY_FLOAT, and BINARY_DOUBLE.

Return type

The return type is the same as the data type of the parameter that has higher numeric precedence.

Examples

This example shows the results of using the MOD and REMAINDER functions to calculate the remainder of 1.5/1. Take note of the difference between the two functions.

Execute the following statement:

SELECT MOD(1.5,1), REMAINDER(1.5,1) FROM DUAL;

The following query result is returned:

+------------+------------------+
| MOD(1.5,1) | REMAINDER(1.5,1) |
+------------+------------------+
|      0.5   |      -0.5        |
+------------+------------------+