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

public abstract Class NumberFormatterSettings<T extends com.ibm.icu.number.NumberFormatterSettings<?>>

extends Object
Class Inheritance
Known Direct Subclasses
com.ibm.icu.number.UnlocalizedNumberFormatter, com.ibm.icu.number.LocalizedNumberFormatter
Imports
java.math.RoundingMode, com.ibm.icu.impl.number.MacroProps, .Padder, com.ibm.icu.number.NumberFormatter.DecimalSeparatorDisplay, .NumberFormatter.GroupingStrategy, .NumberFormatter.SignDisplay, .NumberFormatter.UnitWidth, com.ibm.icu.text.DecimalFormatSymbols, .DisplayOptions, .DisplayOptions.GrammaticalCase, .NumberingSystem, com.ibm.icu.util.Currency, .Measure, .MeasureUnit, .NoUnit, .ULocale

An abstract base class for specifying settings related to number formatting. This class is implemented by UnlocalizedNumberFormatter and LocalizedNumberFormatter. This class is not intended for public subclassing.
ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Field Summary

Modifier and TypeField 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

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract T
create(int key, Object value)

public T

Returns:

The fluent chain
decimal
(NumberFormatter.DecimalSeparatorDisplay
The decimal separator display strategy to use when rendering numbers.
style
)

Sets the decimal separator display strategy.

public T

Returns:

The fluent chain.
displayOptions
(DisplayOptions displayOptions)

Specifies the DisplayOptions.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public T

Returns:

The fluent chain.
grouping
(NumberFormatter.GroupingStrategy
The grouping strategy to use.
strategy
)

Specifies the grouping strategy to use when formatting numbers.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public T

Returns:

The fluent chain.
integerWidth
(IntegerWidth
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

Returns:

The fluent chain.
notation
(Notation
The notation strategy to use.
notation
)

Specifies the notation style (simple, scientific, or compact) for rendering numbers.

public T
padding(Padder padder)

Deprecated ICU 60 This API is ICU internal only.
Set the padding strategy.
public T

Returns:

The fluent chain
perUnit
(MeasureUnit
The unit to render in the denominator.
perUnit
)

Sets a unit to be used in the denominator.

public T

Returns:

The fluent chain.
precision
(Precision
The rounding precision to use.
precision
)

Specifies the rounding precision to use when formatting numbers.

pack-priv MacroProps
public T

Returns:

The fluent chain.
roundingMode
(RoundingMode
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

Returns:

The fluent chain
scale
(Scale
An amount to be multiplied against numbers before formatting.
scale
)

Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.

public T

Returns:

The fluent chain
sign
(NumberFormatter.SignDisplay
The sign display strategy to use when rendering numbers.
style
)

Sets the plus/minus sign display strategy.

public T

Returns:

The fluent chain.
symbols
(DecimalFormatSymbols
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.
symbols
(NumberingSystem
The NumberingSystem to use.
ns
)

Specifies that the given numbering system should be used when fetching symbols.

public T
threshold(Long threshold)

Deprecated ICU 60 This API is ICU internal only.
Internal fluent setter to support a custom regulation threshold.
public String

Returns:

A number skeleton string with behavior corresponding to this number formatter.
toSkeleton
()

Creates a skeleton string representation of this number formatter.

public T

Returns:

The fluent chain.
unit
(MeasureUnit
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
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).
public T

Returns:

The fluent chain
unitWidth
(NumberFormatter.UnitWidth
The width to use when rendering numbers.
style
)

Sets the width of the unit (measure unit or currency).

public T

Returns:

The fluent chain
usage
(String
A usage parameter from the units resource.
usage
)

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.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

keyback to summary
private final int key
KEY_DECIMALback to summary
pack-priv static final int KEY_DECIMAL
KEY_GROUPINGback to summary
pack-priv static final int KEY_GROUPING
KEY_INTEGERback to summary
pack-priv static final int KEY_INTEGER
KEY_LOCALEback to summary
pack-priv static final int KEY_LOCALE
KEY_MACROSback to summary
pack-priv static final int KEY_MACROS
KEY_MAXback to summary
pack-priv static final int KEY_MAX
KEY_NOTATIONback to summary
pack-priv static final int KEY_NOTATION
KEY_PADDERback to summary
pack-priv static final int KEY_PADDER
KEY_PER_UNITback to summary
pack-priv static final int KEY_PER_UNIT
KEY_PRECISIONback to summary
pack-priv static final int KEY_PRECISION
KEY_ROUNDING_MODEback to summary
pack-priv static final int KEY_ROUNDING_MODE
KEY_SCALEback to summary
pack-priv static final int KEY_SCALE
KEY_SIGNback to summary
pack-priv static final int KEY_SIGN
KEY_SYMBOLSback to summary
pack-priv static final int KEY_SYMBOLS
KEY_THRESHOLDback to summary
pack-priv static final int KEY_THRESHOLD
KEY_UNITback to summary
pack-priv static final int KEY_UNIT
KEY_UNIT_DISPLAY_CASEback to summary
pack-priv static final int KEY_UNIT_DISPLAY_CASE
KEY_UNIT_WIDTHback to summary
pack-priv static final int KEY_UNIT_WIDTH
KEY_USAGEback to summary
pack-priv static final int KEY_USAGE
parentback to summary
private final NumberFormatterSettings<?> parent
resolvedMacrosback to summary
private volatile MacroProps resolvedMacros
valueback to summary
private final Object value

Constructor Detail

NumberFormatterSettingsback to summary
pack-priv NumberFormatterSettings(NumberFormatterSettings<?> parent, int key, Object value)

Method Detail

createback to summary
pack-priv abstract T create(int key, Object value)
decimalback to summary
public T decimal(NumberFormatter.DecimalSeparatorDisplay style)

Sets the decimal separator display strategy. This affects integer numbers with no fraction part. Most common values:

  • Auto: "1"
  • Always: "1."

Pass an element from the DecimalSeparatorDisplay enum to this setter. For example:

NumberFormatter.with().decimal(DecimalSeparatorDisplay.ALWAYS)

The default is AUTO decimal separator display.

Parameters
style:NumberFormatter.DecimalSeparatorDisplay

The decimal separator display strategy to use when rendering numbers.

Returns:T

The fluent chain

ICU Status
Stable since ICU 60.
See Also
DecimalSeparatorDisplay
displayOptionsback to summary
public T displayOptions(DisplayOptions displayOptions)

Specifies the DisplayOptions. For example, GrammaticalCase specifies the desired case for a unit formatter's output (e.g. accusative, dative, genitive).

Returns:T

The fluent chain.

ICU Status
Stable since ICU 72.
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

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.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
ICU Status
Stable since ICU 60.
groupingback to summary
public T grouping(NumberFormatter.GroupingStrategy strategy)

Specifies the grouping strategy to use when formatting numbers.

  • Default grouping: "12,300" and "1,230"
  • Grouping with at least 2 digits: "12,300" and "1230"
  • No grouping: "12300" and "1230"

The exact grouping widths will be chosen based on the locale.

Pass this method an element from the GroupingStrategy enum. For example:

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.
Parameters
strategy:NumberFormatter.GroupingStrategy

The grouping strategy to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 61.
See Also
GroupingStrategy
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
ICU Status
Stable since ICU 60.
integerWidthback to summary
public T integerWidth(IntegerWidth style)

Specifies the minimum and maximum number of digits to render before the decimal mark.

  • Zero minimum integer digits: ".08"
  • One minimum integer digit: "0.08"
  • Two minimum integer digits: "00.08"

Pass this method the return value of IntegerWidth#zeroFillTo(int). For example:

NumberFormatter.with().integerWidth(IntegerWidth.zeroFillTo(2))
The default is to have one minimum integer digit.
Parameters
style:IntegerWidth

The integer width to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 60.
See Also
IntegerWidth
macrosback to summary
public T macros(MacroProps macros)

Deprecated

ICU 60 This API is ICU internal only.

Internal method to set a starting macros.

Annotations
@Deprecated
ICU Status
Internal ICU component.
notationback to summary
public T notation(Notation notation)

Specifies the notation style (simple, scientific, or compact) for rendering numbers.

  • Simple notation: "12,300"
  • Scientific notation: "1.23E4"
  • Compact notation: "12K"

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 Notation factory method. For example:

NumberFormatter.with().notation(Notation.compactShort())
The default is to use simple notation.
Parameters
notation:Notation

The notation strategy to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 60.
See Also
Notation
paddingback 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.

Annotations
@Deprecated
ICU Status
Internal ICU component.
perUnitback 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 MeasureUnit. For example:

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 unit, the behavior is undefined.

Parameters
perUnit:MeasureUnit

The unit to render in the denominator.

Returns:T

The fluent chain

ICU Status
Stable since ICU 61.
See Also
unit
precisionback to summary
public T precision(Precision precision)

Specifies the rounding precision to use when formatting numbers.

  • Round to 3 decimal places: "3.142"
  • Round to 3 significant figures: "3.14"
  • Round to the closest nickel: "3.15"
  • Do not perform rounding: "3.1415926..."

Pass this method the return value of one of the factory methods on Precision. For example:

NumberFormatter.with().precision(Precision.fixedFraction(2))

In most cases, the default rounding precision is to round to 6 fraction places; i.e., Precision.maxFraction(6). The exceptions are if compact notation is being used, then the compact notation rounding precision is used (see Notation#compactShort for details), or if the unit is a currency, then standard currency rounding is used, which varies from currency to currency (see Precision#currency for details).

Parameters
precision:Precision

The rounding precision to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 62.
See Also
Precision
resolveback to summary
pack-priv MacroProps resolve()
roundingModeback 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:

  • Ceiling rounding mode with integer precision: "2"
  • Half-down rounding mode with 2 fixed fraction digits: "1.23"
  • Half-up rounding mode with 2 fixed fraction digits: "1.24"
The default is HALF_EVEN. For more information on rounding mode, see the ICU userguide here: https://unicode-org.github.io/icu/userguide/format_parse/numbers/rounding-modes
Parameters
roundingMode:RoundingMode

The rounding mode to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 62.
See Also
Precision
scaleback 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:

  • Multiply by 100: useful for percentages.
  • Multiply by an arbitrary value: useful for unit conversions.

Pass an element from a Scale factory method to this setter. For example:

NumberFormatter.with().scale(Scale.powerOfTen(2))

The default is to not apply any multiplier.

Parameters
scale:Scale

An amount to be multiplied against numbers before formatting.

Returns:T

The fluent chain

ICU Status
Stable since ICU 62.
See Also
Scale
signback to summary
public T sign(NumberFormatter.SignDisplay style)

Sets the plus/minus sign display strategy. Most common values:

  • Auto: "123", "-123"
  • Always: "+123", "-123"
  • Accounting: "$123", "($123)"

Pass an element from the SignDisplay enum to this setter. For example:

NumberFormatter.with().sign(SignDisplay.ALWAYS)

The default is AUTO sign display.

Parameters
style:NumberFormatter.SignDisplay

The sign display strategy to use when rendering numbers.

Returns:T

The fluent chain

ICU Status
Stable since ICU 60.
See Also
SignDisplay
symbolsback to summary
public T symbols(DecimalFormatSymbols symbols)

Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering numbers.

  • en_US symbols: "12,345.67"
  • fr_FR symbols: "12 345,67"
  • de_CH symbols: "12’345.67"
  • my_MY symbols: "၁၂,၃၄၅.၆၇"

Pass this method an instance of DecimalFormatSymbols. For example:

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 symbols(NumberingSystem).

The default is to choose the symbols based on the locale specified in the fluent chain.

Parameters
symbols:DecimalFormatSymbols

The DecimalFormatSymbols to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 60.
See Also
DecimalFormatSymbols
symbolsback to summary
public T symbols(NumberingSystem ns)

Specifies that the given numbering system should be used when fetching symbols.

  • Latin numbering system: "12,345"
  • Myanmar numbering system: "၁၂,၃၄၅"
  • Math Sans Bold numbering system: "𝟭𝟮,𝟯𝟰𝟱"

Pass this method an instance of NumberingSystem. For example, to force the locale to always use the Latin alphabet numbering system (ASCII digits):

NumberFormatter.with().symbols(NumberingSystem.LATIN)

Note

Calling this method will override the DecimalFormatSymbols previously specified in symbols(DecimalFormatSymbols).

The default is to choose the best numbering system for the locale.

Parameters
ns:NumberingSystem

The NumberingSystem to use.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 60.
See Also
NumberingSystem
thresholdback 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.

Annotations
@Deprecated
ICU Status
Internal ICU component.
toSkeletonback 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 UnsupportedOperationException is thrown.

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

Returns:String

A number skeleton string with behavior corresponding to this number formatter.

Exceptions
UnsupportedOperationException:
If the number formatter has an option that cannot be represented in a skeleton string.
ICU Status
Stable since ICU 62.
unitback to summary
public T unit(MeasureUnit unit)

Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.

  • Unit of measure: "12.3 meters"
  • Currency: "$12.30"
  • Percent: "12.3%"

Note

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"))
Percent:
NumberFormatter.with().unit(NoUnit.PERCENT)

See perUnit for information on how to format strings like "5 meters per second".

The default is to render without units (equivalent to NoUnit#BASE).

If the input usage is correctly set the output unit will change according to usage, locale and unit value.

Parameters
unit:MeasureUnit

The unit to render.

Returns:T

The fluent chain.

ICU Status
Stable since ICU 60.
See Also
MeasureUnit, Currency, NoUnit, perUnit
unitDisplayCaseback 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).

Returns:T

The fluent chain

Annotations
@Deprecated
ICU Status
Internal ICU component: 69 technology preview
unitWidthback to summary
public T unitWidth(NumberFormatter.UnitWidth style)

Sets the width of the unit (measure unit or currency). Most common values:

  • Short: "$12.00", "12 m"
  • ISO Code: "USD 12.00"
  • Full name: "12.00 US dollars", "12 meters"

Pass an element from the UnitWidth enum to this setter. For example:

NumberFormatter.with().unitWidth(UnitWidth.FULL_NAME)

The default is the SHORT width.

Parameters
style:NumberFormatter.UnitWidth

The width to use when rendering numbers.

Returns:T

The fluent chain

ICU Status
Stable since ICU 60.
See Also
UnitWidth
usageback to summary
public T usage(String usage)

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"))
  • When formatting 0.25, the output will be "10 inches".
  • When formatting 1.50, the output will be "4 feet and 11 inches".

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.

Parameters
usage:String

A usage parameter from the units resource.

Returns:T

The fluent chain

Exceptions
IllegalArgumentException:
in case of Setting a usage string but not a correct input unit.
ICU Status
Stable since ICU 68.