public class CompactDecimalFormat extends DecimalFormat
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.
Modifier and Type | Class and Description |
---|---|
static class |
CompactDecimalFormat.CompactStyle
Style parameter for CompactDecimalFormat.
|
NumberFormat.Field, NumberFormat.NumberFormatFactory, NumberFormat.SimpleNumberFormatFactory
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
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Overrides equals.
|
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.
|
AttributedCharacterIterator |
formatToCharacterIterator(Object obj)
Formats the object to an attributed string, and return the corresponding iterator.
|
static CompactDecimalFormat |
getInstance(Locale locale,
CompactDecimalFormat.CompactStyle style)
Create a CompactDecimalFormat appropriate for a locale.
|
static CompactDecimalFormat |
getInstance(ULocale locale,
CompactDecimalFormat.CompactStyle style)
Create a CompactDecimalFormat appropriate for a locale.
|
Number |
parse(String text,
ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.
|
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
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
format, parseObject
@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)
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.public static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)
locale
- the desired localestyle
- the compact stylepublic static CompactDecimalFormat getInstance(Locale locale, CompactDecimalFormat.CompactStyle style)
locale
- the desired localestyle
- the compact stylepublic boolean equals(Object obj)
equals
in class DecimalFormat
obj
- the object to compare againstpublic StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)
format
in class DecimalFormat
Format.format(Object, StringBuffer, FieldPosition)
public AttributedCharacterIterator formatToCharacterIterator(Object obj)
formatToCharacterIterator
in class DecimalFormat
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)
format
in class DecimalFormat
Format.format(Object, StringBuffer, FieldPosition)
public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)
format
in class DecimalFormat
Format.format(Object, StringBuffer, FieldPosition)
public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
format
in class DecimalFormat
Format.format(Object, StringBuffer, FieldPosition)
public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
format
in class DecimalFormat
Format.format(Object, StringBuffer, FieldPosition)
public Number parse(String text, ParsePosition parsePosition)
parse
in class DecimalFormat
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.Number
object with the parsed value or
null
if the parse failedNumberFormat.isParseIntegerOnly()
,
Format.parseObject(String, ParsePosition)
Copyright (c) 2014 IBM Corporation and others.