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:
Serializable,Cloneable
public class CompactDecimalFormat extends DecimalFormat
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.
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 classCompactDecimalFormat.CompactStyleStyle parameter for CompactDecimalFormat.-
Nested classes/interfaces inherited from class com.ibm.icu.text.NumberFormat
NumberFormat.Field, NumberFormat.NumberFormatFactory, NumberFormat.SimpleNumberFormatFactory
-
-
Field Summary
-
Fields inherited from class com.ibm.icu.text.DecimalFormat
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
-
-
Constructor Summary
Constructors Constructor Description CompactDecimalFormat(String pattern, DecimalFormatSymbols formatSymbols, CompactDecimalFormat.CompactStyle style, PluralRules pluralRules, long[] divisor, Map<String,String[][]> pluralAffixes, Map<String,String[]> currencyAffixes, Collection<String> debugCreationErrors)Deprecated.This API is ICU internal only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Overrides equals.StringBufferformat(double number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.StringBufferformat(long number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.StringBufferformat(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)Formats a BigDecimal number.StringBufferformat(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)Formats a BigDecimal number.StringBufferformat(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)Formats a BigInteger number.AttributedCharacterIteratorformatToCharacterIterator(Object obj)Formats the object to an attributed string, and return the corresponding iterator.static CompactDecimalFormatgetInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)Create a CompactDecimalFormat appropriate for a locale.static CompactDecimalFormatgetInstance(Locale locale, CompactDecimalFormat.CompactStyle style)Create a CompactDecimalFormat appropriate for a locale.Numberparse(String text, ParsePosition parsePosition)Parsing is currently unsupported, and throws an UnsupportedOperationException.-
Methods inherited from class com.ibm.icu.text.DecimalFormat
applyLocalizedPattern, applyPattern, areSignificantDigitsUsed, clone, getCurrencyPluralInfo, getCurrencyUsage, getDecimalFormatSymbols, getEffectiveCurrency, getFormatWidth, getGroupingSize, getMathContext, getMathContextICU, getMaximumSignificantDigits, getMinimumExponentDigits, getMinimumSignificantDigits, getMultiplier, getNegativePrefix, getNegativeSuffix, getPadCharacter, getPadPosition, getParseMaxDigits, getPositivePrefix, getPositiveSuffix, getRoundingIncrement, getRoundingMode, getSecondaryGroupingSize, hashCode, isDecimalPatternMatchRequired, isDecimalSeparatorAlwaysShown, isExponentSignAlwaysShown, isParseBigDecimal, isScientificNotation, parseCurrency, setCurrency, setCurrencyPluralInfo, setCurrencyUsage, setDecimalFormatSymbols, setDecimalPatternMatchRequired, setDecimalSeparatorAlwaysShown, setExponentSignAlwaysShown, setFormatWidth, setGroupingSize, setMathContext, setMathContextICU, setMaximumFractionDigits, setMaximumIntegerDigits, setMaximumSignificantDigits, setMinimumExponentDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setMinimumSignificantDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setPadCharacter, setPadPosition, setParseBigDecimal, setParseMaxDigits, setPositivePrefix, setPositiveSuffix, setRoundingIncrement, setRoundingIncrement, setRoundingIncrement, setRoundingMode, setScientificNotation, setSecondaryGroupingSize, setSignificantDigitsUsed, toLocalizedPattern, toPattern
-
Methods inherited from class com.ibm.icu.text.NumberFormat
format, format, format, format, format, format, format, format, getAvailableLocales, getAvailableULocales, getContext, getCurrency, getCurrencyInstance, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getNumberInstance, getPattern, getPattern, getPercentInstance, getPercentInstance, getPercentInstance, getScientificInstance, getScientificInstance, getScientificInstance, isGroupingUsed, isParseIntegerOnly, isParseStrict, parse, parseObject, registerFactory, setContext, setGroupingUsed, setParseIntegerOnly, setParseStrict, unregister
-
Methods inherited from class java.text.Format
format, parseObject
-
-
-
-
Constructor Detail
-
CompactDecimalFormat
@Deprecated public CompactDecimalFormat(String pattern, DecimalFormatSymbols formatSymbols, CompactDecimalFormat.CompactStyle style, PluralRules pluralRules, long[] divisor, Map<String,String[][]> pluralAffixes, Map<String,String[]> currencyAffixes, Collection<String> debugCreationErrors)
Deprecated.This API is ICU internal only.Create a short number "from scratch". Intended for internal use. The prefix, suffix, and divisor arrays are parallel, and provide the information for each power of 10. When formatting a value, the correct power of 10 is found, then the value is divided by the divisor, and the prefix and suffix are set (using setPositivePrefix/Suffix).- Parameters:
pattern- A number format pattern. Note that the prefix and suffix are discarded, and the decimals are overridden by default.formatSymbols- Decimal format symbols, typically from a locale.style- compact style.divisor- An array of prefix values, one for each power of 10 from 0 to 14pluralAffixes- A map from plural categories to affixes.currencyAffixes- A map from plural categories to currency affixes.debugCreationErrors- A collection of strings for debugging. If null on input, then any errors found will be added to that collection instead of throwing exceptions.
-
-
Method Detail
-
getInstance
public static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)
Create 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)
Create 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
-
equals
public boolean equals(Object obj)
Overrides equals.- Overrides:
equalsin classDecimalFormat- Parameters:
obj- the object to compare against- Returns:
- true if the object is equal to this.
- See Also:
Object.hashCode()
-
format
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)
Specialization of format.- Overrides:
formatin classDecimalFormat- See Also:
Format.format(Object, StringBuffer, FieldPosition)
-
formatToCharacterIterator
public AttributedCharacterIterator formatToCharacterIterator(Object obj)
Formats the object to an attributed string, and return the corresponding iterator.- Overrides:
formatToCharacterIteratorin classDecimalFormat- Parameters:
obj- the object to format.- Returns:
- an
AttributedCharacterIteratorwith the formatted object and attributes.
-
format
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)
Specialization of format.- Overrides:
formatin classDecimalFormat- See Also:
Format.format(Object, StringBuffer, FieldPosition)
-
format
public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)
Formats a BigInteger number.- Overrides:
formatin classDecimalFormat- See Also:
Format.format(Object, StringBuffer, FieldPosition)
-
format
public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
Formats a BigDecimal number.- Overrides:
formatin classDecimalFormat- See Also:
Format.format(Object, StringBuffer, FieldPosition)
-
format
public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
Formats a BigDecimal number.- Overrides:
formatin classDecimalFormat- See Also:
Format.format(Object, StringBuffer, FieldPosition)
-
parse
public Number parse(String text, ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.- Overrides:
parsein classDecimalFormat- Parameters:
text- the string to be parsedparsePosition- defines the position where parsing is to begin, and upon return, the position where parsing left off. If the position has not changed upon return, then parsing failed.- Returns:
- a
Numberobject with the parsed value ornullif the parse failed - See Also:
NumberFormat.isParseIntegerOnly(),Format.parseObject(String, ParsePosition)
-
-