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 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 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]
Returns true
if the decimal is negative.
fn is_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 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 Debug for Decimal
[src]
impl Copy 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_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
fn from_f32(n: f32) -> Option<Self>
[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<Self>
[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
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 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 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 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 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 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 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 FromSql for Decimal
[src]
fn from_sql(
_: &Type,
raw: &[u8]
) -> Result<Decimal, Box<Error + Sync + Send + 'static>>
[src]
_: &Type,
raw: &[u8]
) -> Result<Decimal, Box<Error + Sync + Send + 'static>>
Creates a new value of this type from a buffer of data of the specified Postgres Type
in its binary format. Read more
fn accepts(ty: &Type) -> bool
[src]
Determines if a value of this type can be created from the specified Postgres Type
. Read more
fn from_sql_null(ty: &Type) -> Result<Self, Box<Error + 'static + Send + Sync>>
Creates a new value of this type from a NULL
SQL value. Read more
fn from_sql_nullable(
ty: &Type,
raw: Option<&[u8]>
) -> Result<Self, Box<Error + 'static + Send + Sync>>
ty: &Type,
raw: Option<&[u8]>
) -> Result<Self, Box<Error + 'static + Send + Sync>>
A convenience function that delegates to from_sql
and from_sql_null
depending on the value of raw
. Read more
impl ToSql for Decimal
[src]
fn to_sql(
&self,
_: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send + 'static>>
[src]
&self,
_: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send + 'static>>
Converts the value of self
into the binary format of the specified Postgres Type
, appending it to out
. Read more
fn accepts(ty: &Type) -> bool
[src]
Determines if a value of this type can be converted to the specified Postgres Type
. Read more
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<Error + Sync + Send>>
An adaptor method used internally by Rust-Postgres. 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