Module icu::decimal[][src]

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 icu::locid::macros::langid;
use writeable::Writeable;

let locale: Locale = langid!("bn").into();
let provider = icu_testdata::get_provider();
let fdf = FixedDecimalFormat::try_new(locale, &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.writeable_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 locale = Locale::und();
let provider = icu_provider::inv::InvariantDataProvider;
let fdf = FixedDecimalFormat::try_new(locale, &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).writeable_to_string());

Modules

error

Error types for decimal formatting.

format

Lower-level types for decimal formatting.

options

Options for FixedDecimalFormat.

provider

Data provider struct definitions for this ICU4X component.

Structs

FixedDecimalFormat

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

FormattedFixedDecimal

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

Enums

FixedDecimalFormatError