NumberFormatterSettings.Unit(MeasureUnit) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
[Android.Runtime.Register("unit", "(Landroid/icu/util/MeasureUnit;)Landroid/icu/number/NumberFormatterSettings;", "GetUnit_Landroid_icu_util_MeasureUnit_Handler", ApiSince=30)]
public virtual Java.Lang.Object? Unit (Android.Icu.Util.MeasureUnit? unit);
[<Android.Runtime.Register("unit", "(Landroid/icu/util/MeasureUnit;)Landroid/icu/number/NumberFormatterSettings;", "GetUnit_Landroid_icu_util_MeasureUnit_Handler", ApiSince=30)>]
abstract member Unit : Android.Icu.Util.MeasureUnit -> Java.Lang.Object
override this.Unit : Android.Icu.Util.MeasureUnit -> Java.Lang.Object
Parameters
- unit
- MeasureUnit
The unit to render.
Returns
The fluent chain.
- Attributes
Remarks
Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
<ul> <li>Unit of measure: "12.3 meters" <li>Currency: "$12.30" <li>Percent: "12.3%" </ul>
<strong>Note:</strong> The unit can also be specified by passing a Measure
to LocalizedNumberFormatter#format(Measure)
. Units specified via the format method take precedence over units specified here. This setter is designed for situations when the unit is constant for the duration of the number formatting process.
All units will be properly localized with locale data, and all units are compatible with notation styles, rounding strategies, and other number formatter settings.
Pass this method any instance of MeasureUnit
. For units of measure:
NumberFormatter.with().unit(MeasureUnit.METER)
Currency:
NumberFormatter.with().unit(Currency.getInstance("USD"))
See #perUnit
for information on how to format strings like "5 meters per second".
If the input usage is correctly set the output unit <b>will change</b> according to usage
, locale
and unit
value.
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.