Operator Mod (Modulus)
- Source: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOpModulus
- Last revised: 2016-11-20
Finds the remainder from a division operation
Syntax
` declare operator Mod ( byref lhs as integer, byref rhs as integer ) as integer
`
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. Float 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.
Examples
start GeSHi
vb
Print 47 Mod 7
Print 5.6 Mod 2.1
Print 5.1 Mod 2.8end GeSHi
Output:
5
0
2This 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
Back to DocToc