Integer::div(i : Integer) : Integer calculates an integer quotient when you need to divide one integer by another and discard the fractional remainder.
Syntax
number1.div(number2)number1is the dividend: the value being divided.number2is the divisor: the value to divide by.- The result is an
Integer.
Example
To calculate how many complete groups of five are contained in 17, use:
17.div(5)The result is 3. The remainder, 2, is discarded.
For a model value, the following expression divides the first customer's age by 20:
Customer.allInstances->first.Age.div(20)If the age is 45, the result is 2.
Choose the right division operation
Use div when the integer quotient is the required result. Use / when the calculation must retain a fractional result.
| Requirement | Use | Example result |
|---|---|---|
| Count complete groups and discard the remainder | div
|
17.div(5) returns 3
|
| Calculate a fractional quotient | / | 17 / 5 returns a numeric fractional result
|
Quotient and remainder
Use mod when you need the integer remainder rather than the quotient. For the same values, 17 mod 5 returns 2.
For the general operation documentation and additional examples, see div.
