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.
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.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | CompactDecimalFormat.CompactStyle
Style parameter for CompactDecimalFormat. |
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv | CompactDecimalFormat(ULocale
the desired locale locale, CompactDecimalFormat.the compact style styleThe public mechanism is CompactDecimalFormat.getInstance(). |
| Modifier and Type | Method and Description |
|---|---|
| public static CompactDecimalFormat | getInstance(ULocale
the desired locale locale, CompactDecimalFormat.the compact style styleNote New users are strongly encouraged to use
|
| public static CompactDecimalFormat | getInstance(Locale
the desired locale locale, CompactDecimalFormat.the compact style styleNote New users are strongly encouraged to use
|
| public Number | parse(String text, ParsePosition parsePosition)
Overrides com. |
| 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. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| CompactDecimalFormat | back to summary |
|---|---|
| pack-priv CompactDecimalFormat(ULocale locale, CompactDecimalFormat. The public mechanism is CompactDecimalFormat.getInstance().
| |
| getInstance | back to summary |
|---|---|
| public static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat. Note New users are strongly encouraged to use
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.
| |
| getInstance | back to summary |
|---|---|
| public static CompactDecimalFormat getInstance(Locale locale, CompactDecimalFormat. Note New users are strongly encouraged to use
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.
| |
| parse | back to summary |
|---|---|
| public Number parse(String text, ParsePosition parsePosition) Overrides com. Parsing is currently unsupported, and throws an UnsupportedOperationException. | |
| parseCurrency | back to summary |
|---|---|
| public CurrencyAmount parseCurrency(CharSequence text, ParsePosition parsePosition) Overrides com. Parsing is currently unsupported, and throws an UnsupportedOperationException.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final CompactDecimalFormat. | LONG
Longer version, like "1.2 trillion", if available. |
| public static final CompactDecimalFormat. | SHORT
Short version, like "1.2T" |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static CompactDecimalFormat. | |
| public static CompactDecimalFormat. |
| LONG | back to summary |
|---|---|
| public static final CompactDecimalFormat. Longer version, like "1.2 trillion", if available. May return same result as SHORT if not.
| |
| SHORT | back to summary |
|---|---|
| public static final CompactDecimalFormat. Short version, like "1.2T"
| |
| CompactStyle | back to summary |
|---|---|
| private CompactStyle() | |
| valueOf | back to summary |
|---|---|
| public static CompactDecimalFormat. | |
| values | back to summary |
|---|---|
| public static CompactDecimalFormat. | |