![]() |
| SQL MOD scalar function in DB2 for i SQL |
MOD
The MOD function returns the remainder by dividing the first numeric expression by the second numeric expression.
Syntax
MOD(numeric-expression1, numeric-expression2)
Formula used to calculate the remainder
MOD(x,y) = x - FLOOR(x/y) *y
The parameters can also be character/graphic string data type as it is implicitly cast to numeric value of DECFLOAT(34).
The data type of result is based on the passed parameters data type as follows:
Example
SELECT MOD(4,2), MOD(5,2), MOD(5,2.5), MOD(5,2.3), MOD(7.75,3.2) FROM SYSIBM.SYSDUMMY1
Output:
MOD ( 4 , 2 ) MOD ( 5 , 2 ) MOD ( 5 , 2.5 ) MOD ( 5 , 2.3 ) MOD ( 7.75 , 3.2 )
0 1 .0 .4 1.35 