Struct bigdecimal::Context
source · pub struct Context { /* private fields */ }
Expand description
Mathematical Context
Stores rules for numerical operations, such as how to round and number of digits to keep.
Defaults are defined at compile time, determined by environment variables:
Variable | Descripiton | default |
---|---|---|
RUST_BIGDECIMAL_DEFAULT_PRECISION | digit precision | 100 |
RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE | rounding-mode | HalfEven |
It is recommended that the user set explicit values of a Context and not rely on compile time constants, but the option is there if necessary.
Implementations§
source§impl Context
impl Context
sourcepub fn new(precision: NonZeroU64, rounding: RoundingMode) -> Self
pub fn new(precision: NonZeroU64, rounding: RoundingMode) -> Self
Create context with precision and rounding mode
sourcepub fn with_precision(&self, precision: NonZeroU64) -> Self
pub fn with_precision(&self, precision: NonZeroU64) -> Self
Copy context with new precision value
sourcepub fn with_prec<T: ToPrimitive>(&self, precision: T) -> Option<Self>
pub fn with_prec<T: ToPrimitive>(&self, precision: T) -> Option<Self>
Copy context with new precision value
sourcepub fn with_rounding_mode(&self, mode: RoundingMode) -> Self
pub fn with_rounding_mode(&self, mode: RoundingMode) -> Self
Copy context with new rounding mode
sourcepub fn precision(&self) -> NonZeroU64
pub fn precision(&self) -> NonZeroU64
Return maximum precision
sourcepub fn rounding_mode(&self) -> RoundingMode
pub fn rounding_mode(&self) -> RoundingMode
Return rounding mode
source§impl Context
impl Context
sourcepub fn add_refs<'a, 'b, A, B>(&self, a: A, b: B) -> BigDecimal
pub fn add_refs<'a, 'b, A, B>(&self, a: A, b: B) -> BigDecimal
Add two big digit references
sourcepub fn add_refs_into<'a, 'b, A, B>(&self, a: A, b: B, dest: &mut BigDecimal)
pub fn add_refs_into<'a, 'b, A, B>(&self, a: A, b: B, dest: &mut BigDecimal)
Add two decimal refs, storing value in dest
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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