pub struct Decimal(/* private fields */);Expand description
An exact decimal number.
Implementations§
Source§impl Decimal
impl Decimal
Sourcepub fn from_parts(mantissa: u128, scale: u8, negative: bool) -> Decimal
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.
Sourcepub fn is_sign_negative(&self) -> bool
pub fn is_sign_negative(&self) -> bool
Whether the sign bit is set. Negative zero has it set and is equal to zero.
Sourcepub fn max(self, other: Decimal) -> Decimal
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.
Sourcepub fn min(self, other: Decimal) -> Decimal
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.
Sourcepub fn checked_add(self, other: Decimal) -> Option<Decimal>
pub fn checked_add(self, other: Decimal) -> Option<Decimal>
The sum, or None when it is out of range.
Sourcepub fn checked_sub(self, other: Decimal) -> Option<Decimal>
pub fn checked_sub(self, other: Decimal) -> Option<Decimal>
The difference, or None when it is out of range.
Sourcepub fn checked_div(self, other: Decimal) -> Option<Decimal>
pub fn checked_div(self, other: Decimal) -> Option<Decimal>
The quotient, or None when it is out of range. Panics when other
is zero.
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
The nearest double-precision number (the explicit conversion of the managed type to a double).
Sourcepub fn to_f32(&self) -> f32
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.
Sourcepub fn round_to_integer(&self) -> i128
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).
Sourcepub fn from_f64(value: f64) -> Decimal
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.
Sourcepub fn from_f32(value: f32) -> Decimal
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.
Sourcepub fn parse(s: &str) -> Result<Decimal, NumberParseError>
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.
Sourcepub fn parse_with(
s: &str,
styles: NumberStyles,
provider: Option<&NumberFormatInfo>,
) -> Result<Decimal, NumberParseError>
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).
Sourcepub fn try_parse_with(
s: &str,
styles: NumberStyles,
provider: Option<&NumberFormatInfo>,
) -> Option<Decimal>
pub fn try_parse_with( s: &str, styles: NumberStyles, provider: Option<&NumberFormatInfo>, ) -> Option<Decimal>
Decimal::parse_with without the reason of a failure.
Sourcepub fn to_string_with(
&self,
format: &str,
provider: Option<&NumberFormatInfo>,
) -> Result<String, FormatError>
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.
Sourcepub fn to_string_provider(&self, provider: &NumberFormatInfo) -> String
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 AddAssign for Decimal
impl AddAssign for Decimal
Source§fn add_assign(&mut self, other: Decimal)
fn add_assign(&mut self, other: Decimal)
+= operation. Read moreimpl Copy for Decimal
impl Eq for Decimal
Source§impl MarkupTyped for Decimal
impl MarkupTyped for Decimal
Source§const MARKUP: &'static MarkupType
const MARKUP: &'static MarkupType
Source§impl Ord for Decimal
impl Ord for Decimal
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Decimal
impl PartialOrd 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 UnsafeUnpin for Decimal
impl UnwindSafe for Decimal
Blanket Implementations§
Source§impl<T> AnyValue for Twhere
T: PartialEq + 'static,
impl<T> AnyValue for Twhere
T: PartialEq + 'static,
fn any_value_as_any(&self) -> &(dyn Any + 'static)
fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool
fn any_value_type_name(&self) -> &'static str
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> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more