»

Function MOD (Modulo)

The MOD function returns the rest of a division. This function is very useful for

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

If you divide 12 by 3, the result is 4.

The result is a whole number, so the rest of the division is obviously 0. And this is what the function MOD returns

=MOD(12,3) =>0

Now if we divide 12 by 5, the result of the division is not an integer.

The rest of the division, or the modulo, will give this result

=MOD(12,5) =>2

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.

Even number

=MOD(A2;2)=0

Odd number

=MOD(A2;2)<>0

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) =>7

In fact, it's exactly like doing the division inside a INT function

=INT(15/2) =>7

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

Because

  • 24 * 2 = 48
  • 24 * 5 = 120

Permanent link to this article: https://www.excel-exercise.com/function-mod-modulo/


Leave a Reply

Your email address will not be published. Required fields are marked *