Expand description
fixed_decimal is a utility crate of the ICU4X project.
This crate provides Decimal and UnsignedDecimal, essential APIs for representing numbers in a human-readable format.
These types are particularly useful for formatting and plural rule selection, and are optimized for operations on individual digits.
§Examples
use fixed_decimal::Decimal;
let mut dec = Decimal::from(250);
dec.multiply_pow10(-2);
assert_eq!("2.50", format!("{}", dec));
#[derive(Debug, PartialEq)]
struct MagnitudeAndDigit(i16, u8);
let digits: Vec<MagnitudeAndDigit> = dec
    .magnitude_range()
    .map(|m| MagnitudeAndDigit(m, dec.digit_at(m)))
    .collect();
assert_eq!(
    vec![
        MagnitudeAndDigit(-2, 0),
        MagnitudeAndDigit(-1, 5),
        MagnitudeAndDigit(0, 2)
    ],
    digits
);Structs§
- Compact
Decimal  - A struct containing a 
Decimalsignificand 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). - Fixed
Integer  - A 
FixedIntegeris aDecimalwith no fractional part. - Limit
Error  - The magnitude or number of digits exceeds the limit of the 
UnsignedDecimalorDecimal. - Scientific
Decimal  - A struct containing a 
Decimalsignificand together with an exponent, representing a number written in scientific notation, such as 1.729×10³. - Signed
 - The 
Signedstruct represents a numeric value with an associated sign. - Unsigned
Decimal  - A struct containing decimal digits with efficient iteration and manipulation by magnitude (power of 10).
 
Enums§
- Parse
Error  - An error involving FixedDecimal operations or conversion.
 - Rounding
Increment  - Increment used in a rounding operation.
 - Sign
 - A specification of the sign used when formatting a number.
 - Sign
Display  - Configuration for when to render the minus sign or plus sign.
 - Signed
Rounding Mode  - Mode used in a signed rounding operations.
 - Unsigned
Rounding Mode  - Mode used in a unsigned rounding operations.
 
Type Aliases§
- Decimal
 - A Type containing a 
UnsignedDecimaland aSignto represent a signed decimal number.