com.ibm.icu.text
Class CompactDecimalFormat

java.lang.Object
  extended by java.text.Format
      extended by com.ibm.icu.text.UFormat
          extended by com.ibm.icu.text.NumberFormat
              extended by com.ibm.icu.text.DecimalFormat
                  extended by 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.

Author:
markdavis
See Also:
Serialized Form
Status:
Draft ICU 49.

Nested Class Summary
 
Nested classes/interfaces inherited from class com.ibm.icu.text.NumberFormat
NumberFormat.CompactStyle, 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
CURRENCYSTYLE, FRACTION_FIELD, INTEGER_FIELD, INTEGERSTYLE, ISOCURRENCYSTYLE, NUMBERSTYLE, PERCENTSTYLE, PLURALCURRENCYSTYLE, SCIENTIFICSTYLE
 
Constructor Summary
CompactDecimalFormat(String pattern, DecimalFormatSymbols formatSymbols, String[] prefix, String[] suffix, long[] divisor, Collection<String> debugCreationErrors, NumberFormat.CompactStyle style, String[] currencyAffixes)
          Create a short number "from scratch".
 
Method Summary
 StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
          Formats a BigDecimal number.
 StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
          Formats a BigDecimal number.
 StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)
          Formats a BigInteger number.
 StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)
          Specialization of format.
 StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)
          Specialization of format.
 Number parse(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, equals, formatToCharacterIterator, getCurrencyPluralInfo, getDecimalFormatSymbols, getEffectiveCurrency, getFormatWidth, getGroupingSize, getMathContext, getMathContextICU, getMaximumSignificantDigits, getMinimumExponentDigits, getMinimumSignificantDigits, getMultiplier, getNegativePrefix, getNegativeSuffix, getPadCharacter, getPadPosition, getPositivePrefix, getPositiveSuffix, getRoundingIncrement, getRoundingMode, getSecondaryGroupingSize, hashCode, isDecimalSeparatorAlwaysShown, isExponentSignAlwaysShown, isParseBigDecimal, isScientificNotation, parseCurrency, setCurrency, setCurrencyPluralInfo, setDecimalFormatSymbols, setDecimalSeparatorAlwaysShown, setExponentSignAlwaysShown, setFormatWidth, setGroupingSize, setMathContext, setMathContextICU, setMaximumFractionDigits, setMaximumIntegerDigits, setMaximumSignificantDigits, setMinimumExponentDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setMinimumSignificantDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setPadCharacter, setPadPosition, setParseBigDecimal, 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, getCompactDecimalInstance, getCompactDecimalInstance, 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, setGroupingUsed, setParseIntegerOnly, setParseStrict, unregister
 
Methods inherited from class com.ibm.icu.text.UFormat
getLocale
 
Methods inherited from class java.text.Format
format, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompactDecimalFormat

public CompactDecimalFormat(String pattern,
                            DecimalFormatSymbols formatSymbols,
                            String[] prefix,
                            String[] suffix,
                            long[] divisor,
                            Collection<String> debugCreationErrors,
                            NumberFormat.CompactStyle style,
                            String[] currencyAffixes)
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.
prefix - An array of prefix values, one for each power of 10 from 0 to 14
suffix - An array of prefix values, one for each power of 10 from 0 to 14
divisor - An array of prefix values, one for each power of 10 from 0 to 14
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.
Status:
Internal. This API is ICU internal only.
Method Detail

format

public StringBuffer format(double number,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Specialization of format.

Overrides:
format in class DecimalFormat
See Also:
Format.format(Object, StringBuffer, FieldPosition)
Status:
Draft ICU 49.

format

public StringBuffer format(long number,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Specialization of format.

Overrides:
format in class DecimalFormat
See Also:
Format.format(Object, StringBuffer, FieldPosition)
Status:
Draft ICU 49.

format

public StringBuffer format(BigInteger number,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Formats a BigInteger number.

Overrides:
format in class DecimalFormat
See Also:
Format.format(Object, StringBuffer, FieldPosition)
Status:
Draft ICU 49.

format

public StringBuffer format(BigDecimal number,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Formats a BigDecimal number.

Overrides:
format in class DecimalFormat
See Also:
Format.format(Object, StringBuffer, FieldPosition)
Status:
Draft ICU 49.

format

public StringBuffer format(BigDecimal number,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Formats a BigDecimal number.

Overrides:
format in class DecimalFormat
See Also:
Format.format(Object, StringBuffer, FieldPosition)
Status:
Draft ICU 49.

parse

public Number parse(String text,
                    ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.

Overrides:
parse in class DecimalFormat
Parameters:
text - the string to be parsed
parsePosition - 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 Number object with the parsed value or null if the parse failed
See Also:
NumberFormat.isParseIntegerOnly(), Format.parseObject(String, ParsePosition)
Status:
Draft ICU 49.


Copyright (c) 2012 IBM Corporation and others.