Struct leptos_use::UseIntlNumberFormatOptions
source · pub struct UseIntlNumberFormatOptions { /* private fields */ }
Expand description
Options for use_intl_number_format
.
Implementations§
source§impl UseIntlNumberFormatOptions
impl UseIntlNumberFormatOptions
sourcepub fn locales(self, value: Vec<String>) -> Self
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.
sourcepub fn compact_display(self, value: CompactDisplay) -> Self
pub fn compact_display(self, value: CompactDisplay) -> Self
Only used when UseIntlNumberFormatOptions::notation
is Compact
. Takes either Short
(default) or Long
.
sourcepub fn currency<OptionInnerType>(
self,
value: impl Into<Option<OptionInnerType>>
) -> Self
pub fn currency<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>> ) -> Self
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](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=currency-codes.
There is no default value; if the style is Currency
, the currency property must be provided.
sourcepub fn currency_display(self, value: CurrencyDisplay) -> Self
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"
.
sourcepub fn currency_sign(self, value: CurrencySign) -> Self
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
.
sourcepub fn locale_matcher(self, value: LocaleMatcher) -> Self
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.
sourcepub fn notation(self, value: Notation) -> Self
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; SeeUseIntlNumberFormatOptions::compact_display
.
sourcepub fn numbering_system<OptionInnerType>(
self,
value: impl Into<Option<OptionInnerType>>
) -> Self
pub fn numbering_system<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>> ) -> Self
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"
.
sourcepub fn sign_display(self, value: SignDisplay) -> Self
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. ExperimentalNever
: never display sign.
sourcepub fn style(self, value: NumberStyle) -> Self
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.
sourcepub fn unit<OptionInnerType>(
self,
value: impl Into<Option<OptionInnerType>>
) -> Self
pub fn unit<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>> ) -> Self
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.
sourcepub fn unit_display(self, value: UnitDisplay) -> Self
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
).
sourcepub fn use_grouping(self, value: NumberGrouping) -> Self
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.
sourcepub fn rounding_mode(self, value: RoundingMode) -> Self
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 likeCeil
(towards +∞), and below likeFloor
(towards -∞). On the half-increment, values round likeCeil
.HalfFloor
: ties toward -∞. Values above the half-increment round likeCeil
(towards +∞), and below likeFloor
(towards -∞). On the half-increment, values round likeFloor
.HalfExpand
: ties away from 0. Values above the half-increment round likeExpand
(away from zero), and below likeTrunc
(towards 0). On the half-increment, values round likeExpand
.HalfTrunc
: ties toward 0. Values above the half-increment round likeExpand
(away from zero), and below likeTrunc
(towards 0). On the half-increment, values round likeTrunc
.HalfEven
: ties towards the nearest even integer. Values above the half-increment round likeExpand
(away from zero), and below likeTrunc
(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.
sourcepub fn rounding_priority(self, value: RoundingPriority) -> Self
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).
sourcepub fn rounding_increment(self, value: u16) -> Self
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 thanAuto
.
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.
sourcepub fn trailing_zero_display(self, value: TrailingZeroDisplay) -> Self
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 tominimum_fraction_digits
andminimum_significant_digits
.StripIfInteger
: remove the fraction digits if they are all zero. This is the same asAuto
if any of the fraction digits is non-zero.
sourcepub fn minimum_integer_digits(self, value: u8) -> Self
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.
sourcepub fn minimum_fraction_digits<OptionInnerType>(
self,
value: impl Into<Option<OptionInnerType>>
) -> Self
pub fn minimum_fraction_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>> ) -> Self
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).
sourcepub fn maximum_fraction_digits<OptionInnerType>(
self,
value: impl Into<Option<OptionInnerType>>
) -> Self
pub fn maximum_fraction_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>> ) -> Self
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
.
sourcepub fn minimum_significant_digits<OptionInnerType>(
self,
value: impl Into<Option<OptionInnerType>>
) -> Self
pub fn minimum_significant_digits<OptionInnerType>( self, value: impl Into<Option<OptionInnerType>> ) -> Self
The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.
Trait Implementations§
source§impl Default for UseIntlNumberFormatOptions
impl Default for UseIntlNumberFormatOptions
source§impl From<UseIntlNumberFormatOptions> for Object
impl From<UseIntlNumberFormatOptions> for Object
source§fn from(options: UseIntlNumberFormatOptions) -> Self
fn from(options: UseIntlNumberFormatOptions) -> Self
Auto Trait Implementations§
impl Freeze for UseIntlNumberFormatOptions
impl RefUnwindSafe for UseIntlNumberFormatOptions
impl Send for UseIntlNumberFormatOptions
impl Sync for UseIntlNumberFormatOptions
impl Unpin for UseIntlNumberFormatOptions
impl UnwindSafe for UseIntlNumberFormatOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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