Skip to main content

Decimal

Struct Decimal 

Source
pub struct Decimal(/* private fields */);
Expand description

An exact decimal number.

Implementations§

Source§

impl Decimal

Source

pub const ZERO: Decimal

The number zero.

Source

pub const ONE: Decimal

The number one.

Source

pub const MAX_VALUE: Decimal

The largest value: 79,228,162,514,264,337,593,543,950,335.

Source

pub const MIN_VALUE: Decimal

The smallest value: -79,228,162,514,264,337,593,543,950,335.

Source

pub fn from_parts(mantissa: u128, scale: u8, negative: bool) -> Decimal

A decimal of mantissa / 10^scale, negated when negative.

Panics when the mantissa has more than 96 bits or the scale is greater than 28.

Source

pub fn mantissa(&self) -> u128

The 96-bit integer that, divided by 10^scale, is the magnitude.

Source

pub fn scale(&self) -> u8

The number of digits after the decimal point (0 to 28).

Source

pub fn is_sign_negative(&self) -> bool

Whether the sign bit is set. Negative zero has it set and is equal to zero.

Source

pub fn is_zero(&self) -> bool

Whether the value is zero (of any scale and sign).

Source

pub fn max(self, other: Decimal) -> Decimal

The larger of two values (C# Math.Max): of two equal values the first, which matters for their scales.

Source

pub fn min(self, other: Decimal) -> Decimal

The smaller of two values (C# Math.Min): of two equal values the second, which matters for their scales.

Source

pub fn checked_add(self, other: Decimal) -> Option<Decimal>

The sum, or None when it is out of range.

Source

pub fn checked_sub(self, other: Decimal) -> Option<Decimal>

The difference, or None when it is out of range.

Source

pub fn checked_div(self, other: Decimal) -> Option<Decimal>

The quotient, or None when it is out of range. Panics when other is zero.

Source

pub fn to_f64(&self) -> f64

The nearest double-precision number (the explicit conversion of the managed type to a double).

Source

pub fn to_f32(&self) -> f32

The nearest single-precision number (the explicit conversion of the managed type to a float): the double of the value, narrowed.

Source

pub fn round_to_integer(&self) -> i128

The value rounded to an integer, midpoints to even (Decimal.Round with no decimals, which the conversions of the managed runtime to the integer types apply before their range check).

Source

pub fn from_f64(value: f64) -> Decimal

The decimal of a double-precision number, rounded to 15 significant digits (the explicit conversion of a double to the managed type).

Panics when the number is not finite or is outside the value range.

Source

pub fn from_f32(value: f32) -> Decimal

The decimal of a single-precision number, rounded to 7 significant digits (the explicit conversion of a float to the managed type).

Panics when the number is not finite or is outside the value range.

Source

pub fn try_from_f32(value: f32) -> Option<Decimal>

from_f32, with None where it panics.

Source

pub fn try_from_f64(value: f64) -> Option<Decimal>

from_f64, with None where it panics.

Source

pub fn parse(s: &str) -> Result<Decimal, NumberParseError>

Parses text of the invariant culture with the Number styles: leading and trailing white space, a leading or trailing sign, a decimal point and group separators.

Source

pub fn try_parse(s: &str) -> Option<Decimal>

Decimal::parse without the reason of a failure.

Source

pub fn parse_with( s: &str, styles: NumberStyles, provider: Option<&NumberFormatInfo>, ) -> Result<Decimal, NumberParseError>

Parses text with the given styles and format information (C# decimal.Parse(string, NumberStyles, IFormatProvider)). Without a provider the format information of the current culture is used.

Styles that are not defined, and the hexadecimal and binary styles, are an error (NumberParseError::InvalidStyle).

Source

pub fn try_parse_with( s: &str, styles: NumberStyles, provider: Option<&NumberFormatInfo>, ) -> Option<Decimal>

Decimal::parse_with without the reason of a failure.

Source

pub fn to_string_with( &self, format: &str, provider: Option<&NumberFormatInfo>, ) -> Result<String, FormatError>

Formats the value with a standard or custom numeric format string (C# ToString(string, IFormatProvider)). Without a provider the format information of the current culture is used.

Source

pub fn to_string_provider(&self, provider: &NumberFormatInfo) -> String

Formats the value in the general format with the given format information (C# ToString(IFormatProvider)).

Trait Implementations§

Source§

impl Add for Decimal

Source§

type Output = Decimal

The resulting type after applying the + operator.
Source§

fn add(self, other: Decimal) -> Decimal

Performs the + operation. Read more
Source§

impl AddAssign for Decimal

Source§

fn add_assign(&mut self, other: Decimal)

Performs the += operation. Read more
Source§

impl Clone for Decimal

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Decimal

Source§

impl Debug for Decimal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Decimal

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Decimal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for Decimal

Source§

type Output = Decimal

The resulting type after applying the / operator.
Source§

fn div(self, other: Decimal) -> Decimal

Performs the / operation. Read more
Source§

impl Eq for Decimal

Source§

impl From<i8> for Decimal

Source§

fn from(value: i8) -> Decimal

Converts to this type from the input type.
Source§

impl From<i16> for Decimal

Source§

fn from(value: i16) -> Decimal

Converts to this type from the input type.
Source§

impl From<i32> for Decimal

Source§

fn from(value: i32) -> Decimal

Converts to this type from the input type.
Source§

impl From<i64> for Decimal

Source§

fn from(value: i64) -> Decimal

Converts to this type from the input type.
Source§

impl From<isize> for Decimal

Source§

fn from(value: isize) -> Decimal

Converts to this type from the input type.
Source§

impl From<u8> for Decimal

Source§

fn from(value: u8) -> Decimal

Converts to this type from the input type.
Source§

impl From<u16> for Decimal

Source§

fn from(value: u16) -> Decimal

Converts to this type from the input type.
Source§

impl From<u32> for Decimal

Source§

fn from(value: u32) -> Decimal

Converts to this type from the input type.
Source§

impl From<u64> for Decimal

Source§

fn from(value: u64) -> Decimal

Converts to this type from the input type.
Source§

impl From<usize> for Decimal

Source§

fn from(value: usize) -> Decimal

Converts to this type from the input type.
Source§

impl FromStr for Decimal

Source§

type Err = NumberParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Decimal

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MarkupTyped for Decimal

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl Neg for Decimal

Source§

type Output = Decimal

The resulting type after applying the - operator.
Source§

fn neg(self) -> Decimal

Performs the unary - operation. Read more
Source§

impl Ord for Decimal

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Decimal

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Decimal

Source§

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 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Decimal

Source§

impl Sub for Decimal

Source§

type Output = Decimal

The resulting type after applying the - operator.
Source§

fn sub(self, other: Decimal) -> Decimal

Performs the - operation. Read more
Source§

impl SubAssign for Decimal

Source§

fn sub_assign(&mut self, other: Decimal)

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ResourceKeyObject for T
where T: Eq + Hash + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn ResourceKeyObject + 'static)) -> bool

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

fn key_type_name(&self) -> &'static str

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.