Struct fixed_decimal::CompactDecimal
source · pub struct CompactDecimal { /* private fields */ }
Expand description
A struct containing a FixedDecimal
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: FixedDecimal,
exponent: u8
) -> Self
pub fn from_significand_and_exponent( significand: FixedDecimal, exponent: u8 ) -> Self
Constructs a CompactDecimal
from its significand and exponent.
sourcepub fn significand(&self) -> &FixedDecimal
pub fn significand(&self) -> &FixedDecimal
Returns a reference to the significand of self
.
assert_eq!(
CompactDecimal::from_str("+1.20c6").unwrap().significand(),
&FixedDecimal::from_str("+1.20").unwrap()
);
sourcepub fn into_significand(self) -> FixedDecimal
pub fn into_significand(self) -> FixedDecimal
Returns the significand of self
.
assert_eq!(
CompactDecimal::from_str("+1.20c6")
.unwrap()
.into_significand(),
FixedDecimal::from_str("+1.20").unwrap()
);
Trait Implementations§
source§impl Clone for CompactDecimal
impl Clone for CompactDecimal
source§fn clone(&self) -> CompactDecimal
fn clone(&self) -> CompactDecimal
1.0.0 · 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
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 ==
.source§impl TryFrom<&[u8]> for CompactDecimal
impl TryFrom<&[u8]> for CompactDecimal
The deprecated letter e is not accepted as a synonym for c.
source§impl Writeable for CompactDecimal
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.