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
Sourcepub fn round_decimal(&self, n: BigDecimal) -> BigDecimal
pub fn round_decimal(&self, n: BigDecimal) -> BigDecimal
Round decimal to precision in this context, using rounding-mode
Sourcepub fn round_decimal_ref<'a, D: Into<BigDecimalRef<'a>>>(
&self,
n: D,
) -> BigDecimal
pub fn round_decimal_ref<'a, D: Into<BigDecimalRef<'a>>>( &self, n: D, ) -> BigDecimal
Round decimal to precision in this context, using 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