pub struct Decimal {
pub inner: BigDecimal,
}
Expand description
Mybatis Decimal
Fields§
§inner: BigDecimal
Implementations§
Methods from Deref<Target = BigDecimal>§
Sourcepub fn with_scale(&self, new_scale: i64) -> BigDecimal
pub fn with_scale(&self, new_scale: i64) -> BigDecimal
Return a new BigDecimal object equivalent to self, with internal scaling set to the number specified. If the new_scale is lower than the current value (indicating a larger power of 10), digits will be dropped (as precision is lower)
Sourcepub fn with_prec(&self, prec: u64) -> BigDecimal
pub fn with_prec(&self, prec: u64) -> BigDecimal
Return a new BigDecimal object with precision set to new value
Sourcepub fn sign(&self) -> Sign
pub fn sign(&self) -> Sign
Return the sign of the BigDecimal
as num::bigint::Sign
.
§Examples
extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;
assert_eq!(bigdecimal::BigDecimal::from_str("-1").unwrap().sign(), num_bigint::Sign::Minus);
assert_eq!(bigdecimal::BigDecimal::from_str("0").unwrap().sign(), num_bigint::Sign::NoSign);
assert_eq!(bigdecimal::BigDecimal::from_str("1").unwrap().sign(), num_bigint::Sign::Plus);
Sourcepub fn as_bigint_and_exponent(&self) -> (BigInt, i64)
pub fn as_bigint_and_exponent(&self) -> (BigInt, i64)
Return the internal big integer value and an exponent. Note that a positive exponent indicates a negative power of 10.
§Examples
extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;
assert_eq!(bigdecimal::BigDecimal::from_str("1.1").unwrap().as_bigint_and_exponent(),
(num_bigint::BigInt::from_str("11").unwrap(), 1));
Sourcepub fn abs(&self) -> BigDecimal
pub fn abs(&self) -> BigDecimal
Compute the absolute value of number
pub fn double(&self) -> BigDecimal
Sourcepub fn half(&self) -> BigDecimal
pub fn half(&self) -> BigDecimal
Divide this efficiently by 2
Note, if this is odd, the precision will increase by 1, regardless of the context’s limit.
Sourcepub fn square(&self) -> BigDecimal
pub fn square(&self) -> BigDecimal
pub fn cube(&self) -> BigDecimal
Sourcepub fn sqrt(&self) -> Option<BigDecimal>
pub fn sqrt(&self) -> Option<BigDecimal>
Take the square root of the number
If the value is < 0, None is returned
Sourcepub fn cbrt(&self) -> BigDecimal
pub fn cbrt(&self) -> BigDecimal
Take the cube root of the number
Sourcepub fn inverse(&self) -> BigDecimal
pub fn inverse(&self) -> BigDecimal
Compute the reciprical of the number: x-1
Sourcepub fn round(&self, round_digits: i64) -> BigDecimal
pub fn round(&self, round_digits: i64) -> BigDecimal
Return number rounded to round_digits precision after the decimal point
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Return true if this number has zero fractional part (is equal to an integer)
Sourcepub fn exp(&self) -> BigDecimal
pub fn exp(&self) -> BigDecimal
Evaluate the natural-exponential function ex
pub fn normalized(&self) -> BigDecimal
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Decimal
Decimal allow deserialize by an String or Binary
impl<'de> Deserialize<'de> for Decimal
Decimal allow deserialize by an String or Binary
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Decimal, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Decimal, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<&BigDecimal> for Decimal
impl From<&BigDecimal> for Decimal
Source§fn from(arg: &BigDecimal) -> Decimal
fn from(arg: &BigDecimal) -> Decimal
Source§impl From<BigDecimal> for Decimal
impl From<BigDecimal> for Decimal
Source§fn from(arg: BigDecimal) -> Decimal
fn from(arg: BigDecimal) -> Decimal
Source§impl Ord for Decimal
impl Ord for Decimal
Source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
Source§impl Serialize for Decimal
impl Serialize for Decimal
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Eq for Decimal
impl StructuralPartialEq for Decimal
Auto Trait Implementations§
impl Freeze for Decimal
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnwindSafe for Decimal
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
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more