pub struct CompactDecimal { /* private fields */ }Expand description
A struct containing a Decimal significand together with an exponent, representing a
number written in compact notation (such as 1.2M).
This represents a source number, as defined
in UTS #35.
The value exponent=0 represents a number in non-compact
notation (such as 1 200 000).
This is distinct from crate::ScientificDecimal because it does not represent leading 0s
nor a sign in the exponent, and behaves differently in pluralization.
Implementations§
Source§impl CompactDecimal
impl CompactDecimal
Sourcepub fn from_significand_and_exponent(significand: Decimal, exponent: u8) -> Self
pub fn from_significand_and_exponent(significand: Decimal, exponent: u8) -> Self
Constructs a CompactDecimal from its significand and exponent.
Sourcepub fn significand(&self) -> &Decimal
pub fn significand(&self) -> &Decimal
Returns a reference to the significand of self.
assert_eq!(
CompactDecimal::from_str("+1.20c6").unwrap().significand(),
&Decimal::from_str("+1.20").unwrap()
);Sourcepub fn into_significand(self) -> Decimal
pub fn into_significand(self) -> Decimal
Returns the significand of self.
assert_eq!(
CompactDecimal::from_str("+1.20c6")
.unwrap()
.into_significand(),
Decimal::from_str("+1.20").unwrap()
);Source§impl CompactDecimal
impl CompactDecimal
Sourcepub fn try_from_str(s: &str) -> Result<Self, ParseError>
pub fn try_from_str(s: &str) -> Result<Self, ParseError>
Parses a CompactDecimal.
Trait Implementations§
Source§impl Clone for CompactDecimal
impl Clone for CompactDecimal
Source§fn clone(&self) -> CompactDecimal
fn clone(&self) -> CompactDecimal
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompactDecimal
impl Debug for CompactDecimal
Source§impl Display for CompactDecimal
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for CompactDecimal
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
Source§impl FromStr for CompactDecimal
impl FromStr for CompactDecimal
Source§impl PartialEq for CompactDecimal
impl PartialEq for CompactDecimal
Source§fn eq(&self, other: &CompactDecimal) -> bool
fn eq(&self, other: &CompactDecimal) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for CompactDecimal
Source§impl Writeable for CompactDecimal
Render the CompactDecimal in sampleValue syntax.
The letter c is used, rather than the deprecated e.
impl Writeable for CompactDecimal
Render the CompactDecimal in sampleValue syntax.
The letter c is used, rather than the deprecated e.
§Examples
assert_writeable_eq!(
CompactDecimal::from_str("+1.20c6").unwrap(),
"+1.20c6"
);
assert_writeable_eq!(CompactDecimal::from_str("+1729").unwrap(), "+1729");Source§fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
write_to_parts, and discards any
Part annotations.Source§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
Source§fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
S: PartsWrite + ?Sized,
fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
S: PartsWrite + ?Sized,
Part annotations to the given sink. Errors from the
sink are bubbled up. The default implementation delegates to write_to,
and doesn’t produce any Part annotations.