Crate fixed_decimal

source ·
Expand description

fixed_decimal is a utility crate of the ICU4X project.

This crate provides SignedFixedDecimal and UnsignedFixedDecimal, 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::SignedFixedDecimal;

let mut dec = SignedFixedDecimal::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
);

Re-exports§

Structs§

Enums§

  • Specifies the precision of a floating point value when constructing a FixedDecimal.
  • An error involving FixedDecimal operations or conversion.
  • Increment used in a rounding operation.
  • This module defines variations of numeric types, including signed values, values with infinity, and values with NaN. A specification of the sign used when formatting a number.
  • Configuration for when to render the minus sign or plus sign.
  • Mode used in a signed rounding operations.
  • Mode used in a unsigned rounding operations.

Type Aliases§