Crate fixed_decimal

source ยท
Expand description

fixed_decimal is a utility crate of the ICU4X project.

It includes FixedDecimal, a core API for representing numbers in a human-readable form appropriate for formatting and plural rule selection. It is optimized for operations involving the individual digits of a number.

ยงExamples

use fixed_decimal::FixedDecimal;

let dec = FixedDecimal::from(250).multiplied_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ยง

Modulesยง

Structsยง

  • 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).
  • 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, as well as an optional sign; used for formatting and plural selection.
  • A FixedInteger is a FixedDecimal with no fractional part.
  • A struct containing a FixedDecimal significand together with an exponent, representing a number written in scientific notation, such as 1.729ร—10ยณ. This structure represents any 0s shown in the significand and exponent, and an optional sign for both the significand and the exponent.

Enumsยง

  • An error involving FixedDecimal operations or conversion.
  • Specifies the precision of a floating point value when constructing a FixedDecimal.
  • Increment used in a rounding operation.
  • A specification of the sign used when formatting a number.
  • Configuration for when to render the minus sign or plus sign.