Module icu::decimal

source · []
Expand description

Decimal formatting operations

This API provides necessary functionality for formatting of numbers with decimal digits.

FixedDecimalFormat is the main structure of the component. It formats a FixedDecimal to a FormattedFixedDecimal.

Examples

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)
    .multiplied_pow10(-2)
    .expect("Operation is fully in range");

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

Modules

Error types for decimal formatting.

Lower-level types for decimal formatting.

Data provider struct definitions for this ICU4X component.

Structs

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

An intermediate structure returned by FixedDecimalFormat. Use Writeable to render the formatted decimal to a string or buffer.

Enums