Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class CompactDecimalFormat

extends DecimalFormat
Class Inheritance
Imports
java.text.ParsePosition, java.util.Locale, com.ibm.icu.impl.number.DecimalFormatProperties, com.ibm.icu.number.NumberFormatter, com.ibm.icu.util.CurrencyAmount, .ULocale

Formats numbers in compact (abbreviated) notation, like "1.2K" instead of "1200".

Important Note

New users are strongly encouraged to see if NumberFormatter fits their use case. Although not deprecated, this class, CompactDecimalFormat, is provided for backwards compatibility only.


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.

The "short" style is also capable of formatting currency amounts, such as "$1.2M" instead of "$1,200,000.00" (English) or "5,3 Mio. €" instead of "5.300.000,00 €" (German). Localized data concerning longer formats is not available yet in the Unicode CLDR. Because of this, attempting to format a currency amount using the "long" style will produce an UnsupportedOperationException.

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.

Author
markdavis
ICU Status
Stable since ICU 49.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
CompactDecimalFormat.CompactStyle

Style parameter for CompactDecimalFormat.

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.ibm.icu.text.DecimalFormat:
currencyParserexportedPropertiesformatterMINIMUM_GROUPING_DIGITS_AUTOMINIMUM_GROUPING_DIGITS_MIN2PAD_AFTER_PREFIXPAD_AFTER_SUFFIXPAD_BEFORE_PREFIXPAD_BEFORE_SUFFIXparserpropertiessymbols

Constructor Summary

AccessConstructor and Description
pack-priv
CompactDecimalFormat(ULocale
the desired locale
locale
,
CompactDecimalFormat.CompactStyle
the compact style
style
)

The public mechanism is CompactDecimalFormat.getInstance().

Method Summary

Modifier and TypeMethod and Description
public static CompactDecimalFormat
getInstance(ULocale
the desired locale
locale
,
CompactDecimalFormat.CompactStyle
the compact style
style
)

Note

New users are strongly encouraged to use NumberFormatter instead of NumberFormat.

public static CompactDecimalFormat
getInstance(Locale
the desired locale
locale
,
CompactDecimalFormat.CompactStyle
the compact style
style
)

Note

New users are strongly encouraged to use NumberFormatter instead of NumberFormat.

public Number
parse(String text, ParsePosition parsePosition)

Overrides com.ibm.icu.text.DecimalFormat.parse.

Parsing is currently unsupported, and throws an UnsupportedOperationException.
public CurrencyAmount
parseCurrency(CharSequence
the text to parse
text
,
ParsePosition
input-output position; on input, the position within text to match; must have 0 <= pos.getIndex() < text.length(); on output, the position after the last matched character. If the parse fails, the position in unchanged upon output.
parsePosition
)

Overrides com.ibm.icu.text.DecimalFormat.parseCurrency.

Parsing is currently unsupported, and throws an UnsupportedOperationException.
Inherited from com.ibm.icu.text.DecimalFormat:
applyLocalizedPatternapplyPatternareSignificantDigitsUsedcloneequalsfieldPositionHelperformatformatformatformatformatformatformatToCharacterIteratorgetCurrencygetCurrencyParsergetCurrencyPluralInfogetCurrencyUsagegetDecimalFormatSymbolsgetFixedDecimalgetFormatWidthgetGroupingSizegetMathContextgetMathContextICUgetMaximumFractionDigitsgetMaximumIntegerDigitsgetMaximumSignificantDigitsgetMinimumExponentDigitsgetMinimumFractionDigitsgetMinimumGroupingDigitsgetMinimumIntegerDigitsgetMinimumSignificantDigitsgetMultipliergetNegativePrefixgetNegativeSuffixgetPadCharactergetPadPositiongetParseMaxDigitsgetParsergetPositivePrefixgetPositiveSuffixgetRoundingIncrementgetRoundingModegetSecondaryGroupingSizehashCodeisDecimalPatternMatchRequiredisDecimalSeparatorAlwaysShownisExponentSignAlwaysShownisGroupingUsedisParseBigDecimalisParseCaseSensitiveisParseIntegerOnlyisParseNoExponentisParseStrictisScientificNotationisSignAlwaysShownrefreshFormattersetCurrencysetCurrencyPluralInfosetCurrencyUsagesetDecimalFormatSymbolssetDecimalPatternMatchRequiredsetDecimalSeparatorAlwaysShownsetExponentSignAlwaysShownsetFormatWidthsetGroupingSizesetGroupingUsedsetMathContextsetMathContextICUsetMaximumFractionDigitssetMaximumIntegerDigitssetMaximumSignificantDigitssetMinimumExponentDigitssetMinimumFractionDigitssetMinimumGroupingDigitssetMinimumIntegerDigitssetMinimumSignificantDigitssetMultipliersetNegativePrefixsetNegativeSuffixsetPadCharactersetPadPositionsetParseBigDecimalsetParseCaseSensitivesetParseIntegerOnlysetParseMaxDigitssetParseNoExponentsetParseStrictsetParseStrictModesetPositivePrefixsetPositiveSuffixsetPropertiessetPropertiesFromPatternsetRoundingIncrementsetRoundingIncrementsetRoundingIncrementsetRoundingModesetScientificNotationsetSecondaryGroupingSizesetSignAlwaysShownsetSignificantDigitsUsedtoLocalizedPatterntoNumberFormattertoPatterntoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.ibm.icu.text.DecimalFormat.serialVersionUID.

Constructor Detail

CompactDecimalFormatback to summary
pack-priv CompactDecimalFormat(ULocale locale, CompactDecimalFormat.CompactStyle style)

The public mechanism is CompactDecimalFormat.getInstance().

Parameters
locale:ULocale

the desired locale

style:CompactDecimalFormat.CompactStyle

the compact style

Method Detail

getInstanceback to summary
public static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)

Note

New users are strongly encouraged to use NumberFormatter instead of NumberFormat.


Creates 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

ICU Status
Stable since ICU 50.
getInstanceback to summary
public static CompactDecimalFormat getInstance(Locale locale, CompactDecimalFormat.CompactStyle style)

Note

New users are strongly encouraged to use NumberFormatter instead of NumberFormat.


Creates 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

ICU Status
Stable since ICU 50.
parseback to summary
public Number parse(String text, ParsePosition parsePosition)

Overrides com.ibm.icu.text.DecimalFormat.parse.

Parsing is currently unsupported, and throws an UnsupportedOperationException.

Annotations
@Override
ICU Status
Stable since ICU 49.
parseCurrencyback to summary
public CurrencyAmount parseCurrency(CharSequence text, ParsePosition parsePosition)

Overrides com.ibm.icu.text.DecimalFormat.parseCurrency.

Parsing is currently unsupported, and throws an UnsupportedOperationException.

Parameters
text:CharSequence

Doc from com.ibm.icu.text.NumberFormat.parseCurrency.

the text to parse

parsePosition:ParsePosition

Doc from com.ibm.icu.text.NumberFormat.parseCurrency.

input-output position; on input, the position within text to match; must have 0 <= pos.getIndex() < text.length(); on output, the position after the last matched character. If the parse fails, the position in unchanged upon output.

Returns:CurrencyAmount

Doc from com.ibm.icu.text.NumberFormat.parseCurrency.

a CurrencyAmount, or null upon failure

Annotations
@Override
ICU Status
Stable since ICU 49.
com.ibm.icu.text back to summary

public final Enum CompactDecimalFormat.CompactStyle

extends Enum<CompactDecimalFormat.CompactStyle>
Class Inheritance

Style parameter for CompactDecimalFormat.
ICU Status
Stable since ICU 50.

Field Summary

Modifier and TypeField and Description
public static final CompactDecimalFormat.CompactStyle
LONG

Longer version, like "1.2 trillion", if available.

public static final CompactDecimalFormat.CompactStyle
SHORT

Short version, like "1.2T"

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CompactDecimalFormat.CompactStyle
public static CompactDecimalFormat.CompactStyle[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LONGback to summary
public static final CompactDecimalFormat.CompactStyle LONG

Longer version, like "1.2 trillion", if available. May return same result as SHORT if not.

ICU Status
Stable since ICU 50.
SHORTback to summary
public static final CompactDecimalFormat.CompactStyle SHORT

Short version, like "1.2T"

ICU Status
Stable since ICU 50.

Constructor Detail

CompactStyleback to summary
private CompactStyle()

Method Detail

valueOfback to summary
public static CompactDecimalFormat.CompactStyle valueOf(String name)
valuesback to summary
public static CompactDecimalFormat.CompactStyle[] values()