public class CompactDecimalFormat extends DecimalFormat
IMPORTANT: 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 |
---|---|
static class |
CompactDecimalFormat.CompactStyle
Style parameter for CompactDecimalFormat.
|
DecimalFormat.PropertySetter
NumberFormat.Field, NumberFormat.NumberFormatFactory, NumberFormat.SimpleNumberFormatFactory
UFormat.SpanField
MINIMUM_GROUPING_DIGITS_AUTO, MINIMUM_GROUPING_DIGITS_MIN2, PAD_AFTER_PREFIX, PAD_AFTER_SUFFIX, PAD_BEFORE_PREFIX, PAD_BEFORE_SUFFIX
ACCOUNTINGCURRENCYSTYLE, CASHCURRENCYSTYLE, CURRENCYSTYLE, FRACTION_FIELD, INTEGER_FIELD, INTEGERSTYLE, ISOCURRENCYSTYLE, NUMBERSTYLE, PERCENTSTYLE, PLURALCURRENCYSTYLE, SCIENTIFICSTYLE, STANDARDCURRENCYSTYLE
Modifier and Type | Method and Description |
---|---|
static CompactDecimalFormat |
getInstance(Locale locale,
CompactDecimalFormat.CompactStyle style)
NOTE: New users are strongly encouraged to use
NumberFormatter instead of NumberFormat. |
static CompactDecimalFormat |
getInstance(ULocale locale,
CompactDecimalFormat.CompactStyle style)
NOTE: New users are strongly encouraged to use
NumberFormatter instead of NumberFormat. |
Number |
parse( |