Added in API level 30

LocalizedNumberFormatter


public class LocalizedNumberFormatter
extends NumberFormatterSettings<LocalizedNumberFormatter>

java.lang.Object
   ↳ android.icu.number.NumberFormatterSettings<android.icu.number.LocalizedNumberFormatter>
     ↳ android.icu.number.LocalizedNumberFormatter


A NumberFormatter that has a locale associated with it; this means .format() methods are available. Instances of this class are immutable and thread-safe.

Summary

Public methods

FormattedNumber format(double input)

Format the given float or double to a string using the settings specified in the NumberFormatter fluent setting chain.

FormattedNumber format(Measure input)

Format the given Measure or CurrencyAmount to a string using the settings specified in the NumberFormatter fluent setting chain.

FormattedNumber format(long input)

Format the given byte, short, int, or long to a string using the settings specified in the NumberFormatter fluent setting chain.

FormattedNumber format(Number input)

Format the given BigInteger, BigDecimal, or other Number to a string using the settings specified in the NumberFormatter fluent setting chain.

Format toFormat()

Creates a representation of this LocalizedNumberFormat as a Format, enabling the use of this number formatter with APIs that need an object of that type, such as MessageFormat.

UnlocalizedNumberFormatter withoutLocale()

Disassociate the locale from this formatter.

Inherited methods

T decimal(NumberFormatter.DecimalSeparatorDisplay style)

Sets the decimal separator display strategy.

T displayOptions(DisplayOptions displayOptions)

Specifies the DisplayOptions.

boolean equals(Object other)

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

T grouping(NumberFormatter.GroupingStrategy strategy)

Specifies the grouping strategy to use when formatting numbers.

int hashCode()

Returns a hash code value for the object.

T integerWidth(IntegerWidth style)

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

T notation(Notation notation)

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

T perUnit(MeasureUnit perUnit)

Sets a unit to be used in the denominator.

T precision(Precision precision)

Specifies the rounding precision to use when formatting numbers.

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.

T scale(Scale scale)

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

T sign(NumberFormatter.SignDisplay style)

Sets the plus/minus sign display strategy.

T symbols(NumberingSystem ns)

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

T symbols(DecimalFormatSymbols symbols)

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

T unit(MeasureUnit unit)

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

T unitWidth(NumberFormatter.UnitWidth style)

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

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.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

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

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public methods

format

Added in API level 30
public FormattedNumber format (double input)

Format the given float or double to a string using the settings specified in the NumberFormatter fluent setting chain.

Parameters
input double: The number to format.

Returns
FormattedNumber A FormattedNumber object; call .toString() to get the string.

See also:

format

Added in API level 30
public FormattedNumber format (Measure input)

Format the given Measure or CurrencyAmount to a string using the settings specified in the NumberFormatter fluent setting chain.

The unit specified here overrides any unit that may have been specified in the setter chain. This method is intended for cases when each input to the number formatter has a different unit.

Parameters
input Measure: The number to format.

Returns
FormattedNumber A FormattedNumber object; call .toString() to get the string.

See also:

format

Added in API level 30
public FormattedNumber format (long input)

Format the given byte, short, int, or long to a string using the settings specified in the NumberFormatter fluent setting chain.

Parameters
input long: The number to format.

Returns
FormattedNumber A FormattedNumber object; call .toString() to get the string.

See also:

format

Added in API level 30
public FormattedNumber format (Number input)

Format the given BigInteger, BigDecimal, or other Number to a string using the settings specified in the NumberFormatter fluent setting chain.

Parameters
input Number: The number to format.

Returns
FormattedNumber A FormattedNumber object; call .toString() to get the string.

See also:

toFormat

Added in API level 30
public Format toFormat ()

Creates a representation of this LocalizedNumberFormat as a Format, enabling the use of this number formatter with APIs that need an object of that type, such as MessageFormat.

This API is not intended to be used other than for enabling API compatibility. The format(Measure) methods should normally be used when formatting numbers, not the Format object returned by this method.

Returns
Format A Format wrapping this LocalizedNumberFormatter.

See also:

withoutLocale

public UnlocalizedNumberFormatter withoutLocale ()

Disassociate the locale from this formatter.

Returns
UnlocalizedNumberFormatter The fluent chain.