fixed_decimal

Crates.iofixed_decimal
lib.rsfixed_decimal
version0.7.0
created_at2020-10-15 15:25:20.264738+00
updated_at2025-02-26 18:18:09.328876+00
descriptionAn API for representing numbers in a human-readable form
homepage
repositoryhttps://github.com/unicode-org/icu4x
max_upload_size
id300032
size362,546
Manish Goregaokar (Manishearth)

documentation

README

fixed_decimal crates.io

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
);

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Commit count: 4409

cargo fmt