#[repr(u8)]pub enum RoundingMode {
No = 0,
Up = 1,
Down = 2,
Ceiling = 3,
Floor = 4,
HalfUp = 5,
HalfDown = 6,
HalfEven = 7,
}Expand description
Determines how to calculate the last digit of the number
Default rounding mode is HalfUp.
Variants§
No = 0
Special no-rounding mode.
Up = 1
Always round away from zero
- 5.5 → 6.0
- 2.5 → 3.0
- 1.6 → 2.0
- 1.1 → 2.0
- -1.1 → -2.0
- -1.6 → -2.0
- -2.5 → -3.0
- -5.5 → -6.0
Down = 2
Always round towards zero
- 5.5 → 5.0
- 2.5 → 2.0
- 1.6 → 1.0
- 1.1 → 1.0
- -1.1 → -1.0
- -1.6 → -1.0
- -2.5 → -2.0
- -5.5 → -5.0
Ceiling = 3
Towards +∞
- 5.5 → 6.0
- 2.5 → 3.0
- 1.6 → 2.0
- 1.1 → 2.0
- -1.1 → -1.0
- -1.6 → -1.0
- -2.5 → -2.0
- -5.5 → -5.0
Floor = 4
Towards -∞
- 5.5 → 5.0
- 2.5 → 2.0
- 1.6 → 1.0
- 1.1 → 1.0
- -1.1 → -2.0
- -1.6 → -2.0
- -2.5 → -3.0
- -5.5 → -6.0
HalfUp = 5
Round to ‘nearest neighbor’, or up if ending decimal is 5
- 5.5 → 6.0
- 2.5 → 3.0
- 1.6 → 2.0
- 1.1 → 1.0
- -1.1 → -1.0
- -1.6 → -2.0
- -2.5 → -3.0
- -5.5 → -6.0
HalfDown = 6
Round to ‘nearest neighbor’, or down if ending decimal is 5
- 5.5 → 5.0
- 2.5 → 2.0
- 1.6 → 2.0
- 1.1 → 1.0
- -1.1 → -1.0
- -1.6 → -2.0
- -2.5 → -2.0
- -5.5 → -5.0
HalfEven = 7
Round to ‘nearest neighbor’, if equidistant, round towards nearest even digit
- 5.5 → 6.0
- 2.5 → 2.0
- 1.6 → 2.0
- 1.1 → 1.0
- -1.1 → -1.0
- -1.6 → -2.0
- -2.5 → -2.0
- -5.5 → -6.0
Implementations§
Source§impl RoundingMode
impl RoundingMode
Sourcepub const fn is_default(&self) -> bool
pub const fn is_default(&self) -> bool
Returns true if given RoundingMode is
default.
Trait Implementations§
Source§impl Clone for RoundingMode
impl Clone for RoundingMode
Source§fn clone(&self) -> RoundingMode
fn clone(&self) -> RoundingMode
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RoundingMode
impl Debug for RoundingMode
Source§impl Default for RoundingMode
impl Default for RoundingMode
Source§impl Display for RoundingMode
impl Display for RoundingMode
Source§impl Hash for RoundingMode
impl Hash for RoundingMode
Source§impl PartialEq for RoundingMode
impl PartialEq for RoundingMode
Source§fn eq(&self, other: &RoundingMode) -> bool
fn eq(&self, other: &RoundingMode) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for RoundingMode
impl Eq for RoundingMode
impl StructuralPartialEq for RoundingMode
Auto Trait Implementations§
impl Freeze for RoundingMode
impl RefUnwindSafe for RoundingMode
impl Send for RoundingMode
impl Sync for RoundingMode
impl Unpin for RoundingMode
impl UnsafeUnpin for RoundingMode
impl UnwindSafe for RoundingMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more