DMOD, FMOD, and IMOD: Calculating the Remainder From a Division
Available Languages: reporting, Maintain
The MOD functions calculate the remainder from a division. Each function returns the remainder in a different format.
The functions use the following formula.
remainder = dividend - INT(dividend/divisor) * divisor
- DMOD returns the remainder as a decimal number.
- FMOD returns the remainder as a floating-point number.
- IMOD returns the remainder as an integer.
For information on the INT function, see INT: Finding the Greatest Integer.
Calculate the Remainder From a Division
function(dividend, divisor, output)
Is one of the following:
DMOD
returns the remainder
as a decimal number.
FMOD
returns
the remainder as a floating-point number.
IMOD
returns
the remainder as an integer.
Numeric
Is the number being divided.
Numeric
Is the number dividing the dividend.
Numeric
Is the result whose format is determined by the function used. Can be the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
If the divisor is zero (0), the dividend is returned.
Calculating the Remainder From a Division
IMOD divides ACCTNUMBER by 1000 and stores the remainder in a column with the format I3L.
IMOD(ACCTNUMBER, 1000, 'I3L')
For 122850108, the result is 108.
For 163800144, the result is 144.
IMOD divides ACCTNUMBER by 1000 and returns the remainder to LAST3_ACCT:
TABLE FILE EMPLOYEE PRINT ACCTNUMBER AND COMPUTE LAST3_ACCT/I3L = IMOD(ACCTNUMBER, 1000, LAST3_ACCT); BY LAST_NAME BY FIRST_NAME WHERE (ACCTNUMBER NE 000000000) AND (DEPARTMENT EQ 'MIS'); END
The output is:
LAST_NAME FIRST_NAME ACCTNUMBER LAST3_ACCT --------- ---------- ---------- ---------- BLACKWOOD ROSEMARIE 122850108 108 CROSS BARBARA 163800144 144 GREENSPAN MARY 150150302 302 JONES DIANE 040950036 036 MCCOY JOHN 109200096 096 SMITH MARY 027300024 024