finanza/decimal/rounding
Rounding modes for decimal arithmetic.
Every operation in finanza/decimal that can
reduce precision takes a Mode so the rounding behaviour is
explicit. The seven modes match the IBM General Decimal Arithmetic
specification (see doc/reference/specs/ibm-decimal-arithmetic.md).
Types
The rounding mode applied when a decimal operation must drop digits.
HalfEven is the canonical financial default (“banker’s rounding”):
it rounds half-way values to the nearest even digit, which avoids
the systematic upward bias of HalfUp when many roundings are
summed.
pub type Mode {
HalfEven
HalfUp
HalfDown
Up
Down
Ceiling
Floor
}
Constructors
-
HalfEvenRound half-way values to the nearest even digit.
2.5 -> 2,3.5 -> 4,-2.5 -> -2. -
HalfUpRound half-way values away from zero.
2.5 -> 3,-2.5 -> -3. -
HalfDownRound half-way values toward zero.
2.5 -> 2,-2.5 -> -2. -
UpAlways round away from zero.
2.1 -> 3,-2.1 -> -3. -
DownAlways round toward zero (truncate).
2.9 -> 2,-2.9 -> -2. -
CeilingAlways round toward +∞.
2.1 -> 3,-2.9 -> -2. -
FloorAlways round toward -∞.
2.9 -> 2,-2.1 -> -3.