Operator Mod (Modulus)
 
Finds the remainder from a division operation

Syntax
Usage

result = lhs Mod rhs

Parameters

lhs
The left-hand side dividend expression.
rhs
The right-hand side divisor expression.

Return Value

Returns the remainder of a division operation.

Description

Operator Mod (Modulus) divides two Integer expressions and returns the remainder. Numeric values are converted to Integer by rounding up or down.

Neither of the operands are modified in any way.

This operator can be overloaded for user-defined types.

Example

Print 47 Mod 7
Print 5.6 Mod 2.1
Print 5.1 Mod 2.8

Output:
5
0
2

This is because:
  • 47 divided by 7 gives a remainder of 5
  • 5.6 is rounded to 6 while 2.1 is rounded to 2. This makes the problem 6 MOD 2 which means 6 divided by 2 which gives a remainder of 0
  • 5.1 is rounded to 5 while 2.8 is rounded to 3. This makes the problem 5 MOD 3 which means 5 divided by 3 which gives a remainder of 2

Dialect Differences

  • In the -lang qb dialect, this operator cannot be overloaded.

Differences from QB

  • None

See also