Class CompactDecimalFormat
- java.lang.Object
-
- java.text.Format
-
- com.ibm.icu.text.UFormat
-
- com.ibm.icu.text.NumberFormat
-
- com.ibm.icu.text.DecimalFormat
-
- com.ibm.icu.text.CompactDecimalFormat
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class CompactDecimalFormat extends DecimalFormat
Formats numbers in compact (abbreviated) notation, like "1.2K" instead of "1200".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.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompactDecimalFormat.CompactStyle
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.NumberFormatShim, NumberFormat.SimpleNumberFormatFactory
-
Nested classes/interfaces inherited from class com.ibm.icu.text.UFormat
UFormat.SpanField
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
-
Fields inherited from class com.ibm.icu.text.DecimalFormat
currencyParser, exportedProperties, formatter, MINIMUM_GROUPING_DIGITS_AUTO, MINIMUM_GROUPING_DIGITS_MIN2, PAD_AFTER_PREFIX, PAD_AFTER_SUFFIX, PAD_BEFORE_PREFIX, PAD_BEFORE_SUFFIX, parser, properties, symbols
-
Fields inherited from class com.ibm.icu.text.NumberFormat
ACCOUNTINGCURRENCYSTYLE, CASHCURRENCYSTYLE, CURRENCYSTYLE, currentSerialVersion, FRACTION_FIELD, INTEGER_FIELD, INTEGERSTYLE, ISOCURRENCYSTYLE, NUMBERSTYLE, PERCENTSTYLE, PLURALCURRENCYSTYLE, SCIENTIFICSTYLE, STANDARDCURRENCYSTYLE
-
-
Constructor Summary
Constructors Constructor Description CompactDecimalFormat(ULocale locale, CompactDecimalFormat.CompactStyle style)
The public mechanism is CompactDecimalFormat.getInstance().
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CompactDecimalFormat
getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)
NOTE: New users are strongly encouraged to useNumberFormatter
instead of NumberFormat.static CompactDecimalFormat
getInstance(java.util.Locale locale, CompactDecimalFormat.CompactStyle style)
NOTE: New users are strongly encouraged to useNumberFormatter
instead of NumberFormat.java.lang.Number
parse(java.lang.String text, java.text.ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.CurrencyAmount
parseCurrency(java.lang.CharSequence text, java.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, fieldPositionHelper, format, format, format, format, format, format, formatToCharacterIterator, getCurrency, getCurrencyParser, getCurrencyPluralInfo, getCurrencyUsage, getDecimalFormatSymbols, getFixedDecimal, getFormatWidth, getGroupingSize, getMathContext, getMathContextICU, getMaximumFractionDigits, getMaximumIntegerDigits, getMaximumSignificantDigits, getMinimumExponentDigits, getMinimumFractionDigits, getMinimumGroupingDigits, getMinimumIntegerDigits, getMinimumSignificantDigits, getMultiplier, getNegativePrefix, getNegativeSuffix, getPadCharacter, getPadPosition, getParseMaxDigits, getParser, getPositivePrefix, getPositiveSuffix, getRoundingIncrement, getRoundingMode, getSecondaryGroupingSize, hashCode, isDecimalPatternMatchRequired, isDecimalSeparatorAlwaysShown, isExponentSignAlwaysShown, isGroupingUsed, isParseBigDecimal, isParseCaseSensitive, isParseIntegerOnly, isParseNoExponent, isParseStrict, isScientificNotation, isSignAlwaysShown, refreshFormatter, 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, setPropertiesFromPattern, setRoundingIncrement, setRoundingIncrement, setRoundingIncrement, setRoundingMode, setScientificNotation, setSecondaryGroupingSize, setSignAlwaysShown, setSignificantDigitsUsed, toLocalizedPattern, toNumberFormatter, toPattern, toString
-
Methods inherited from class com.ibm.icu.text.NumberFormat
createInstance, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CompactDecimalFormat
CompactDecimalFormat(ULocale locale, CompactDecimalFormat.CompactStyle style)
The public mechanism is CompactDecimalFormat.getInstance().- Parameters:
locale
- the desired localestyle
- the compact style
-
-
Method Detail
-
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(java.util.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
public java.lang.Number parse(java.lang.String text, java.text.ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.- Overrides:
parse
in classDecimalFormat
- See Also:
NumberFormat.isParseIntegerOnly()
,DecimalFormat.setParseBigDecimal(boolean)
,Format.parseObject(String, ParsePosition)
-
parseCurrency
public CurrencyAmount parseCurrency(java.lang.CharSequence text, java.text.ParsePosition parsePosition)
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
-
-