Stay organized with collections
Save and categorize content based on your preferences.
UnitWidth
class UnitWidth
An enum declaring how to render units, including currencies. Example outputs when formatting 123 USD and 123 meters in en-CA:
- NARROW: "$123.00" and "123 m"
- SHORT: "US$ 123.00" and "123 m"
- FULL_NAME: "123.00 US dollars" and "123 meters"
- ISO_CODE: "USD 123.00" and undefined behavior
- HIDDEN: "123.00" and "123"
This enum is similar to android.icu.text.MeasureFormat.FormatWidth
.
Summary
Enum values |
Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan dollar in zh-TW.
|
Print the full name of the unit, without any abbreviations.
|
Format the number according to the specified unit, but do not display the unit.
|
Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
|
Print an abbreviated version of the unit name.
|
Print an abbreviated version of the unit name.
|
Use the alternate variant of the currency symbol; for example, "TL" for the Turkish lira (TRY).
|
Enum values
enum val FORMAL : NumberFormatter.UnitWidth
Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan dollar in zh-TW.
Behavior of this option with non-currency units is not defined at this time.
FULL_NAME
enum val FULL_NAME : NumberFormatter.UnitWidth
Print the full name of the unit, without any abbreviations.
In CLDR, this option corresponds to the default format for measure units and the "¤¤¤" placeholder for currencies.
HIDDEN
enum val HIDDEN : NumberFormatter.UnitWidth
Format the number according to the specified unit, but do not display the unit. For currencies, apply monetary symbols and formats as with SHORT, but omit the currency symbol. For measure units, the behavior is equivalent to not specifying the unit at all.
ISO_CODE
enum val ISO_CODE : NumberFormatter.UnitWidth
Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
Behavior of this option with non-currency units is not defined at this time.
In CLDR, this option corresponds to the "¤¤" placeholder for currencies.
NARROW
enum val NARROW : NumberFormatter.UnitWidth
Print an abbreviated version of the unit name. Similar to SHORT, but always use the shortest available abbreviation or symbol. This option can be used when the context hints at the identity of the unit. For more information on the difference between NARROW and SHORT, see SHORT.
In CLDR, this option corresponds to the "Narrow" format for measure units and the "¤¤¤¤¤" placeholder for currencies.
SHORT
enum val SHORT : NumberFormatter.UnitWidth
Print an abbreviated version of the unit name. Similar to NARROW, but use a slightly wider abbreviation or symbol when there may be ambiguity. This is the default behavior.
For example, in es-US, the SHORT form for Fahrenheit is "{0} °F", but the NARROW form is "{0}°", since Fahrenheit is the customary unit for temperature in that locale.
In CLDR, this option corresponds to the "Short" format for measure units and the "¤" placeholder for currencies.
VARIANT
enum val VARIANT : NumberFormatter.UnitWidth
Use the alternate variant of the currency symbol; for example, "TL" for the Turkish lira (TRY).
Behavior of this option with non-currency units is not defined at this time.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# NumberFormatter.UnitWidth\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nUnitWidth\n=========\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/icu/number/NumberFormatter.UnitWidth \"View this page in Java\") \n\n```\nclass UnitWidth\n```\n\n|---|---|---------------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||\n| ↳ | [kotlin.Enum](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-enum/index.html)\\\u003c[android.icu.number.NumberFormatter.UnitWidth](#)\\\u003e ||\n| | ↳ | [android.icu.number.NumberFormatter.UnitWidth](#) |\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [NumberFormatter.UnitWidth.FORMAL](#ENUM_VALUE:FORMAL), [NumberFormatter.UnitWidth.FULL_NAME](#ENUM_VALUE:FULL_NAME), [NumberFormatter.UnitWidth.HIDDEN](#ENUM_VALUE:HIDDEN), [NumberFormatter.UnitWidth.ISO_CODE](#ENUM_VALUE:ISO_CODE), [NumberFormatter.UnitWidth.NARROW](#ENUM_VALUE:NARROW), [NumberFormatter.UnitWidth.SHORT](#ENUM_VALUE:SHORT), [NumberFormatter.UnitWidth.VARIANT](#ENUM_VALUE:VARIANT) |--------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| | [NumberFormatter.UnitWidth.FORMAL](#ENUM_VALUE:FORMAL) | Use the formal variant of the currency symbol; for example, \"NT$\" for the New Taiwan dollar in zh-TW. | | [NumberFormatter.UnitWidth.FULL_NAME](#ENUM_VALUE:FULL_NAME) | Print the full name of the unit, without any abbreviations. | | [NumberFormatter.UnitWidth.HIDDEN](#ENUM_VALUE:HIDDEN) | Format the number according to the specified unit, but do not display the unit. | | [NumberFormatter.UnitWidth.ISO_CODE](#ENUM_VALUE:ISO_CODE) | Use the three-digit ISO XXX code in place of the symbol for displaying currencies. | | [NumberFormatter.UnitWidth.NARROW](#ENUM_VALUE:NARROW) | Print an abbreviated version of the unit name. | | [NumberFormatter.UnitWidth.SHORT](#ENUM_VALUE:SHORT) | Print an abbreviated version of the unit name. | | [NumberFormatter.UnitWidth.VARIANT](#ENUM_VALUE:VARIANT) | Use the alternate variant of the currency symbol; for example, \"TL\" for the Turkish lira (TRY). | |\n\nAn enum declaring how to render units, including currencies. Example outputs when formatting 123 USD and 123 meters in *en-CA*:\n\n- NARROW: \"$123.00\" and \"123 m\"\n- SHORT: \"US$ 123.00\" and \"123 m\"\n- FULL_NAME: \"123.00 US dollars\" and \"123 meters\"\n- ISO_CODE: \"USD 123.00\" and undefined behavior\n- HIDDEN: \"123.00\" and \"123\"\n\n\u003cbr /\u003e\n\nThis enum is similar to [android.icu.text.MeasureFormat.FormatWidth](../text/MeasureFormat.FormatWidth.html#).\n\nSummary\n-------\n\n| Enum values ||\n|------------------------------------------------------------------------------------------------------------------------------------|---|\n| [FORMAL](#ENUM_VALUE:FORMAL) Use the formal variant of the currency symbol; for example, \"NT$\" for the New Taiwan dollar in zh-TW. |\n| [FULL_NAME](#ENUM_VALUE:FULL_NAME) Print the full name of the unit, without any abbreviations. |\n| [HIDDEN](#ENUM_VALUE:HIDDEN) Format the number according to the specified unit, but do not display the unit. |\n| [ISO_CODE](#ENUM_VALUE:ISO_CODE) Use the three-digit ISO XXX code in place of the symbol for displaying currencies. |\n| [NARROW](#ENUM_VALUE:NARROW) Print an abbreviated version of the unit name. |\n| [SHORT](#ENUM_VALUE:SHORT) Print an abbreviated version of the unit name. |\n| [VARIANT](#ENUM_VALUE:VARIANT) Use the alternate variant of the currency symbol; for example, \"TL\" for the Turkish lira (TRY). |\n\nEnum values\n-----------\n\n### FORMAL\n\nAdded in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val FORMAL : NumberFormatter.UnitWidth\n```\n\nUse the formal variant of the currency symbol; for example, \"NT$\" for the New Taiwan dollar in zh-TW.\n\nBehavior of this option with non-currency units is not defined at this time. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter) \n\n### FULL_NAME\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val FULL_NAME : NumberFormatter.UnitWidth\n```\n\nPrint the full name of the unit, without any abbreviations.\n\nIn CLDR, this option corresponds to the default format for measure units and the \"¤¤¤\" placeholder for currencies. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter) \n\n### HIDDEN\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val HIDDEN : NumberFormatter.UnitWidth\n```\n\nFormat the number according to the specified unit, but do not display the unit. For currencies, apply monetary symbols and formats as with SHORT, but omit the currency symbol. For measure units, the behavior is equivalent to not specifying the unit at all. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter) \n\n### ISO_CODE\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val ISO_CODE : NumberFormatter.UnitWidth\n```\n\nUse the three-digit ISO XXX code in place of the symbol for displaying currencies.\n\nBehavior of this option with non-currency units is not defined at this time.\n\nIn CLDR, this option corresponds to the \"¤¤\" placeholder for currencies. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter) \n\n### NARROW\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val NARROW : NumberFormatter.UnitWidth\n```\n\nPrint an abbreviated version of the unit name. Similar to SHORT, but always use the shortest available abbreviation or symbol. This option can be used when the context hints at the identity of the unit. For more information on the difference between NARROW and SHORT, see SHORT.\n\nIn CLDR, this option corresponds to the \"Narrow\" format for measure units and the \"¤¤¤¤¤\" placeholder for currencies. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter) \n\n### SHORT\n\nAdded in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val SHORT : NumberFormatter.UnitWidth\n```\n\nPrint an abbreviated version of the unit name. Similar to NARROW, but use a slightly wider abbreviation or symbol when there may be ambiguity. This is the default behavior.\n\nFor example, in *es-US*, the SHORT form for Fahrenheit is \"{0} °F\", but the NARROW form is \"{0}°\", since Fahrenheit is the customary unit for temperature in that locale.\n\nIn CLDR, this option corresponds to the \"Short\" format for measure units and the \"¤\" placeholder for currencies. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter) \n\n### VARIANT\n\nAdded in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nenum val VARIANT : NumberFormatter.UnitWidth\n```\n\nUse the alternate variant of the currency symbol; for example, \"TL\" for the Turkish lira (TRY).\n\nBehavior of this option with non-currency units is not defined at this time. \n**See Also**\n\n- [android.icu.number.NumberFormatter](/reference/kotlin/android/icu/number/NumberFormatter)"]]