Struct leptos_use::UseIntlNumberFormatOptions

source ·
pub struct UseIntlNumberFormatOptions { /* private fields */ }
Expand description

Implementations§

source§

impl UseIntlNumberFormatOptions

source

pub fn locales(self, value: Vec<String>) -> Self

A vec of strings, each with a BCP 47 language tag. Please refer to the MDN Docs for more info.

source

pub fn compact_display(self, value: CompactDisplay) -> Self

Only used when UseIntlNumberFormatOptions::notation is Compact. Takes either Short (default) or Long.

source

pub fn currency<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<String>,

The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as “USD” for the US dollar, “EUR” for the euro, or “CNY” for the Chinese RMB — see the Current currency & funds code list. There is no default value; if the style is Currency, the currency property must be provided.

source

pub fn currency_display(self, value: CurrencyDisplay) -> Self

How to display the currency in currency formatting. The default is Symbol.

  • Symbol: use a localized currency symbol such as €.
  • NarrowSymbol: use a narrow format symbol (“$100” rather than “US$100”).
  • Code: use the ISO currency code.
  • Name: use a localized currency name such as "dollar".
source

pub fn currency_sign(self, value: CurrencySign) -> Self

In many locales, accounting format means to wrap the number with parentheses instead of appending a minus sign. You can enable this formatting by setting this option to Accounting. The default value is Standard.

source

pub fn locale_matcher(self, value: LocaleMatcher) -> Self

The locale matching algorithm to use. Possible values are Lookup and BestFit; the default is "BestFit". For information about this option, see the Intl page.

source

pub fn notation(self, value: Notation) -> Self

The formatting that should be displayed for the number. The default is "standard".

  • Standard: plain number formatting.
  • Scientific: order-of-magnitude for formatted number.
  • Engineering: exponent of ten when divisible by three.
  • Compact: string representing exponent; See UseIntlNumberFormatOptions::compact_display.
source

pub fn numbering_system<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<String>,

Numbering System. Possible values include: "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt".

source

pub fn sign_display(self, value: SignDisplay) -> Self

When to display the sign for the number. The default is Auto.

  • Auto: sign display for negative numbers only, including negative zero.
  • Always: always display sign.
  • ExceptZero: sign display for positive and negative numbers, but not zero.
  • Negative: sign display for negative numbers only, excluding negative zero. Experimental
  • Never: never display sign.
source

pub fn style(self, value: NumberStyle) -> Self

The formatting style to use. The default is Decimal.

  • Decimal for plain number formatting.
  • Currency for currency formatting.
  • Percent for percent formatting.
  • Unit for unit formatting.
source

pub fn unit<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<String>,

The unit to use in unit formatting, Possible values are core unit identifiers, defined in UTS #35, Part 2, Section 6. A subset of units from the full list was selected for use in ECMAScript. Pairs of simple units can be concatenated with “-per-” to make a compound unit. There is no default value; if the style is Unit, the unit property must be provided.

source

pub fn unit_display(self, value: UnitDisplay) -> Self

The unit formatting style to use in unit formatting. The default is Short.

  • Long (e.g., 16 litres).
  • Short (e.g., 16 l).
  • Narrow (e.g., 16l).
source

pub fn use_grouping(self, value: NumberGrouping) -> Self

Experimental. Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. The default is Auto.

  • Always: display grouping separators even if the locale prefers otherwise.
  • Auto: display grouping separators based on the locale preference, which may also be dependent on the currency.
  • None: do not display grouping separators.
  • Min2: display grouping separators when there are at least 2 digits in a group.
source

pub fn rounding_mode(self, value: RoundingMode) -> Self

Experimental. Options for rounding modes. The default is HalfExpand.

  • Ceil: round toward +∞. Positive values round up. Negative values round “more positive”.
  • Floor round toward -∞. Positive values round down. Negative values round “more negative”.
  • Expand: round away from 0. The magnitude of the value is always increased by rounding. Positive values round up. Negative values round “more negative”.
  • Trunc: round toward 0. This magnitude of the value is always reduced by rounding. Positive values round down. Negative values round “less negative”.
  • HalfCeil: ties toward +∞. Values above the half-increment round like Ceil (towards +∞), and below like Floor (towards -∞). On the half-increment, values round like Ceil.
  • HalfFloor: ties toward -∞. Values above the half-increment round like Ceil (towards +∞), and below like Floor (towards -∞). On the half-increment, values round like Floor.
  • HalfExpand: ties away from 0. Values above the half-increment round like Expand (away from zero), and below like Trunc (towards 0). On the half-increment, values round like Expand.
  • HalfTrunc: ties toward 0. Values above the half-increment round like Expand (away from zero), and below like Trunc (towards 0). On the half-increment, values round like Trunc.
  • HalfEven: ties towards the nearest even integer. Values above the half-increment round like Expand (away from zero), and below like Trunc (towards 0). On the half-increment values round towards the nearest even digit.

These options reflect the ICU user guide, where Expand and Trunc map to ICU “UP” and “DOWN”, respectively. The rounding modes example demonstrates how each mode works.

source

pub fn rounding_priority(self, value: RoundingPriority) -> Self

Experimental. Specify how rounding conflicts will be resolved if both “FractionDigits” (UseIntlNumberFormatOptions::minimum_fraction_digits/UseIntlNumberFormatOptions::maximum_fraction_digits) and “SignificantDigits” (UseIntlNumberFormatOptions::minimum_significant_digits/UseIntlNumberFormatOptions::maximum_significant_digits) are specified:

  • Auto: the result from the significant digits property is used (default).
  • MorePrecision: the result from the property that results in more precision is used.
  • LessPrecision: the result from the property that results in less precision is used.

Note that for values other than Auto the result with more precision is calculated from the UseIntlNumberFormatOptions::maximum_significant_digits and UseIntlNumberFormatOptions::maximum_fraction_digits (minimum fractional and significant digit settings are ignored).

source

pub fn rounding_increment(self, value: u16) -> Self

Experimental. Specifies the rounding-increment precision. Must be one of the following integers: 1 (default), 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000.

This option controls the rounding increment to be used when formatting numbers:

  • It indicates the increment at which rounding should take place relative to the calculated rounding magnitude.
  • It cannot be mixed with significant-digits rounding or any setting of rounding_priority other than Auto.

For example, if maximum_fraction_digits is 2 and rounding_increment is 5, then the number is rounded to the nearest 0.05 (“nickel rounding”).

let nf = use_intl_number_format(
    UseIntlNumberFormatOptions::default()
        .style(NumberStyle::Currency)
        .currency("USD")
        .maximum_fraction_digits(2)
        .rounding_increment(5),    
);

let formatted = nf.format(11.29); // "$11.30"
let formatted = nf.format(11.25); // "$11.25"
let formatted = nf.format(11.22); // "$11.20"

If you set minimum_fraction_digits and maximum_fraction_digits, they must set them to the same value; otherwise a RangeError is thrown.

source

pub fn trailing_zero_display(self, value: TrailingZeroDisplay) -> Self

Experimental. A string expressing the strategy for displaying trailing zeros on whole numbers. The default is "auto".

  • Auto: keep trailing zeros according to minimum_fraction_digits and minimum_significant_digits.
  • StripIfInteger: remove the fraction digits if they are all zero. This is the same as Auto if any of the fraction digits is non-zero.
source

pub fn minimum_integer_digits(self, value: u8) -> Self

These properties fall into two groups: minimum_integer_digits, minimum_fraction_digits, and maximum_fraction_digits in one group, minimum_significant_digits and maximum_significant_digits in the other. If properties from both groups are specified, conflicts in the resulting display format are resolved based on the value of the UseIntlNumberFormatOptions::rounding_priority property.

The minimum number of integer digits to use. A value with a smaller number of integer digits than this number will be left-padded with zeros (to the specified length) when formatted. Possible values are from 1 to 21; the default is 1.

source

pub fn minimum_fraction_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<u8>,

The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn’t provide that information).

source

pub fn maximum_fraction_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<u8>,

The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimum_fraction_digits and 3; the default for currency formatting is the larger of minimum_fraction_digits and the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn’t provide that information); the default for percent formatting is minimum_fraction_digits.

source

pub fn minimum_significant_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<u8>,

The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.

source

pub fn maximum_significant_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>>, ) -> Self
where OptionInnerType: Into<u8>,

The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.

source§

impl UseIntlNumberFormatOptions

source

pub fn locale(self, locale: &str) -> Self

A string with a BCP 47 language tag. Please refer to the MDN Docs for more info.

Trait Implementations§

source§

impl Default for UseIntlNumberFormatOptions

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<UseIntlNumberFormatOptions> for Object

source§

fn from(options: UseIntlNumberFormatOptions) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more