Skip to content

REMAINDER

Returns the remainder of expr1 divided by expr2.

All data types that can be converted to a numeric data type are accepted as arguments.

The REMAINDER function is very similar to the MOD function. The MOD function uses FLOOR in its formula, while REMAINDER uses the ROUND function, which can result in different return values.

Syntax

sql
REMAINDER(expr1, expr2)

Usage Notes

  • If either expr1 = 0 or expr2 = inf and the arguments are numeric, an error is returned.
  • If expr2 != 0, the remainder is calculated as expr1 - (expr2 * N), where N is the integer closest to the quotient **expr1**/**expr2**.
  • N is rounded to the nearest even integer.
  • If expr1 is a DECIMAL and the remainder is 0, the sign of the remainder is taken from the sign of expr1.
  • The remainder value of 0 is returned without a sign.

Examples

sql
select remainder(5.23, 2),
       mod(5.23, 2),
       remainder(5, 2), 
       mod(5, 2);
+--------------------+--------------+-----------------+-----------+
| REMAINDER(5.23, 2) | MOD(5.23, 2) | REMAINDER(5, 2) | MOD(5, 2) |
+--------------------+--------------+-----------------+-----------+
|              -0.77 |         1.23 |               1 |         1 |
+--------------------+--------------+-----------------+-----------+