Expand description

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 icu4x#275.


Format a number with Bengali digits

use icu::decimal::FixedDecimalFormat;
use icu::locid::locale;
use writeable::Writeable;

let provider = icu_testdata::get_provider();
let fdf = FixedDecimalFormat::try_new(locale!("bn"), &provider, Default::default())
    .expect("Data should load successfully");

let fixed_decimal = 1000007.into();
let formatted_value = fdf.format(&fixed_decimal);
let formatted_str = formatted_value.write_to_string();

assert_eq!("১০,০০,০০৭", formatted_str);

Format a number with digits after the decimal separator

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

let provider = icu_provider::inv::InvariantDataProvider;
let fdf = FixedDecimalFormat::try_new(Locale::UND, &provider, Default::default())
    .expect("Data should load successfully");

let fixed_decimal = FixedDecimal::from(200050)
    .expect("Operation is fully in range");

assert_eq!("2,000.50", fdf.format(&fixed_decimal).write_to_string());


pub use error::Error as FixedDecimalFormatError;
pub use format::FormattedFixedDecimal;


Error types for decimal formatting.

Lower-level types for decimal formatting.

Data provider struct definitions for this ICU4X component.


A formatter for FixedDecimal, rendering decimal digits in an i18n-friendly way.