7 releases (1 stable)

1.0.0 Sep 27, 2022
1.0.0-beta1 Aug 5, 2022
0.6.0 May 17, 2022
0.5.0 Jan 31, 2022
0.2.0 Apr 29, 2021

#19 in #cldr

Download history 2035/week @ 2022-08-13 1606/week @ 2022-08-20 1037/week @ 2022-08-27 2841/week @ 2022-09-03 2043/week @ 2022-09-10 2608/week @ 2022-09-17 2154/week @ 2022-09-24 1704/week @ 2022-10-01 1824/week @ 2022-10-08 1983/week @ 2022-10-15 2648/week @ 2022-10-22 2262/week @ 2022-10-29 2137/week @ 2022-11-05 2046/week @ 2022-11-12 1019/week @ 2022-11-19 1761/week @ 2022-11-26

7,381 downloads per month
Used in 10 crates (6 directly)

Unicode-DFS-2016

545KB
9K SLoC

icu_decimal crates.io

Formatting basic decimal numbers.

This module is published as its own crate (icu_decimal) and as part of the icu crate. See the latter for more details on the ICU4X project.

Support for currencies, measurement units, and compact notation is planned. To track progress, follow icu4x#275.

Examples

Format a number with Bengali digits

use icu::decimal::FixedDecimalFormatter;
use icu::locid::locale;
use writeable::assert_writeable_eq;

let fdf = FixedDecimalFormatter::try_new_unstable(
    &icu_testdata::unstable(),
    &locale!("bn").into(),
    Default::default(),
)
.expect("Data should load successfully");

let fixed_decimal = 1000007.into();

assert_writeable_eq!(fdf.format(&fixed_decimal), "১০,০০,০০৭");

Format a number with digits after the decimal separator

use fixed_decimal::FixedDecimal;
use icu::decimal::FixedDecimalFormatter;
use icu::locid::Locale;
use writeable::assert_writeable_eq;

let fdf = FixedDecimalFormatter::try_new_unstable(
    &icu_testdata::unstable(),
    &Locale::UND.into(),
    Default::default(),
)
.expect("Data should load successfully");

let fixed_decimal = FixedDecimal::from(200050).multiplied_pow10(-2);

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

Format a number using an alternative numbering system

Numbering systems specified in the -u-nu subtag will be followed as long as the locale has symbols for that numbering system.

use icu::decimal::FixedDecimalFormatter;
use icu::locid::locale;
use writeable::assert_writeable_eq;

let fdf = FixedDecimalFormatter::try_new_unstable(
    &icu_testdata::unstable(),
    &locale!("th-u-nu-thai").into(),
    Default::default(),
)
.expect("Data should load successfully");

let fixed_decimal = 1000007.into();

assert_writeable_eq!(fdf.format(&fixed_decimal), "๑,๐๐๐,๐๐๗");

More Information

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

Dependencies

~2.5MB
~33K SLoC