pub struct Decimal { /* private fields */ }
Expand description
An arbitrary-precision Decimal type with a distinct representation of negative zero (-0
).
Implementations
sourceimpl Decimal
impl Decimal
sourcepub fn new<I: Into<Coefficient>>(coefficient: I, exponent: i64) -> Decimal
pub fn new<I: Into<Coefficient>>(coefficient: I, exponent: i64) -> Decimal
Constructs a new Decimal with the provided components. The value of the decimal is (coefficient * 10^exponent) * (if sign == Sign::Negative { -1 } else { 1 })
sourcepub fn scale(&self) -> i64
pub fn scale(&self) -> i64
Returns scale of the Decimal value If zero or positive, a scale indicates the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.
sourcepub fn precision(&self) -> u64
pub fn precision(&self) -> u64
Returns the number of digits in the non-scaled integer representation of the decimal.
sourcepub fn negative_zero() -> Decimal
pub fn negative_zero() -> Decimal
Constructs a Decimal with the value -0d0
. This is provided as a convenience method
because Rust will ignore a unary minus when it is applied to an zero literal (-0
).
sourcepub fn negative_zero_with_exponent(exponent: i64) -> Decimal
pub fn negative_zero_with_exponent(exponent: i64) -> Decimal
Constructs a Decimal with a coefficient of -0
and the specified exponent. This function
is provided as a convenience method because Rust will ignore a unary minus when it is
applied to a zero literal (-0
).
sourcepub fn is_less_than_zero(&self) -> bool
pub fn is_less_than_zero(&self) -> bool
Returns true if this Decimal’s coefficient has a negative sign AND a magnitude greater than zero. Otherwise, returns false. (Negative zero returns false.)
Trait Implementations
sourceimpl From<BigDecimal> for Decimal
impl From<BigDecimal> for Decimal
Make a Decimal from a BigDecimal. This is a lossless operation.
sourcefn from(value: BigDecimal) -> Self
fn from(value: BigDecimal) -> Self
Converts to this type from the input type.
sourceimpl<'val> From<Decimal> for BorrowedElement<'val>
impl<'val> From<Decimal> for BorrowedElement<'val>
sourceimpl From<Decimal> for OwnedElement
impl From<Decimal> for OwnedElement
sourceimpl Ord for Decimal
impl Ord for Decimal
sourceimpl PartialOrd<Decimal> for Decimal
impl PartialOrd<Decimal> for Decimal
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryFrom<Decimal> for BigDecimal
impl TryFrom<Decimal> for BigDecimal
sourceimpl TryFrom<f64> for Decimal
impl TryFrom<f64> for Decimal
sourcefn try_from(value: f64) -> Result<Self, Self::Error>
fn try_from(value: f64) -> Result<Self, Self::Error>
Attempts to create a Decimal from an f64. Returns an Error if the f64 being converted is a special value, including:
- Infinity
- Negative infinity
- NaN (not-a-number) Otherwise, returns Ok.
Because Decimal can represent negative zero, f64::neg_zero() IS supported.
NOTE: While the resulting decimal will be a very close approximation of the original f64’s value, this is an inherently lossy operation. Floating point values do not encode a precision. When converting an f64 to a Decimal, a precision for the new Decimal must be chosen somewhat arbitrarily. Do NOT rely on the precision of the resulting Decimal. This implementation may change without notice.
impl Eq for Decimal
Auto Trait Implementations
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnwindSafe for Decimal
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<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