Decimal
struct · ferroui-base · v0.5.0
struct Decimal
An exact decimal number.
Members
ZEROONEMAX_VALUEMIN_VALUEfrom_partsmantissascaleis_sign_negativeis_zeromaxminchecked_addchecked_subchecked_mulchecked_divto_f64to_f32round_to_integerfrom_f64from_f32try_from_f32try_from_f64parsetry_parseparse_withtry_parse_withto_string_withto_string_provider
ZERO
const ZERO: Decimal
The number zero.
ONE
const ONE: Decimal
The number one.
MAX_VALUE
const MAX_VALUE: Decimal
The largest value: 79,228,162,514,264,337,593,543,950,335.
MIN_VALUE
const MIN_VALUE: Decimal
The smallest value: -79,228,162,514,264,337,593,543,950,335.
from_parts
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.
mantissa
fn mantissa(self: &Self) -> u128
The 96-bit integer that, divided by 10^scale, is the magnitude.
scale
fn scale(self: &Self) -> u8
The number of digits after the decimal point (0 to 28).
is_sign_negative
fn is_sign_negative(self: &Self) -> bool
Whether the sign bit is set. Negative zero has it set and is equal to zero.
is_zero
fn is_zero(self: &Self) -> bool
Whether the value is zero (of any scale and sign).
max
fn max(self: Self, other: Decimal) -> Decimal
The larger of two values (C# Math.Max): of two equal values the
first, which matters for their scales.
min
fn min(self: Self, other: Decimal) -> Decimal
The smaller of two values (C# Math.Min): of two equal values the
second, which matters for their scales.
checked_add
fn checked_add(self: Self, other: Decimal) -> Option<Decimal>
The sum, or None when it is out of range.
checked_sub
fn checked_sub(self: Self, other: Decimal) -> Option<Decimal>
The difference, or None when it is out of range.
checked_mul
fn checked_mul(self: Self, other: Decimal) -> Option<Decimal>
The product, or None when it is out of range. The scale is the sum
of the scales, rounded to 28 digits after the point when it is larger,
as the managed type multiplies.
checked_div
fn checked_div(self: Self, other: Decimal) -> Option<Decimal>
The quotient, or None when it is out of range. Panics when other
is zero.
to_f64
fn to_f64(self: &Self) -> f64
The nearest double-precision number (the explicit conversion of the managed type to a double).
to_f32
fn to_f32(self: &Self) -> f32
The nearest single-precision number (the explicit conversion of the managed type to a float): the double of the value, narrowed.
round_to_integer
fn round_to_integer(self: &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).
from_f64
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.
from_f32
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.
try_from_f32
fn try_from_f32(value: f32) -> Option<Decimal>
from_f32, with None where it panics.
try_from_f64
fn try_from_f64(value: f64) -> Option<Decimal>
from_f64, with None where it panics.
parse
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.
try_parse
fn try_parse(s: &str) -> Option<Decimal>
Decimal::parse without the reason of a failure.
parse_with
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).
try_parse_with
fn try_parse_with(s: &str, styles: NumberStyles, provider: Option<&NumberFormatInfo>) -> Option<Decimal>
Decimal::parse_with without the reason of a failure.
to_string_with
fn to_string_with(self: &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.
to_string_provider
fn to_string_provider(self: &Self, provider: &NumberFormatInfo) -> String
Formats the value in the general format with the given format
information (C# ToString(IFormatProvider)).
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeResourceKeyObjectPropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherCloneCopyStructuralPartialEqPartialEqEqPartialOrdOrdHashMarkupTypedDefaultDisplayDebugFromStrFrom<i8>From<i16>From<i32>From<i64>From<isize>From<u8>From<u16>From<u32>From<u64>From<usize>NegAddSubDivAddAssignSubAssignValueTypeRegistration
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.