Class CompactDecimalFormat
- All Implemented Interfaces:
Serializable
,Cloneable
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.
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
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Style parameter for CompactDecimalFormat.Nested classes/interfaces inherited from class com.ibm.icu.text.DecimalFormat
DecimalFormat.PropertySetter
Nested classes/interfaces inherited from class com.ibm.icu.text.NumberFormat
NumberFormat.Field, NumberFormat.NumberFormatFactory, NumberFormat.SimpleNumberFormatFactory
Nested classes/interfaces inherited from class com.ibm.icu.text.UFormat
UFormat.SpanField
-
Field Summary
Fields inherited from class com.ibm.icu.text.DecimalFormat
MINIMUM_GROUPING_DIGITS_AUTO, MINIMUM_GROUPING_DIGITS_MIN2, PAD_AFTER_PREFIX, PAD_AFTER_SUFFIX, PAD_BEFORE_PREFIX, PAD_BEFORE_SUFFIX
Fields inherited from class com.ibm.icu.text.NumberFormat
ACCOUNTINGCURRENCYSTYLE, CASHCURRENCYSTYLE, CURRENCYSTYLE, FRACTION_FIELD, INTEGER_FIELD, INTEGERSTYLE, ISOCURRENCYSTYLE, NUMBERSTYLE, PERCENTSTYLE, PLURALCURRENCYSTYLE, SCIENTIFICSTYLE, STANDARDCURRENCYSTYLE
-
Method Summary
Modifier and TypeMethodDescriptionstatic CompactDecimalFormat
getInstance
(ULocale locale, CompactDecimalFormat.CompactStyle style) NOTE: New users are strongly encouraged to useNumberFormatter
instead of NumberFormat.static CompactDecimalFormat
getInstance
(Locale locale, CompactDecimalFormat.CompactStyle style) NOTE: New users are strongly encouraged to useNumberFormatter
instead of NumberFormat.parse
(String text, ParsePosition parsePosition) Parsing is currently unsupported, and throws an UnsupportedOperationException.parseCurrency
(CharSequence text, ParsePosition parsePosition) Parsing is currently unsupported, and throws an UnsupportedOperationException.Methods inherited from class com.ibm.icu.text.DecimalFormat
applyLocalizedPattern, applyPattern, areSignificantDigitsUsed, clone, equals, format, format, format, format, format, format, formatToCharacterIterator, getCurrency, getCurrencyPluralInfo, getCurrencyUsage, getDecimalFormatSymbols, getFixedDecimal, getFormatWidth, getGroupingSize, getMathContext, getMathContextICU, getMaximumFractionDigits, getMaximumIntegerDigits, getMaximumSignificantDigits, getMinimumExponentDigits, getMinimumFractionDigits, getMinimumGroupingDigits, getMinimumIntegerDigits, getMinimumSignificantDigits, getMultiplier, getNegativePrefix, getNegativeSuffix, getPadCharacter, getPadPosition, getParseMaxDigits, getPositivePrefix, getPositiveSuffix, getRoundingIncrement, getRoundingMode, getSecondaryGroupingSize, hashCode, isDecimalPatternMatchRequired, isDecimalSeparatorAlwaysShown, isExponentSignAlwaysShown, isGroupingUsed, isParseBigDecimal, isParseCaseSensitive, isParseIntegerOnly, isParseNoExponent, isParseStrict, isScientificNotation, isSignAlwaysShown, setCurrency, setCurrencyPluralInfo, setCurrencyUsage, setDecimalFormatSymbols, setDecimalPatternMatchRequired, setDecimalSeparatorAlwaysShown, setExponentSignAlwaysShown, setFormatWidth, setGroupingSize, setGroupingUsed, setMathContext, setMathContextICU, setMaximumFractionDigits, setMaximumIntegerDigits, setMaximumSignificantDigits, setMinimumExponentDigits, setMinimumFractionDigits, setMinimumGroupingDigits, setMinimumIntegerDigits, setMinimumSignificantDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setPadCharacter, setPadPosition, setParseBigDecimal, setParseCaseSensitive, setParseIntegerOnly, setParseMaxDigits, setParseNoExponent, setParseStrict, setParseStrictMode, setPositivePrefix, setPositiveSuffix, setProperties, setRoundingIncrement, setRoundingIncrement, setRoundingIncrement, setRoundingMode, setScientificNotation, setSecondaryGroupingSize, setSignAlwaysShown, setSignificantDigitsUsed, toLocalizedPattern, toNumberFormatter, toPattern, toString
Methods inherited from class com.ibm.icu.text.NumberFormat
format, format, format, format, format, format, format, getAvailableLocales, getAvailableULocales, getContext, getCurrencyInstance, getCurrencyInstance, getCurrencyInstance, getEffectiveCurrency, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getIntegerInstance, getNumberInstance, getNumberInstance, getNumberInstance, getPattern, getPattern, getPatternForStyle, getPatternForStyleAndNumberingSystem, getPercentInstance, getPercentInstance, getPercentInstance, getScientificInstance, getScientificInstance, getScientificInstance, parse, parseObject, registerFactory, setContext, unregister
Methods inherited from class java.text.Format
format, parseObject
-
Method Details
-
getInstance
public static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style) NOTE: New users are strongly encouraged to useNumberFormatter
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
- the desired localestyle
- the compact style
-
getInstance
public static CompactDecimalFormat getInstance(Locale locale, CompactDecimalFormat.CompactStyle style) NOTE: New users are strongly encouraged to useNumberFormatter
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
- the desired localestyle
- the compact style
-
parse
Parsing is currently unsupported, and throws an UnsupportedOperationException.- Overrides:
parse
in classDecimalFormat
- See Also:
-
parseCurrency
Parsing is currently unsupported, and throws an UnsupportedOperationException.- Overrides:
parseCurrency
in classDecimalFormat
- Parameters:
text
- the text to parseparsePosition
- 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:
- a CurrencyAmount, or null upon failure
-