Most visited

Recently visited

Added in API level 24

CompactDecimalFormat

public class CompactDecimalFormat
extends DecimalFormat

java.lang.Object
   ↳ java.text.Format
     ↳ android.icu.text.UFormat
       ↳ android.icu.text.NumberFormat
         ↳ android.icu.text.DecimalFormat
           ↳ android.icu.text.CompactDecimalFormat


The CompactDecimalFormat produces abbreviated numbers, suitable for display in environments will limited real estate. For example, 'Hits: 1.2B' instead of 'Hits: 1,200,000,000'. The format will be appropriate for the given language, such as "1,2 Mrd." for German.

For numbers under 1000 trillion (under 10^15, such as 123,456,789,012,345), the result will be short for supported languages. However, the result may sometimes exceed 7 characters, such as when there are combining marks or thin characters. In such cases, the visual width in fonts should still be short.

By default, there are 2 significant digits. After creation, if more than three significant digits are set (with setMaximumSignificantDigits), or if a fixed number of digits are set (with setMaximumIntegerDigits or setMaximumFractionDigits), then result may be wider.

At this time, negative numbers and parsing are not supported, and will produce an UnsupportedOperationException. Resetting the pattern prefixes or suffixes is not supported; the method calls are ignored.

Note that important methods, like setting the number of decimals, will be moved up from DecimalFormat to NumberFormat.

Summary

Nested classes

enum CompactDecimalFormat.CompactStyle

Style parameter for CompactDecimalFormat. 

Inherited constants

From class android.icu.text.DecimalFormat
From class android.icu.text.NumberFormat

Public methods

boolean equals(Object obj)

Overrides equals.

StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)

Formats a BigDecimal number.

StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)

Formats a BigInteger number.

StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)

Specialization of format.

StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)

Specialization of format.

StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)

Formats a BigDecimal number.

AttributedCharacterIterator formatToCharacterIterator(Object obj)

Formats the object to an attributed string, and return the corresponding iterator.

static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)

Create a CompactDecimalFormat appropriate for a locale.

static CompactDecimalFormat getInstance(Locale locale, CompactDecimalFormat.CompactStyle style)

Create a CompactDecimalFormat appropriate for a locale.

Number parse(String text, ParsePosition parsePosition)

Parsing is currently unsupported, and throws an UnsupportedOperationException.

Inherited methods

From class android.icu.text.DecimalFormat
From class android.icu.text.NumberFormat
From class java.text.Format
From class java.lang.Object

Public methods

equals

Added in API level 24
boolean equals (Object obj)

Overrides equals.

Parameters
obj Object: the object to compare against
Returns
boolean true if the object is equal to this.

format

Added in API level 24
StringBuffer format (BigDecimal number, 
                StringBuffer toAppendTo, 
                FieldPosition pos)

Formats a BigDecimal number.

Parameters
number BigDecimal
toAppendTo StringBuffer
pos FieldPosition
Returns
StringBuffer

format

Added in API level 24
StringBuffer format (BigInteger number, 
                StringBuffer toAppendTo, 
                FieldPosition pos)

Formats a BigInteger number.

Parameters
number BigInteger
toAppendTo StringBuffer
pos FieldPosition
Returns
StringBuffer

format

Added in API level 24
StringBuffer format (double number, 
                StringBuffer toAppendTo, 
                FieldPosition pos)

Specialization of format.

Parameters
number double
toAppendTo StringBuffer
pos FieldPosition
Returns
StringBuffer

format

Added in API level 24
StringBuffer format (long number, 
                StringBuffer toAppendTo, 
                FieldPosition pos)

Specialization of format.

Parameters
number long
toAppendTo StringBuffer
pos FieldPosition
Returns
StringBuffer

format

Added in API level 24
StringBuffer format (BigDecimal number, 
                StringBuffer toAppendTo, 
                FieldPosition pos)

Formats a BigDecimal number.

Parameters
number BigDecimal
toAppendTo StringBuffer
pos FieldPosition
Returns
StringBuffer

formatToCharacterIterator

Added in API level 24
AttributedCharacterIterator formatToCharacterIterator (Object obj)

Formats the object to an attributed string, and return the corresponding iterator.

Parameters
obj Object: The object to format
Returns
AttributedCharacterIterator AttributedCharacterIterator describing the formatted value.

getInstance

Added in API level 24
CompactDecimalFormat getInstance (ULocale locale, 
                CompactDecimalFormat.CompactStyle style)

Create a CompactDecimalFormat appropriate for a locale. The result may be affected by the number system in the locale, such as ar-u-nu-latn.

Parameters
locale ULocale: the desired locale
style CompactDecimalFormat.CompactStyle: the compact style
Returns
CompactDecimalFormat

getInstance

Added in API level 24
CompactDecimalFormat getInstance (Locale locale, 
                CompactDecimalFormat.CompactStyle style)

Create a CompactDecimalFormat appropriate for a locale. The result may be affected by the number system in the locale, such as ar-u-nu-latn.

Parameters
locale Locale: the desired locale
style CompactDecimalFormat.CompactStyle: the compact style
Returns
CompactDecimalFormat

parse

Added in API level 24
Number parse (String text, 
                ParsePosition parsePosition)

Parsing is currently unsupported, and throws an UnsupportedOperationException.

Parameters
text String: the string to be parsed
parsePosition ParsePosition: defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position has not changed upon return, then parsing failed.
Returns
Number a Number object with the parsed value or null if the parse failed

Hooray!