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<RoundingStrategy> for RoundingStrategy
impl PartialEq<RoundingStrategy> 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 ==
.impl Copy for RoundingStrategy
impl Eq for RoundingStrategy
impl StructuralEq for RoundingStrategy
impl StructuralPartialEq for RoundingStrategy
Auto Trait Implementations§
impl RefUnwindSafe for RoundingStrategy
impl Send for RoundingStrategy
impl Sync for RoundingStrategy
impl Unpin for RoundingStrategy
impl UnwindSafe for RoundingStrategy
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
§fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
self
into a collection.fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where
F: FnMut(T) -> U,
A: Array<Item = U>,
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
&self
to an expression for Diesel’s query builder. Read moresource§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
&self
to an expression for Diesel’s query builder. Read more