Top Description Inners Fields Constructors Methods
com.ibm.icu.number

public final Class NumberFormatter

extends Object
Class Inheritance
Imports
java.util.Locale, com.ibm.icu.impl.number.DecimalFormatProperties, com.ibm.icu.text.DecimalFormatSymbols, com.ibm.icu.util.ULocale

All-in-one formatter for localized numbers, currencies, and units. For a full list of options, see NumberFormatterSettings.
// Most basic usage:
NumberFormatter.withLocale(...).format(123).toString();  // 1,234 in en-US

// Custom notation, unit, and rounding strategy:
NumberFormatter.with()
    .notation(Notation.compactShort())
    .unit(Currency.getInstance("EUR"))
    .precision(Precision.maxDigits(2))
    .locale(...)
    .format(1234)
    .toString();  // €1.2K in en-US

// Create a formatter in a private static final field:
private static final LocalizedNumberFormatter formatter = NumberFormatter.withLocale(...)
    .unit(NoUnit.PERCENT)
    .precision(Precision.fixedFraction(3));
formatter.format(5.9831).toString();  // 5.983% in en-US

// Create a "template" in a private static final field but without setting a locale until the call site:
private static final UnlocalizedNumberFormatter template = NumberFormatter.with()
    .sign(SignDisplay.ALWAYS)
    .unitWidth(UnitWidth.FULL_NAME);
template.locale(...).format(new Measure(1234, MeasureUnit.METER)).toString();  // +1,234 meters in en-US

This API offers more features than com.ibm.icu.text.DecimalFormat and is geared toward new users of ICU.

NumberFormatter instances (i.e., LocalizedNumberFormatter and UnlocalizedNumberFormatter) are immutable and thread safe. This means that invoking a configuration method has no effect on the receiving instance; you must store and use the new number formatter instance it returns instead.

UnlocalizedNumberFormatter formatter = UnlocalizedNumberFormatter.with()
        .notation(Notation.scientific());
formatter.precision(Precision.maxFraction(2)); // does nothing!
formatter.locale(ULocale.ENGLISH).format(9.8765).toString(); // prints "9.8765E0", not "9.88E0"

This API is based on the fluent design pattern popularized by libraries such as Google's Guava. For extensive details on the design of this API, read the design doc.

Note

To format monetary/currency values, specify the currency in the `.unit()` function.

Author
Shane Carr
ICU Status
Stable since ICU 60.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
NumberFormatter.DecimalSeparatorDisplay

An enum declaring how to render the decimal separator.

public static enum
NumberFormatter.GroupingStrategy

An enum declaring the strategy for when and how to display grouping separators (i.e., the separator, often a comma or period, after every 2-3 powers of ten).

public static enum
NumberFormatter.RoundingPriority

An enum declaring how to resolve conflicts between maximum fraction digits and maximum significant digits.

public static enum
NumberFormatter.SignDisplay

An enum declaring how to denote positive and negative numbers.

public static enum
NumberFormatter.TrailingZeroDisplay

An enum declaring how to render trailing zeros.

public static enum
NumberFormatter.UnitWidth

An enum declaring how to render units, including currencies.

Field Summary

Modifier and TypeField and Description
private static final UnlocalizedNumberFormatter
pack-priv static final long
DEFAULT_THRESHOLD

Use a default threshold of 3.

Constructor Summary

AccessConstructor and Description
private
NumberFormatter()

Private constructor, not designed for instantiation.

Method Summary

Modifier and TypeMethod and Description
public static UnlocalizedNumberFormatter

Returns:

An UnlocalizedNumberFormatter, to be used for chaining.
forSkeleton
(String
The skeleton string off of which to base this NumberFormatter.
skeleton
)

Call this method at the beginning of a NumberFormatter fluent chain to create an instance based on a given number skeleton string.

public static UnlocalizedNumberFormatter
fromDecimalFormat(DecimalFormatProperties properties, DecimalFormatSymbols symbols, DecimalFormatProperties exportedProperties)

Deprecated ICU 60 This API is ICU internal only.

Note

In Java, since NumberPropertyMapper is package-private, this method is here so that it is accessible to tests.

public static UnlocalizedNumberFormatter

Returns:

An UnlocalizedNumberFormatter, to be used for chaining.
with
()

Call this method at the beginning of a NumberFormatter fluent chain in which the locale is not currently known at the call site.

public static LocalizedNumberFormatter

Returns:

A LocalizedNumberFormatter, to be used for chaining.
withLocale
(Locale
The locale from which to load formats and symbols for number formatting.
locale
)

Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at the call site.

public static LocalizedNumberFormatter

Returns:

A LocalizedNumberFormatter, to be used for chaining.
withLocale
(ULocale
The locale from which to load formats and symbols for number formatting.
locale
)

Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at the call site.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BASEback to summary
private static final UnlocalizedNumberFormatter BASE
DEFAULT_THRESHOLDback to summary
pack-priv static final long DEFAULT_THRESHOLD

Use a default threshold of 3. This means that the third time .format() is called, the data structures get built using the "safe" code path. The first two calls to .format() will trigger the unsafe code path.

Constructor Detail

NumberFormatterback to summary
private NumberFormatter()

Private constructor, not designed for instantiation.

Method Detail

forSkeletonback to summary
public static UnlocalizedNumberFormatter forSkeleton(String skeleton)

Call this method at the beginning of a NumberFormatter fluent chain to create an instance based on a given number skeleton string. For more information on number skeleton strings, see: https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html

Parameters
skeleton:String

The skeleton string off of which to base this NumberFormatter.

Returns:UnlocalizedNumberFormatter

An UnlocalizedNumberFormatter, to be used for chaining.

Exceptions
SkeletonSyntaxException:
If the given string is not a valid number formatting skeleton.
ICU Status
Stable since ICU 62.
fromDecimalFormatback to summary
public static UnlocalizedNumberFormatter fromDecimalFormat(DecimalFormatProperties properties, DecimalFormatSymbols symbols, DecimalFormatProperties exportedProperties)

Deprecated

ICU 60 This API is ICU internal only.

Note

In Java, since NumberPropertyMapper is package-private, this method is here so that it is accessible to tests.

Annotations
@Deprecated
ICU Status
Internal ICU component.
withback to summary
public static UnlocalizedNumberFormatter with()

Call this method at the beginning of a NumberFormatter fluent chain in which the locale is not currently known at the call site.

Returns:UnlocalizedNumberFormatter

An UnlocalizedNumberFormatter, to be used for chaining.

ICU Status
Stable since ICU 60.
withLocaleback to summary
public static LocalizedNumberFormatter withLocale(Locale locale)

Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at the call site.

Parameters
locale:Locale

The locale from which to load formats and symbols for number formatting.

Returns:LocalizedNumberFormatter

A LocalizedNumberFormatter, to be used for chaining.

ICU Status
Stable since ICU 60.
withLocaleback to summary
public static LocalizedNumberFormatter withLocale(ULocale locale)

Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at the call site.

Parameters
locale:ULocale

The locale from which to load formats and symbols for number formatting.

Returns:LocalizedNumberFormatter

A LocalizedNumberFormatter, to be used for chaining.

ICU Status
Stable since ICU 60.
com.ibm.icu.number back to summary

public final Enum NumberFormatter.DecimalSeparatorDisplay

extends Enum<NumberFormatter.DecimalSeparatorDisplay>
Class Inheritance

An enum declaring how to render the decimal separator. Example outputs when formatting 1 and 1.1 in en-US:
ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberFormatter.DecimalSeparatorDisplay
ALWAYS

Always show the decimal separator, even if there are no digits to display after the separator.

public static final NumberFormatter.DecimalSeparatorDisplay
AUTO

Show the decimal separator when there are one or more digits to display after the separator, and do not show it otherwise.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberFormatter.DecimalSeparatorDisplay
public static NumberFormatter.DecimalSeparatorDisplay[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALWAYSback to summary
public static final NumberFormatter.DecimalSeparatorDisplay ALWAYS

Always show the decimal separator, even if there are no digits to display after the separator.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
AUTOback to summary
public static final NumberFormatter.DecimalSeparatorDisplay AUTO

Show the decimal separator when there are one or more digits to display after the separator, and do not show it otherwise. This is the default behavior.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Constructor Detail

DecimalSeparatorDisplayback to summary
private DecimalSeparatorDisplay()

Method Detail

valueOfback to summary
public static NumberFormatter.DecimalSeparatorDisplay valueOf(String name)
valuesback to summary
public static NumberFormatter.DecimalSeparatorDisplay[] values()
com.ibm.icu.number back to summary

public final Enum NumberFormatter.GroupingStrategy

extends Enum<NumberFormatter.GroupingStrategy>
Class Inheritance

An enum declaring the strategy for when and how to display grouping separators (i.e., the separator, often a comma or period, after every 2-3 powers of ten). The choices are several pre-built strategies for different use cases that employ locale data whenever possible. Example outputs for 1234 and 1234567 in en-IN:

The default is AUTO, which displays grouping separators unless the locale data says that grouping is not customary. To force grouping for all numbers greater than 1000 consistently across locales, use ON_ALIGNED. On the other hand, to display grouping less frequently than the default, use MIN2 or OFF. See the docs of each option for details.

Note

This enum specifies the strategy for grouping sizes. To set which character to use as the grouping separator, use the "symbols" setter.

ICU Status
Stable since ICU 61.
See Also
NumberFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberFormatter.GroupingStrategy
AUTO

Display grouping using the default strategy for all locales.

public static final NumberFormatter.GroupingStrategy
MIN2

Display grouping using locale defaults, except do not show grouping on values smaller than 10000 (such that there is a minimum of two digits before the first separator).

public static final NumberFormatter.GroupingStrategy
OFF

Do not display grouping separators in any locale.

public static final NumberFormatter.GroupingStrategy
ON_ALIGNED

Always display the grouping separator on values of at least 1000.

public static final NumberFormatter.GroupingStrategy
THOUSANDS

Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberFormatter.GroupingStrategy
public static NumberFormatter.GroupingStrategy[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTOback to summary
public static final NumberFormatter.GroupingStrategy AUTO

Display grouping using the default strategy for all locales. This is the default behavior.

Note that locales may restrict grouping separators to be displayed only on 1 million or greater (for example, ee and hu) or disable grouping altogether (for example, bg currency).

Locale data is used to determine whether to separate larger numbers into groups of 2 (customary in South Asia) or groups of 3 (customary in Europe and the Americas).

ICU Status
Stable since ICU 61.
See Also
NumberFormatter
MIN2back to summary
public static final NumberFormatter.GroupingStrategy MIN2

Display grouping using locale defaults, except do not show grouping on values smaller than 10000 (such that there is a minimum of two digits before the first separator).

Note that locales may restrict grouping separators to be displayed only on 1 million or greater (for example, ee and hu) or disable grouping altogether (for example, bg currency).

Locale data is used to determine whether to separate larger numbers into groups of 2 (customary in South Asia) or groups of 3 (customary in Europe and the Americas).

ICU Status
Stable since ICU 61.
See Also
NumberFormatter
OFFback to summary
public static final NumberFormatter.GroupingStrategy OFF

Do not display grouping separators in any locale.

ICU Status
Stable since ICU 61.
See Also
NumberFormatter
ON_ALIGNEDback to summary
public static final NumberFormatter.GroupingStrategy ON_ALIGNED

Always display the grouping separator on values of at least 1000.

This option ignores the locale data that restricts or disables grouping, described in MIN2 and AUTO. This option may be useful to normalize the alignment of numbers, such as in a spreadsheet.

Locale data is used to determine whether to separate larger numbers into groups of 2 (customary in South Asia) or groups of 3 (customary in Europe and the Americas).

ICU Status
Stable since ICU 61.
See Also
NumberFormatter
THOUSANDSback to summary
public static final NumberFormatter.GroupingStrategy THOUSANDS

Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater. Do not use locale data for determining the grouping strategy.

ICU Status
Stable since ICU 61.
See Also
NumberFormatter

Constructor Detail

GroupingStrategyback to summary
private GroupingStrategy()

Method Detail

valueOfback to summary
public static NumberFormatter.GroupingStrategy valueOf(String name)
valuesback to summary
public static NumberFormatter.GroupingStrategy[] values()
com.ibm.icu.number back to summary

public final Enum NumberFormatter.RoundingPriority

extends Enum<NumberFormatter.RoundingPriority>
Class Inheritance

An enum declaring how to resolve conflicts between maximum fraction digits and maximum significant digits.

There are two modes, RELAXED and STRICT:

The default settings for compact notation rounding are Max-Fraction = 0 (round to the nearest integer), Max-Significant = 2 (round to 2 significant digits), and priority RELAXED (choose the constraint that results in more digits being displayed).

Conflicting minimum fraction and significant digits are always resolved in the direction that results in more trailing zeros.

Example 1: Consider the number 3.141, with various different settings:

The rounding priority determines how to resolve the conflict when both Max-Fraction and Max-Significant are set. With RELAXED, the less-strict setting (the one that causes more digits to be displayed) will be used; Max-Significant wins. With STRICT, the more-strict setting (the one that causes fewer digits to be displayed) will be used; Max-Fraction wins.

Example 2: Consider the number 8317, with various different settings:

Here, RELAXED favors Max-Fraction and STRICT favors Max-Significant. Note that this larger number caused the two modes to favor the opposite result.

ICU Status
Stable since ICU 69.

Field Summary

Modifier and TypeField and Description
public static final NumberFormatter.RoundingPriority
RELAXED

Favor greater precision by relaxing one of the rounding constraints.

public static final NumberFormatter.RoundingPriority
STRICT

Favor adherence to all rounding constraints by producing lower precision.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberFormatter.RoundingPriority
public static NumberFormatter.RoundingPriority[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

RELAXEDback to summary
public static final NumberFormatter.RoundingPriority RELAXED

Favor greater precision by relaxing one of the rounding constraints.

ICU Status
Stable since ICU 69.
STRICTback to summary
public static final NumberFormatter.RoundingPriority STRICT

Favor adherence to all rounding constraints by producing lower precision.

ICU Status
Stable since ICU 69.

Constructor Detail

RoundingPriorityback to summary
private RoundingPriority()

Method Detail

valueOfback to summary
public static NumberFormatter.RoundingPriority valueOf(String name)
valuesback to summary
public static NumberFormatter.RoundingPriority[] values()
com.ibm.icu.number back to summary

public final Enum NumberFormatter.SignDisplay

extends Enum<NumberFormatter.SignDisplay>
Class Inheritance

An enum declaring how to denote positive and negative numbers. Example outputs when formatting 123, 0, and -123 in en-US:

The exact format, including the position and the code point of the sign, differ by locale.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberFormatter.SignDisplay
ACCOUNTING

Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive numbers.

public static final NumberFormatter.SignDisplay
ACCOUNTING_ALWAYS

Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive numbers, including zero.

public static final NumberFormatter.SignDisplay
ACCOUNTING_EXCEPT_ZERO

Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive numbers.

public static final NumberFormatter.SignDisplay
ACCOUNTING_NEGATIVE

Same as ACCOUNTING, but do not show the sign on negative zero.

public static final NumberFormatter.SignDisplay
ALWAYS

Show the minus sign on negative numbers and the plus sign on positive numbers, including zero.

public static final NumberFormatter.SignDisplay
AUTO

Show the minus sign on negative numbers, and do not show the sign on positive numbers.

public static final NumberFormatter.SignDisplay
EXCEPT_ZERO

Show the minus sign on negative numbers and the plus sign on positive numbers.

public static final NumberFormatter.SignDisplay
NEGATIVE

Same as AUTO, but do not show the sign on negative zero.

public static final NumberFormatter.SignDisplay
NEVER

Do not show the sign on positive or negative numbers.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberFormatter.SignDisplay
public static NumberFormatter.SignDisplay[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ACCOUNTINGback to summary
public static final NumberFormatter.SignDisplay ACCOUNTING

Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive numbers.

The accounting format is defined in CLDR and varies by locale; in many Western locales, the format is a pair of parentheses around the number.

Note

Since CLDR defines the accounting format in the monetary context only, this option falls back to the AUTO sign display strategy when formatting without a currency unit. This limitation may be lifted in the future.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
ACCOUNTING_ALWAYSback to summary
public static final NumberFormatter.SignDisplay ACCOUNTING_ALWAYS

Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive numbers, including zero. For more information on the accounting format, see the ACCOUNTING sign display strategy. To hide the sign on zero, see ACCOUNTING_EXCEPT_ZERO.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
ACCOUNTING_EXCEPT_ZEROback to summary
public static final NumberFormatter.SignDisplay ACCOUNTING_EXCEPT_ZERO

Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive numbers. Do not show a sign on zero, numbers that round to zero, or NaN. For more information on the accounting format, see the ACCOUNTING sign display strategy.

ICU Status
Stable since ICU 61.
See Also
NumberFormatter
ACCOUNTING_NEGATIVEback to summary
public static final NumberFormatter.SignDisplay ACCOUNTING_NEGATIVE

Same as ACCOUNTING, but do not show the sign on negative zero.

ICU Status
Stable since ICU 69.
ALWAYSback to summary
public static final NumberFormatter.SignDisplay ALWAYS

Show the minus sign on negative numbers and the plus sign on positive numbers, including zero. To hide the sign on zero, see EXCEPT_ZERO.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
AUTOback to summary
public static final NumberFormatter.SignDisplay AUTO

Show the minus sign on negative numbers, and do not show the sign on positive numbers. This is the default behavior. If using this option, a sign will be displayed on negative zero, including negative numbers that round to zero. To hide the sign on negative zero, use the NEGATIVE option.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
EXCEPT_ZEROback to summary
public static final NumberFormatter.SignDisplay EXCEPT_ZERO

Show the minus sign on negative numbers and the plus sign on positive numbers. Do not show a sign on zero, numbers that round to zero, or NaN.

ICU Status
Stable since ICU 61.
See Also
NumberFormatter
NEGATIVEback to summary
public static final NumberFormatter.SignDisplay NEGATIVE

Same as AUTO, but do not show the sign on negative zero.

ICU Status
Stable since ICU 69.
NEVERback to summary
public static final NumberFormatter.SignDisplay NEVER

Do not show the sign on positive or negative numbers.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Constructor Detail

SignDisplayback to summary
private SignDisplay()

Method Detail

valueOfback to summary
public static NumberFormatter.SignDisplay valueOf(String name)
valuesback to summary
public static NumberFormatter.SignDisplay[] values()
com.ibm.icu.number back to summary

public final Enum NumberFormatter.TrailingZeroDisplay

extends Enum<NumberFormatter.TrailingZeroDisplay>
Class Inheritance

An enum declaring how to render trailing zeros.
ICU Status
Stable since ICU 69.

Field Summary

Modifier and TypeField and Description
public static final NumberFormatter.TrailingZeroDisplay
AUTO

Display trailing zeros according to the settings for minimum fraction and significant digits.

public static final NumberFormatter.TrailingZeroDisplay
HIDE_IF_WHOLE

Same as AUTO, but hide trailing zeros after the decimal separator if they are all zero.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberFormatter.TrailingZeroDisplay
public static NumberFormatter.TrailingZeroDisplay[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTOback to summary
public static final NumberFormatter.TrailingZeroDisplay AUTO

Display trailing zeros according to the settings for minimum fraction and significant digits.

ICU Status
Stable since ICU 69.
HIDE_IF_WHOLEback to summary
public static final NumberFormatter.TrailingZeroDisplay HIDE_IF_WHOLE

Same as AUTO, but hide trailing zeros after the decimal separator if they are all zero.

ICU Status
Stable since ICU 69.

Constructor Detail

TrailingZeroDisplayback to summary
private TrailingZeroDisplay()

Method Detail

valueOfback to summary
public static NumberFormatter.TrailingZeroDisplay valueOf(String name)
valuesback to summary
public static NumberFormatter.TrailingZeroDisplay[] values()
com.ibm.icu.number back to summary

public final Enum NumberFormatter.UnitWidth

extends Enum<NumberFormatter.UnitWidth>
Class Inheritance

An enum declaring how to render units, including currencies. Example outputs when formatting 123 USD and 123 meters in en-CA:

This enum is similar to com.ibm.icu.text.MeasureFormat.FormatWidth.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberFormatter.UnitWidth
FORMAL

Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan dollar in zh-TW.

public static final NumberFormatter.UnitWidth
FULL_NAME

Print the full name of the unit, without any abbreviations.

public static final NumberFormatter.UnitWidth
HIDDEN

Format the number according to the specified unit, but do not display the unit.

public static final NumberFormatter.UnitWidth
ISO_CODE

Use the three-digit ISO XXX code in place of the symbol for displaying currencies.

public static final NumberFormatter.UnitWidth
NARROW

Print an abbreviated version of the unit name.

public static final NumberFormatter.UnitWidth
SHORT

Print an abbreviated version of the unit name.

public static final NumberFormatter.UnitWidth
VARIANT

Use the alternate variant of the currency symbol; for example, "TL" for the Turkish lira (TRY).

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberFormatter.UnitWidth
public static NumberFormatter.UnitWidth[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FORMALback to summary
public static final NumberFormatter.UnitWidth FORMAL

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.

ICU Status
Stable since ICU 67.
See Also
NumberFormatter
FULL_NAMEback to summary
public static final NumberFormatter.UnitWidth FULL_NAME

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.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
HIDDENback to summary
public static final NumberFormatter.UnitWidth HIDDEN

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.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
ISO_CODEback to summary
public static final NumberFormatter.UnitWidth ISO_CODE

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.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
NARROWback to summary
public static final NumberFormatter.UnitWidth NARROW

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.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
SHORTback to summary
public static final NumberFormatter.UnitWidth SHORT

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.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter
VARIANTback to summary
public static final NumberFormatter.UnitWidth VARIANT

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.

ICU Status
Stable since ICU 67.
See Also
NumberFormatter

Constructor Detail

UnitWidthback to summary
private UnitWidth()

Method Detail

valueOfback to summary
public static NumberFormatter.UnitWidth valueOf(String name)
valuesback to summary
public static NumberFormatter.UnitWidth[] values()