# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Nested Classes | Methods | Inherited Methods

# NumberFormatter

`public final class NumberFormatter`
`extends Object` ``

java.lang.Object
↳ | android.icu.number.NumberFormatter

The main entrypoint to the localized number formatting library introduced in ICU 60. Basic usage examples:

     // 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 `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.

## Summary

### Nested classes
`enum` | `NumberFormatter.DecimalSeparatorDisplay` An enum declaring how to render the decimal separator.
`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).
`enum` | `NumberFormatter.SignDisplay` An enum declaring how to denote positive and negative numbers.
`enum` | `NumberFormatter.UnitWidth` An enum declaring how to render units, including currencies.

### Public methods
`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.
`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.
`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.

### Inherited methods
From class `java.lang.Object`
`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 timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Public methods

### with

    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.

### withLocale

    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.

### withLocale

    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.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*