API reference / Quittio \ Core \ Calculation
LargestRemainder
final class in quittio/core
Quittio\Core\Calculation\LargestRemainder · Source
Distributes an amount over weights so that the rounded parts add up exactly (largest remainder method).
Weights are signed: each part is total × weight / Σ weights, so a negative weight (e.g. a VAT group that only contains returns) receives a part with the opposite sign.
Methods#
| Method | Description |
|---|---|
::distribute() |
distribute()#
public static function distribute(
BigDecimal $total,
array<array-key, BigDecimal> $weights,
int<0, max> $scale = 2,
): array<array-key, BigDecimal>| Parameter | Type | Description |
|---|---|---|
$total | Brick\Math\BigDecimal | |
$weights | array<array-key, Brick\Math\BigDecimal> | |
$scale | int<0, max> = 2 |
- Returns
array<array-key, Brick\Math\BigDecimal>– parts with $scale decimals, same keys as $weights- Throws
CalculationException– if the weights are not all zero but add up to zero