Number.IntegerDivide
Divides one number by another and keeps only the whole number of times it fits.
Number.IntegerDivide(number as nullable number, divisor as number, optional precision as any) as nullable numberReturns: The whole part of the division, or null when the input is null.
What it does
Number.IntegerDivide answers "how many complete units fit" without any decimal part. It is the whole number version of a division. Use it when a fraction makes no sense, such as the number of full pallets, full weeks, or complete installments. Pair it with Number.Mod to get the leftover.
Syntax and arguments
- number: the amount to divide.
- divisor: the size of each unit.
- precision (optional): a setting for the arithmetic used. Leave it out for whole numbers.
Example
A company pays a loan in full installments of 250 dollars. The question is how many full installments a balance covers, and how much is left over.
let
Balance = 1080,
Installment = 250,
FullPayments = Number.IntegerDivide(Balance, Installment),
Remainder = Number.Mod(Balance, Installment)
in
{FullPayments, Remainder}
1080 divided by 250 gives 4 full installments, with 80 left over, so the result is {4, 80}. The remainder is the amount that does not make a full installment.
Example: a second, different use
Work out how many complete pallets of a given count fit into a shipment, and how many units are left for a partial pallet.
Things to watch
- It drops the fraction. 1080 divided by 250 is 4.32, and the function returns 4.
- Number.RoundDown gives the same answer for positive numbers, but the name of this function says what you mean.
- The divisor must not be zero.
- Null in gives null out.
In business terms
Installments, pallets, billing units and full periods are whole quantities. Taking the whole part of a division makes the query say that directly, which is easier for a reviewer than a long division formula.