LargestRemainder
in package
FinalYes
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.
Table of Contents
Methods
- distribute() : array<string|int, BigDecimal>
Methods
distribute()
public
static distribute(BigDecimal $total, array<string|int, BigDecimal> $weights[, int<0, max> $scale = 2 ]) : array<string|int, BigDecimal>
Parameters
- $total : BigDecimal
- $weights : array<string|int, BigDecimal>
- $scale : int<0, max> = 2
Tags
Return values
array<string|int, BigDecimal> —parts with $scale decimals, same keys as $weights