Struct fixed_decimal::decimal::FixedDecimal [−][src]
pub struct FixedDecimal { /* fields omitted */ }
A struct containing decimal digits with efficient iteration and manipulation by magnitude (power of 10). Supports a mantissa of non-zero digits and a number of leading and trailing zeros, used for formatting and plural selection.
You can create a FixedDecimal
from a standard integer type. To represent fraction digits,
call .multiply_pow10()
after creating your FixedDecimal
.
Examples
use fixed_decimal::FixedDecimal; let mut dec = FixedDecimal::from(250); assert_eq!("250", dec.to_string()); dec.multiply_pow10(-2); assert_eq!("2.50", dec.to_string());
Implementations
impl FixedDecimal
[src]
impl FixedDecimal
[src]pub fn digit_at(&self, magnitude: i16) -> u8
[src]
Gets the digit at the specified order of magnitude. Returns 0 if the magnitude is out of range of the currently visible digits.
Examples
use fixed_decimal::FixedDecimal; let dec = FixedDecimal::from(945); assert_eq!(0, dec.digit_at(-1)); assert_eq!(5, dec.digit_at(0)); assert_eq!(4, dec.digit_at(1)); assert_eq!(9, dec.digit_at(2)); assert_eq!(0, dec.digit_at(3));
pub const fn magnitude_range(&self) -> RangeInclusive<i16>
[src]
Gets the visible range of digit magnitudes, in ascending order of magnitude. Call .rev()
on the return value to get the range in descending order. Magnitude 0 is always included,
even if the number has leading or trailing zeros.
Examples
use fixed_decimal::FixedDecimal; let mut dec = FixedDecimal::from(120); assert_eq!(0..=2, dec.magnitude_range());
pub fn multiply_pow10(&mut self, delta: i16) -> Result<(), Error>
[src]
Shift the digits by a power of 10, modifying self.
Leading or trailing zeros may be added to keep the digit at magnitude 0 (the last digit before the decimal separator) visible.
Can fail if the change in magnitude pushes the digits out of bounds; the magnitudes of all digits should fit in an i16.
Examples
use fixed_decimal::FixedDecimal; let mut dec = FixedDecimal::from(42); assert_eq!("42", dec.to_string()); dec.multiply_pow10(3).expect("Bounds are small"); assert_eq!("42000", dec.to_string());
pub fn multiplied_pow10(self, delta: i16) -> Result<Self, Error>
[src]
Shift the digits by a power of 10, consuming self and returning a new object if successful.
Leading or trailing zeros may be added to keep the digit at magnitude 0 (the last digit before the decimal separator) visible.
Can fail if the change in magnitude pushes the digits out of bounds; the magnitudes of all digits should fit in an i16.
Examples
use fixed_decimal::FixedDecimal; let dec = FixedDecimal::from(42).multiplied_pow10(3).expect("Bounds are small"); assert_eq!("42000", dec.to_string());
pub fn negate(&mut self)
[src]
Change the value from negative to positive or from positive to negative, modifying self.
Examples
use fixed_decimal::FixedDecimal; let mut dec = FixedDecimal::from(42); assert_eq!("42", dec.to_string()); dec.negate(); assert_eq!("-42", dec.to_string()); dec.negate(); assert_eq!("42", dec.to_string());
pub fn negated(self) -> Self
[src]
Change the value from negative to positive or from positive to negative, consuming self and returning a new object.
Examples
use fixed_decimal::FixedDecimal; assert_eq!(FixedDecimal::from(-42), FixedDecimal::from(42).negated());
pub fn signum(&self) -> Signum
[src]
Returns the Signum of this FixedDecimal.
Examples
use fixed_decimal::FixedDecimal; use fixed_decimal::Signum; assert_eq!(Signum::AboveZero, FixedDecimal::from(42).signum()); assert_eq!(Signum::PositiveZero, FixedDecimal::from(0).signum()); assert_eq!(Signum::NegativeZero, FixedDecimal::from(0).negated().signum()); assert_eq!(Signum::BelowZero, FixedDecimal::from(-42).signum());
Trait Implementations
impl Clone for FixedDecimal
[src]
impl Clone for FixedDecimal
[src]fn clone(&self) -> FixedDecimal
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for FixedDecimal
[src]
impl Default for FixedDecimal
[src]impl Display for FixedDecimal
[src]
impl Display for FixedDecimal
[src]Renders the FixedDecimal
according to the syntax documented in FixedDecimal::write_to
.
impl FromStr for FixedDecimal
[src]
impl FromStr for FixedDecimal
[src]impl PartialEq<FixedDecimal> for FixedDecimal
[src]
impl PartialEq<FixedDecimal> for FixedDecimal
[src]fn eq(&self, other: &FixedDecimal) -> bool
[src]
fn ne(&self, other: &FixedDecimal) -> bool
[src]
impl StructuralPartialEq for FixedDecimal
[src]
impl StructuralPartialEq for FixedDecimal
[src]impl Writeable for FixedDecimal
[src]
impl Writeable for FixedDecimal
[src]fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
[src]
Render the FixedDecimal
as a string of ASCII digits with a possible decimal point.
Examples
use fixed_decimal::FixedDecimal; use writeable::Writeable; let dec = FixedDecimal::from(42); let mut result = String::with_capacity(dec.write_len().capacity()); dec.write_to(&mut result).expect("write_to(String) should not fail"); assert_eq!("42", result);
fn write_len(&self) -> LengthHint
[src]
The number of bytes that will be written by FixedDecimal::write_to
. Use this function to
pre-allocate capacity in the destination buffer.
Examples
use fixed_decimal::FixedDecimal; use writeable::Writeable; use writeable::LengthHint; let dec = FixedDecimal::from(-5000).multiplied_pow10(-2).expect("Bounds are small"); let result = dec.writeable_to_string(); assert_eq!(LengthHint::Exact(6), dec.write_len());
pub fn writeable_to_string(&self) -> String
[src]
Auto Trait Implementations
impl RefUnwindSafe for FixedDecimal
impl RefUnwindSafe for FixedDecimal
impl Send for FixedDecimal
impl Send for FixedDecimal
impl Sync for FixedDecimal
impl Sync for FixedDecimal
impl Unpin for FixedDecimal
impl Unpin for FixedDecimal
impl UnwindSafe for FixedDecimal
impl UnwindSafe for FixedDecimal