icu_decimal crates.io

icu_decimal offers localized decimal number formatting.

Currently, icu_decimal provides [FixedDecimalFormat], which renders basic decimal numbers in a locale-sensitive way.

Support for currencies, measurement units, and compact notation is planned. To track progress, follow this issue:

https://github.com/unicode-org/icu4x/issues/275

Examples

Format a number with Bengali digits

```rust use icu::decimal::FixedDecimalFormat; use icu::locid::Locale; use icu::locid::macros::langid; use writeable::Writeable;

let locale: Locale = langid!("bn").into(); let provider = icutestdata::getprovider(); let fdf = FixedDecimalFormat::try_new(locale, &provider, Default::default()) .expect("Data should load successfully");

let fixeddecimal = 1000007.into(); let formattedvalue = fdf.format(&fixeddecimal); let formattedstr = formattedvalue.writeableto_string();

asserteq!("১০,০০,০০৭", formattedstr); ```

Format a number with digits after the decimal separator

```rust use fixed_decimal::FixedDecimal; use icu::decimal::FixedDecimalFormat; use icu::locid::Locale; use writeable::Writeable;

let locale = Locale::und(); let provider = icuprovider::inv::InvariantDataProvider; let fdf = FixedDecimalFormat::trynew(locale, &provider, Default::default()) .expect("Data should load successfully");

let fixeddecimal = FixedDecimal::from(200050) .multipliedpow10(-2) .expect("Operation is fully in range");

asserteq!("2,000.50", fdf.format(&fixeddecimal).writeabletostring()); ```

More Information

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