Struct rust_decimal::Decimal
[−]
[src]
pub struct Decimal { /* fields omitted */ }
Decimal
represents a 128 bit representation of a fixed-precision decimal number.
The finite set of values of type Decimal
are of the form m / 10e,
where m is an integer such that -296 <= m <= 296, and e is an integer
between 0 and 28 inclusive.
Methods
impl Decimal
[src]
fn new(num: i64, scale: u32) -> Decimal
[src]
Returns a Decimal
with a 64 bit m
representation and corresponding e
scale.
Arguments
num
- An i64 that represents them
portion of the decimal numberscale
- A u32 representing thee
portion of the decimal number.
Example
use rust_decimal::Decimal; let _pi = Decimal::new(3141i64, 3u32);
fn from_parts(lo: u32, mid: u32, hi: u32, negative: bool, scale: u32) -> Decimal
[src]
Returns a Decimal
using the instances constituent parts.
Arguments
lo
- The low 32 bits of a 96-bit integer.mid
- The middle 32 bits of a 96-bit integer.hi
- The high 32 bits of a 96-bit integer.negative
-true
to indicate a negative number.scale
- A power of 10 ranging from 0 to 28.
Example
use rust_decimal::Decimal; let _pi = Decimal::from_parts(3141u32, 0u32, 0u32, false, 3u32);
fn scale(&self) -> u32
[src]
Returns the scale of the decimal number, otherwise known as e
.
fn set_sign(&mut self, positive: bool)
[src]
An optimized method for changing the sign of a decimal number.
Arguments
positive
: true if the resulting decimal should be positive.
fn set_scale(&mut self, scale: u32) -> Result<(), Error>
[src]
An optimized method for changing the scale of a decimal number.
Arguments
scale
: the new scale of the number
fn serialize(&self) -> [u8; 16]
[src]
Returns a serialized version of the decimal number. The resulting byte array will have the following representation:
- Bytes 1-4: flags
- Bytes 5-8: lo portion of
m
- Bytes 9-12: mid portion of
m
- Bytes 13-16: high portion of
m
fn deserialize(bytes: [u8; 16]) -> Decimal
[src]
Deserializes the given bytes into a decimal number. The deserialized byte representation must be 16 bytes and adhere to the followign convention:
- Bytes 1-4: flags
- Bytes 5-8: lo portion of
m
- Bytes 9-12: mid portion of
m
- Bytes 13-16: high portion of
m
fn is_negative(&self) -> bool
[src]
: please use is_sign_negative
instead
Returns true
if the decimal is negative.
fn is_positive(&self) -> bool
[src]
: please use is_sign_positive
instead
Returns true
if the decimal is positive.
fn is_sign_negative(&self) -> bool
[src]
Returns true
if the decimal is negative.
fn is_sign_positive(&self) -> bool
[src]
Returns true
if the decimal is positive.
fn min_value() -> Decimal
[src]
Returns the minimum possible number that Decimal
can represent.
fn max_value() -> Decimal
[src]
Returns the maximum possible number that Decimal
can represent.
fn trunc(&self) -> Decimal
[src]
Returns a new Decimal
integral with no fractional portion.
This is a true truncation whereby no rounding is performed, e.g. 1.56 -> 1
fn fract(&self) -> Decimal
[src]
Returns a new Decimal
representing the fractional portion of the number.
e.g. 1.56 -> 0.56
fn normalize(&self) -> Decimal
[src]
Strips any trailing zero's from a Decimal
. e.g. 1.10 -> 1.1
fn round(&self) -> Decimal
[src]
Returns a new Decimal
number with no fractional portion (i.e. an integer).
Rounding currently follows "Bankers Rounding" rules. e.g. 6.5 -> 6, 7.5 -> 8
fn round_dp(&self, dp: u32) -> Decimal
[src]
Returns a new Decimal
number with the specified number of decimal points for fractional portion.
Rounding currently follows "Bankers Rounding" rules. e.g. 6.5 -> 6, 7.5 -> 8
Arguments
dp
: the number of decimal points to round to.
Trait Implementations
impl Clone for Decimal
[src]
fn clone(&self) -> Decimal
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Decimal
[src]
impl Debug for Decimal
[src]
impl From<isize> for Decimal
[src]
impl From<i8> for Decimal
[src]
impl From<i16> for Decimal
[src]
impl From<i32> for Decimal
[src]
impl From<i64> for Decimal
[src]
impl From<usize> for Decimal
[src]
impl From<u8> for Decimal
[src]
impl From<u16> for Decimal
[src]
impl From<u32> for Decimal
[src]
impl From<u64> for Decimal
[src]
impl Zero for Decimal
[src]
fn is_zero(&self) -> bool
[src]
Returns true
if self
is equal to the additive identity.
fn zero() -> Decimal
[src]
Returns the additive identity element of Self
, 0
. Read more
impl One for Decimal
[src]
impl FromStr for Decimal
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(value: &str) -> Result<Decimal, Self::Err>
[src]
Parses a string s
to return a value of this type. Read more
impl FromPrimitive for Decimal
[src]
fn from_i32(n: i32) -> Option<Decimal>
[src]
Convert an i32
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_i64(n: i64) -> Option<Decimal>
[src]
Convert an i64
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_u32(n: u32) -> Option<Decimal>
[src]
Convert an u32
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_u64(n: u64) -> Option<Decimal>
[src]
Convert an u64
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_f32(n: f32) -> Option<Decimal>
[src]
Convert a f32
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_f64(n: f64) -> Option<Decimal>
[src]
Convert a f64
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_isize(n: isize) -> Option<Self>
[src]
Convert an isize
to return an optional value of this type. If the value cannot be represented by this value, the None
is returned. Read more
fn from_i8(n: i8) -> Option<Self>
[src]
Convert an i8
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_i16(n: i16) -> Option<Self>
[src]
Convert an i16
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_usize(n: usize) -> Option<Self>
[src]
Convert a usize
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_u8(n: u8) -> Option<Self>
[src]
Convert an u8
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
fn from_u16(n: u16) -> Option<Self>
[src]
Convert an u16
to return an optional value of this type. If the type cannot be represented by this value, the None
is returned. Read more
impl ToPrimitive for Decimal
[src]
fn to_f64(&self) -> Option<f64>
[src]
Converts the value of self
to an f64
.
fn to_i64(&self) -> Option<i64>
[src]
Converts the value of self
to an i64
.
fn to_u64(&self) -> Option<u64>
[src]
Converts the value of self
to an u64
.
fn to_isize(&self) -> Option<isize>
[src]
Converts the value of self
to an isize
.
fn to_i8(&self) -> Option<i8>
[src]
Converts the value of self
to an i8
.
fn to_i16(&self) -> Option<i16>
[src]
Converts the value of self
to an i16
.
fn to_i32(&self) -> Option<i32>
[src]
Converts the value of self
to an i32
.
fn to_usize(&self) -> Option<usize>
[src]
Converts the value of self
to a usize
.
fn to_u8(&self) -> Option<u8>
[src]
Converts the value of self
to an u8
.
fn to_u16(&self) -> Option<u16>
[src]
Converts the value of self
to an u16
.
fn to_u32(&self) -> Option<u32>
[src]
Converts the value of self
to an u32
.
fn to_f32(&self) -> Option<f32>
[src]
Converts the value of self
to an f32
.
impl Display for Decimal
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl Add<Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the +
operator.
fn add(self, other: Decimal) -> Decimal
[src]
Performs the +
operation.
impl<'a> Add<Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the +
operator.
fn add(self, other: Decimal) -> Decimal
[src]
Performs the +
operation.
impl<'a> Add<&'a Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the +
operator.
fn add(self, other: &Decimal) -> Decimal
[src]
Performs the +
operation.
impl<'a, 'b> Add<&'b Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the +
operator.
fn add(self, other: &Decimal) -> Decimal
[src]
Performs the +
operation.
impl AddAssign for Decimal
[src]
fn add_assign(&mut self, other: Decimal)
[src]
Performs the +=
operation.
impl Sub<Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the -
operator.
fn sub(self, other: Decimal) -> Decimal
[src]
Performs the -
operation.
impl<'a> Sub<Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the -
operator.
fn sub(self, other: Decimal) -> Decimal
[src]
Performs the -
operation.
impl<'a> Sub<&'a Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the -
operator.
fn sub(self, other: &Decimal) -> Decimal
[src]
Performs the -
operation.
impl<'a, 'b> Sub<&'b Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the -
operator.
fn sub(self, other: &Decimal) -> Decimal
[src]
Performs the -
operation.
impl SubAssign for Decimal
[src]
fn sub_assign(&mut self, other: Decimal)
[src]
Performs the -=
operation.
impl Mul<Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the *
operator.
fn mul(self, other: Decimal) -> Decimal
[src]
Performs the *
operation.
impl<'a> Mul<Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the *
operator.
fn mul(self, other: Decimal) -> Decimal
[src]
Performs the *
operation.
impl<'a> Mul<&'a Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the *
operator.
fn mul(self, other: &Decimal) -> Decimal
[src]
Performs the *
operation.
impl<'a, 'b> Mul<&'b Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the *
operator.
fn mul(self, other: &Decimal) -> Decimal
[src]
Performs the *
operation.
impl MulAssign for Decimal
[src]
fn mul_assign(&mut self, other: Decimal)
[src]
Performs the *=
operation.
impl Div<Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the /
operator.
fn div(self, other: Decimal) -> Decimal
[src]
Performs the /
operation.
impl<'a> Div<Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the /
operator.
fn div(self, other: Decimal) -> Decimal
[src]
Performs the /
operation.
impl<'a> Div<&'a Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the /
operator.
fn div(self, other: &Decimal) -> Decimal
[src]
Performs the /
operation.
impl<'a, 'b> Div<&'b Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the /
operator.
fn div(self, other: &Decimal) -> Decimal
[src]
Performs the /
operation.
impl DivAssign for Decimal
[src]
fn div_assign(&mut self, other: Decimal)
[src]
Performs the /=
operation.
impl Rem<Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the %
operator.
fn rem(self, other: Decimal) -> Decimal
[src]
Performs the %
operation.
impl<'a> Rem<Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the %
operator.
fn rem(self, other: Decimal) -> Decimal
[src]
Performs the %
operation.
impl<'a> Rem<&'a Decimal> for Decimal
[src]
type Output = Decimal
The resulting type after applying the %
operator.
fn rem(self, other: &Decimal) -> Decimal
[src]
Performs the %
operation.
impl<'a, 'b> Rem<&'b Decimal> for &'a Decimal
[src]
type Output = Decimal
The resulting type after applying the %
operator.
fn rem(self, other: &Decimal) -> Decimal
[src]
Performs the %
operation.
impl RemAssign for Decimal
[src]
fn rem_assign(&mut self, other: Decimal)
[src]
Performs the %=
operation.
impl PartialEq for Decimal
[src]
fn eq(&self, other: &Decimal) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Eq for Decimal
[src]
impl Hash for Decimal
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialOrd for Decimal
[src]
fn partial_cmp(&self, other: &Decimal) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Decimal
[src]
fn cmp(&self, other: &Decimal) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl<'de> Deserialize<'de> for Decimal
[src]
fn deserialize<D>(deserializer: D) -> Result<Decimal, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more