Enum rust_decimal::RoundingStrategy
source · pub enum RoundingStrategy {
MidpointNearestEven,
MidpointAwayFromZero,
MidpointTowardZero,
ToZero,
AwayFromZero,
ToNegativeInfinity,
ToPositiveInfinity,
BankersRounding,
RoundHalfUp,
RoundHalfDown,
RoundDown,
RoundUp,
}
Expand description
RoundingStrategy
represents the different rounding strategies that can be used by
round_dp_with_strategy
.
Variants§
MidpointNearestEven
When a number is halfway between two others, it is rounded toward the nearest even number. Also known as “Bankers Rounding”. e.g. 6.5 -> 6, 7.5 -> 8
MidpointAwayFromZero
When a number is halfway between two others, it is rounded toward the nearest number that is away from zero. e.g. 6.4 -> 6, 6.5 -> 7, -6.5 -> -7
MidpointTowardZero
When a number is halfway between two others, it is rounded toward the nearest number that is toward zero. e.g. 6.4 -> 6, 6.5 -> 6, -6.5 -> -6
ToZero
The number is always rounded toward zero. e.g. -6.8 -> -6, 6.8 -> 6
AwayFromZero
The number is always rounded away from zero. e.g. -6.8 -> -7, 6.8 -> 7
ToNegativeInfinity
The number is always rounded towards negative infinity. e.g. 6.8 -> 6, -6.8 -> -7
ToPositiveInfinity
The number is always rounded towards positive infinity. e.g. 6.8 -> 7, -6.8 -> -6
BankersRounding
When a number is halfway between two others, it is rounded toward the nearest even number. e.g. 6.5 -> 6, 7.5 -> 8
RoundHalfUp
Rounds up if the value >= 5, otherwise rounds down, e.g. 6.5 -> 7
RoundHalfDown
Rounds down if the value =< 5, otherwise rounds up, e.g. 6.5 -> 6, 6.51 -> 7 1.4999999 -> 1
RoundDown
Always round down.
RoundUp
Always round up.
Trait Implementations§
source§impl Clone for RoundingStrategy
impl Clone for RoundingStrategy
source§fn clone(&self) -> RoundingStrategy
fn clone(&self) -> RoundingStrategy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RoundingStrategy
impl Debug for RoundingStrategy
source§impl PartialEq for RoundingStrategy
impl PartialEq for RoundingStrategy
source§fn eq(&self, other: &RoundingStrategy) -> bool
fn eq(&self, other: &RoundingStrategy) -> bool
self
and other
values to be equal, and is used
by ==
.