UnlocalizedNumberFormatter and LocalizedNumberFormatter. This class is not intended
for public subclassing.
NumberFormatter
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| private final NumberFormatterSettings | |
| private volatile MacroProps | |
| private final Object |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract T | |
| public T | Returns: The fluent chainThe decimal separator display strategy to use when rendering numbers. styleSets the decimal separator display strategy. |
| public T | Returns: The fluent chain.Specifies the |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. |
| public T | Returns: The fluent chain.The grouping strategy to use. strategySpecifies the grouping strategy to use when formatting numbers. |
| public int | |
| public T | Returns: The fluent chain.The integer width to use. style)Specifies the minimum and maximum number of digits to render before the decimal mark. |
| public T | macros(MacroProps macros)
Deprecated
ICU 60 This API is ICU internal only.
Internal method to set a starting macros.
|
| public T | |
| public T | |
| public T | Returns: The fluent chainThe unit to render in the denominator. perUnit)Sets a unit to be used in the denominator. |
| public T | |
| pack-priv MacroProps | |
| public T | Returns: The fluent chain.The rounding mode to use. roundingMode)Specifies how to determine the direction to round a number when it has more digits than fit in the desired precision. |
| public T | |
| public T | Returns: The fluent chainThe sign display strategy to use when rendering numbers. styleSets the plus/minus sign display strategy. |
| public T | Returns: The fluent chain.The DecimalFormatSymbols to use. symbols)Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering numbers. |
| public T | Returns: The fluent chain.The NumberingSystem to use. ns)Specifies that the given numbering system should be used when fetching symbols. |
| public T | |
| public String | Returns: A number skeleton string with behavior corresponding to this number formatter.Creates a skeleton string representation of this number formatter. |
| public T | Returns: The fluent chain.The unit to render. unit)Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers. |
| public T | Returns: The fluent chain
Deprecated
This API is for technology preview only.
Specifies the desired case for a unit formatter's output (e.g.
accusative, dative, genitive).
|
| public T | Returns: The fluent chainThe width to use when rendering numbers. styleSets the width of the unit (measure unit or currency). |
| public T |
| key | back to summary |
|---|---|
| private final int key | |
| KEY_DECIMAL | back to summary |
|---|---|
| pack-priv static final int KEY_DECIMAL | |
| KEY_GROUPING | back to summary |
|---|---|
| pack-priv static final int KEY_GROUPING | |
| KEY_INTEGER | back to summary |
|---|---|
| pack-priv static final int KEY_INTEGER | |
| KEY_LOCALE | back to summary |
|---|---|
| pack-priv static final int KEY_LOCALE | |
| KEY_MACROS | back to summary |
|---|---|
| pack-priv static final int KEY_MACROS | |
| KEY_MAX | back to summary |
|---|---|
| pack-priv static final int KEY_MAX | |
| KEY_NOTATION | back to summary |
|---|---|
| pack-priv static final int KEY_NOTATION | |
| KEY_PADDER | back to summary |
|---|---|
| pack-priv static final int KEY_PADDER | |
| KEY_PER_UNIT | back to summary |
|---|---|
| pack-priv static final int KEY_PER_UNIT | |
| KEY_PRECISION | back to summary |
|---|---|
| pack-priv static final int KEY_PRECISION | |
| KEY_ROUNDING_MODE | back to summary |
|---|---|
| pack-priv static final int KEY_ROUNDING_MODE | |
| KEY_SCALE | back to summary |
|---|---|
| pack-priv static final int KEY_SCALE | |
| KEY_SIGN | back to summary |
|---|---|
| pack-priv static final int KEY_SIGN | |
| KEY_SYMBOLS | back to summary |
|---|---|
| pack-priv static final int KEY_SYMBOLS | |
| KEY_THRESHOLD | back to summary |
|---|---|
| pack-priv static final int KEY_THRESHOLD | |
| KEY_UNIT | back to summary |
|---|---|
| pack-priv static final int KEY_UNIT | |
| KEY_UNIT_DISPLAY_CASE | back to summary |
|---|---|
| pack-priv static final int KEY_UNIT_DISPLAY_CASE | |
| KEY_UNIT_WIDTH | back to summary |
|---|---|
| pack-priv static final int KEY_UNIT_WIDTH | |
| KEY_USAGE | back to summary |
|---|---|
| pack-priv static final int KEY_USAGE | |
| parent | back to summary |
|---|---|
| private final NumberFormatterSettings<?> parent | |
| resolvedMacros | back to summary |
|---|---|
| private volatile MacroProps resolvedMacros | |
| value | back to summary |
|---|---|
| private final Object value | |
| NumberFormatterSettings | back to summary |
|---|---|
| pack-priv NumberFormatterSettings(NumberFormatterSettings<?> parent, int key, Object value) | |
| create | back to summary |
|---|---|
| pack-priv abstract T create(int key, Object value) | |
| decimal | back to summary |
|---|---|
| public T decimal(NumberFormatter. Sets the decimal separator display strategy. This affects integer numbers with no fraction part. Most common values:
Pass an element from the NumberFormatter.with().decimal(DecimalSeparatorDisplay.ALWAYS) The default is AUTO decimal separator display.
| |
| displayOptions | back to summary |
|---|---|
| public T displayOptions(DisplayOptions displayOptions) Specifies the
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| grouping | back to summary |
|---|---|
| public T grouping(NumberFormatter. Specifies the grouping strategy to use when formatting numbers.
The exact grouping widths will be chosen based on the locale.
Pass this method an element from the NumberFormatter.with().grouping(GroupingStrategy.MIN2)The default is to perform grouping according to locale data; most locales, but not all locales, enable it by default.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| integerWidth | back to summary |
|---|---|
| public T integerWidth(IntegerWidth style) Specifies the minimum and maximum number of digits to render before the decimal mark.
Pass this method the return value of NumberFormatter.with().integerWidth(IntegerWidth.zeroFillTo(2))The default is to have one minimum integer digit.
| |
| macros | back to summary |
|---|---|
| public T macros(MacroProps macros)
Deprecated ICU 60 This API is ICU internal only. Internal method to set a starting macros.
| |
| notation | back to summary |
|---|---|
| public T notation(Notation notation) Specifies the notation style (simple, scientific, or compact) for rendering numbers.
All notation styles will be properly localized with locale data, and all notation styles are compatible with units, rounding strategies, and other number formatter settings.
Pass this method the return value of a NumberFormatter.with().notation(Notation.compactShort())The default is to use simple notation. | |
| padding | back to summary |
|---|---|
| public T padding(Padder padder)
Deprecated ICU 60 This API is ICU internal only. Set the padding strategy. May be added to ICU 61; see #13338.
| |
| perUnit | back to summary |
|---|---|
| public T perUnit(MeasureUnit perUnit) Sets a unit to be used in the denominator. For example, to format "3 m/s", pass METER to the unit and SECOND to the perUnit.
Pass this method any instance of NumberFormatter.with().unit(MeasureUnit.METER).perUnit(MeasureUnit.SECOND) The default is not to display any unit in the denominator.
If a per-unit is specified without a primary unit via
| |
| precision | back to summary |
|---|---|
| public T precision(Precision precision) Specifies the rounding precision to use when formatting numbers.
Pass this method the return value of one of the factory methods on NumberFormatter.with().precision(Precision.fixedFraction(2))
In most cases, the default rounding precision is to round to 6 fraction places; i.e.,
| |
| resolve | back to summary |
|---|---|
| pack-priv MacroProps resolve() | |
| roundingMode | back to summary |
|---|---|
| public T roundingMode(RoundingMode roundingMode) Specifies how to determine the direction to round a number when it has more digits than fit in the desired precision. When formatting 1.235:
| |
| scale | back to summary |
|---|---|
| public T scale(Scale scale) Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting. Most common values:
Pass an element from a NumberFormatter.with().scale(Scale.powerOfTen(2)) The default is to not apply any multiplier. | |
| sign | back to summary |
|---|---|
| public T sign(NumberFormatter. Sets the plus/minus sign display strategy. Most common values:
Pass an element from the NumberFormatter.with().sign(SignDisplay.ALWAYS) The default is AUTO sign display.
| |
| symbols | back to summary |
|---|---|
| public T symbols(DecimalFormatSymbols symbols) Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering numbers.
Pass this method an instance of
NumberFormatter.with().symbols(DecimalFormatSymbols.getInstance(new ULocale("de_CH")))
Note DecimalFormatSymbols automatically chooses the best numbering system based on the locale. In the examples above, the first three are using the Latin numbering system, and the fourth is using the Myanmar numbering system. Note The instance of DecimalFormatSymbols will be copied: changes made to the symbols object after passing it into the fluent chain will not be seen. Note Calling this method will override the NumberingSystem previously specified
in The default is to choose the symbols based on the locale specified in the fluent chain.
| |
| symbols | back to summary |
|---|---|
| public T symbols(NumberingSystem ns) Specifies that the given numbering system should be used when fetching symbols.
Pass this method an instance of NumberFormatter.with().symbols(NumberingSystem.LATIN) Note Calling this method will override the DecimalFormatSymbols previously
specified in The default is to choose the best numbering system for the locale.
| |
| threshold | back to summary |
|---|---|
| public T threshold(Long threshold)
Deprecated ICU 60 This API is ICU internal only. Internal fluent setter to support a custom regulation threshold. A threshold of 1 causes the data structures to be built right away. A threshold of 0 prevents the data structures from being built.
| |
| toSkeleton | back to summary |
|---|---|
| public String toSkeleton() Creates a skeleton string representation of this number formatter. A skeleton string is a locale-agnostic serialized form of a number formatter.
Not all options are capable of being represented in the skeleton string; for example, a
DecimalFormatSymbols object. If any such option is encountered, an
The returned skeleton is in normalized form, such that two number formatters with equivalent behavior should produce the same skeleton. For more information on number skeleton strings, see: https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html
| |
| unit | back to summary |
|---|---|
| public T unit(MeasureUnit unit) Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
Note The unit can also be specified by passing a 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 NumberFormatter.with().unit(MeasureUnit.METER)Currency:
NumberFormatter.with().unit(Currency.getInstance("USD"))
Percent:
NumberFormatter.with().unit(NoUnit.PERCENT)
See
The default is to render without units (equivalent to
If the input usage is correctly set the output unit will change
according to
| |
| unitDisplayCase | back to summary |
|---|---|
| public T unitDisplayCase(String unitDisplayCase)
Deprecated This API is for technology preview only. Specifies the desired case for a unit formatter's output (e.g. accusative, dative, genitive).
| |
| unitWidth | back to summary |
|---|---|
| public T unitWidth(NumberFormatter. Sets the width of the unit (measure unit or currency). Most common values:
Pass an element from the NumberFormatter.with().unitWidth(UnitWidth.FULL_NAME) The default is the SHORT width.
| |
| usage | back to summary |
|---|---|
| public T usage(String usage) Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall", etc.)
When a
NumberFormatter.with().usage("person").unit(MeasureUnit.METER).locale(new ULocale("en-US"))
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.
| |