docs.intersystems.com
Home  /  Application Development: Core Topics  /  InterSystems SQL Reference  /  SQL Functions  /  MOD


InterSystems SQL Reference
MOD
[Back]  [Next] 
InterSystems: The power behind what matters   
Search:  


A scalar numeric function that returns the modulus (remainder) of a number divided by another.
Synopsis
{fn MOD(dividend,divisor)}
Arguments
dividend A number that is the numerator (dividend) of the division.
divisor A number that is the denominator (divisor) of the division.
MOD returns the NUMERIC data type unless the dividend is data type DOUBLE. If dividend is DOUBLE, MOD returns DOUBLE.
Description
MOD returns the mathematical remainder (modulus) from the dividend by the divisor. It returns a negative or zero result for a division involving a negative divisor. MOD returns NULL if passed a NULL value for either argument.
MOD can only be used as an ODBC scalar function (with the curly brace syntax).
Examples
The following example shows the remainder returned by MOD.
SELECT {fn MOD(5,3)} AS Remainder
returns 2.
The following example shows the remainder returned by MOD with a negative dividend.
SELECT {fn MOD(-5,3)} AS Remainder
returns 1.
The following example shows the remainder returned by MOD with a negative divisor.
SELECT {fn MOD(5,-3)} AS Remainder
returns –1.
See Also
CEILING FLOOR ROUND TRUNCATE