Documentation/Calc Functions/MOD
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
Function name:
MOD
Category:
Mathematical
Summary:
Calculates the remainder when one number (the dividend or numerator) is divided by another number (the divisor or denominator). This is known as the modulo operation.
Often the dividend and divisor will be integer values (Euclidean division). However, MOD accepts and processes real numbers with non-zero fractional parts.
Syntax:
MOD(Dividend; Divisor)
Returns:
Returns a real number that is the remainder when one number is divided by another number. The value returned has the same sign as the divisor.
Arguments:
Dividend is a real number, or a reference to a cell containing that number, that is the dividend of the divide operation.
Divisor is a real number, or a reference to a cell containing that number, that is the divisor of the divide operation.
- If either Dividend or Divisor is non-numeric, then MOD reports a #VALUE! error.
- If Divisor is equal to 0, then MOD reports a #DIV/0! error.
Additional details:
- For real x and y (y <>0), MOD implements the following formula:
[math]\displaystyle{ \text{ MOD}(x,y)~=~x-\left(y\times \text{ INT} \left(\frac{x}{y}\right)\right) }[/math]
- The INT function always rounds down (toward -∞) and returns the largest integer less than or equal to a given number. This means that when the dividend and divisor have different signs, MOD may produce results that appear counterintuitive. For example, the formula
=MOD(7; −3)
returns −2; this is because the fraction [math]\displaystyle{ \left(\frac{7}{-3}\right) }[/math] is rounded to −3 by the INT function.
- For more general information about the modulo operation, visit Wikipedia’s Modulo operation page.
Examples:
Formula | Description | Returns |
---|---|---|
=MOD(11; 3) | Return the remainder when 11 is divided by 3. The result has the same (positive) sign as the divisor. | 2 |
=MOD(−11; 3) | Return the remainder when −11 is divided by 3. The result has the same (positive) sign as the divisor. Note the counterintuitive value produced when the dividend and divisor have different signs. | 1 |
=MOD(11; −3) | Return the remainder when 11 is divided by −3. The result has the same (negative) sign as the divisor. Note the counterintuitive value produced when the dividend and divisor have different signs. | −1 |
=MOD(−11; −3) | Return the remainder when −11 is divided by −3. The result has the same (negative) sign as the divisor. | −2 |
=MOD(D1; D2)
where cells D1 and D2 contain the numbers 11.25 and 2.5 respectively. |
Return the remainder when 11.25 is divided by 2.5. The result has the same (positive) sign as the divisor. | 1.25 |
Related LibreOffice functions:
ODF standard:
Related (or similar) Excel functions:
MOD