The MOD function returns the rest of a division. This function is very useful for
- a logical test
- the conditional formatting
- data validation
There is also 2 other functions that could be useful in your test. It's the functions QUOTIENT or GCD. We will see how to use them at the end of this article.
Presentation of the MOD function
The result is a whole number, so the rest of the division is obviously 0. And this is what the function MOD returns
The rest of the division, or the modulo, will give this result
Odd or even?
The function MOD is the most convenient way to find if a number is odd or even. The test to write is very simple.
And you can include this test in an IF function to display the result of your test
=IF(MOD(A2,2)=0,"Is even number", "Is odd number")
Other examples of use of the MOD function
You can also used the MOD function is these cases
- Test if the maturity of a contract is reached or not (divisor = 12)
- Quantity in a package (divisor depends of the number of items)
The QUOTIENT function
If you want to return the opposite, the integer part of a division, in that case you have to use the QUOTIENT function.
=QUOTIENT(15,2) =>7In fact, it's exactly like doing the division inside a INT function
The GCD function
The GCD function returns the Greatest Common Divisor 🤨🤔🙄
This function returns the greatest value that divide 2 values. For example, if you have the value 120 and 48, the result is:
=GCD(120,48) => 24
- 24 * 2 = 48
- 24 * 5 = 120