Type Alias Decimal

Source
pub type Decimal = Signed<UnsignedDecimal>;
Expand description

A Type containing a UnsignedDecimal and a Sign to represent a signed decimal number.

Supports a mantissa of non-zero digits and a number of leading and trailing zeros, as well as an optional sign; used for formatting and plural selection.

§Data Types

The following types can be converted to a Decimal:

  • Integers, signed and unsigned
  • Strings representing an arbitrary-precision decimal
  • Floating point values (using the ryu feature)

To create a Decimal with fractional digits, you have several options:

  • Create it from an integer and then call UnsignedDecimal::multiply_pow10 (you can also call multiply_pow10 directly on the Decimal).
  • Create it from a string.
  • When the ryu feature is enabled, create it from a floating point value using [Decimal::try_from_f64].

§Examples

use fixed_decimal::Decimal;

let mut dec = Decimal::from(250);
assert_eq!("250", dec.to_string());

dec.multiply_pow10(-2);
assert_eq!("2.50", dec.to_string());

Aliased Type§

struct Decimal {
    pub sign: Sign,
    pub absolute: UnsignedDecimal,
}

Fields§

§sign: Sign§absolute: UnsignedDecimal