Skip to content

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#

MethodDescription
::distribute()

distribute()#

public static function distribute(
    BigDecimal $total,
    array<array-key, BigDecimal> $weights,
    int<0, max> $scale = 2,
): array<array-key, BigDecimal>

static

ParameterTypeDescription
$totalBrick\Math\BigDecimal
$weightsarray<array-key, Brick\Math\BigDecimal>
$scaleint<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

The open core packages are MIT licensed. The legal wording of the country packs must be confirmed by a tax adviser.