Enum rust_decimal::prelude::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
Please use RoundingStrategy::MidpointNearestEven instead
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
Please use RoundingStrategy::MidpointAwayFromZero instead
Rounds up if the value >= 5, otherwise rounds down, e.g. 6.5 -> 7
RoundHalfDown
Please use RoundingStrategy::MidpointTowardZero instead
Rounds down if the value =< 5, otherwise rounds up, e.g. 6.5 -> 6, 6.51 -> 7 1.4999999 -> 1
RoundDown
Please use RoundingStrategy::ToZero instead
Always round down.
RoundUp
Please use RoundingStrategy::AwayFromZero instead
Always round up.
Trait Implementations
sourceimpl Clone for RoundingStrategy
impl Clone for RoundingStrategy
sourcefn clone(&self) -> RoundingStrategy
fn clone(&self) -> RoundingStrategy
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for RoundingStrategy
impl Debug for RoundingStrategy
sourceimpl PartialEq<RoundingStrategy> for RoundingStrategy
impl PartialEq<RoundingStrategy> for RoundingStrategy
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn 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>,
Converts self
into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
sourceimpl<T> IntoSql for T
impl<T> IntoSql for T
sourcefn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
Convert self
to an expression for Diesel’s query builder. Read more
sourcefn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel’s query builder. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more