Partager via


NumberFormatterSettings.Usage(String) Method

Definition

Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall", etc.

[Android.Runtime.Register("usage", "(Ljava/lang/String;)Landroid/icu/number/NumberFormatterSettings;", "GetUsage_Ljava_lang_String_Handler", ApiSince=33)]
public virtual Java.Lang.Object? Usage (string? usage);
[<Android.Runtime.Register("usage", "(Ljava/lang/String;)Landroid/icu/number/NumberFormatterSettings;", "GetUsage_Ljava_lang_String_Handler", ApiSince=33)>]
abstract member Usage : string -> Java.Lang.Object
override this.Usage : string -> Java.Lang.Object

Parameters

usage
String

A usage parameter from the units resource.

Returns

The fluent chain

Attributes

Remarks

Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall", etc.)

When a usage is specified, the output unit will change depending on the Locale and the unit quantity. For example, formatting length measurements specified in meters:

NumberFormatter.with().usage("person").unit(MeasureUnit.METER).locale(new ULocale("en-US"))

<ul> <li> When formatting 0.25, the output will be "10 inches". <li> When formatting 1.50, the output will be "4 feet and 11 inches". </ul>

The input unit specified via unit() determines the type of measurement being formatted (e.g. "length" when the unit is "foot"). The usage requested will be looked for only within this category of measurement units.

The output unit can be found via FormattedNumber.getOutputUnit().

If the usage has multiple parts (e.g. "land-agriculture-grain") and does not match a known usage preference, the last part will be dropped repeatedly until a match is found (e.g. trying "land-agriculture", then "land"). If a match is still not found, usage will fall back to "default".

Setting usage to an empty string clears the usage (disables usage-based localized formatting).

Setting a usage string but not a correct input unit will result in an U_ILLEGAL_ARGUMENT_ERROR.

When using usage, specifying rounding or precision is unnecessary. Specifying a precision in some manner will override the default formatting.

Java documentation for android.icu.number.NumberFormatterSettings.usage(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to