public class CompactDecimalFormat extends DecimalFormat
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.
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.
Modifier and Type | Class and Description |
---|---|
static class |
CompactDecimalFormat.CompactStyle
Style parameter for CompactDecimalFormat.
|
DecimalFormat.PropertySetter
NumberFormat.Field, NumberFormat.NumberFormatFactory, NumberFormat.SimpleNumberFormatFactory
UFormat.SpanField
MINIMUM_GROUPING_DIGITS_AUTO, MINIMUM_GROUPING_DIGITS_MIN2, 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, STANDARDCURRENCYSTYLE
Modifier and Type | Method and Description |
---|---|
static CompactDecimalFormat |
getInstance(Locale locale,
CompactDecimalFormat.CompactStyle style)
NOTE: New users are strongly encouraged to use
NumberFormatter instead of NumberFormat. |
static CompactDecimalFormat |
getInstance(ULocale locale,
CompactDecimalFormat.CompactStyle style)
NOTE: New users are strongly encouraged to use
NumberFormatter instead of NumberFormat. |
Number |
parse(String text,
ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.
|
CurrencyAmount |
parseCurrency(CharSequence text,
ParsePosition parsePosition)
Parsing is currently unsupported, and throws an UnsupportedOperationException.
|
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
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
format, parseObject
public static CompactDecimalFormat getInstance(ULocale locale, CompactDecimalFormat.CompactStyle style)
NumberFormatter
instead of NumberFormat.
locale
- the desired localestyle
- the compact stylepublic static CompactDecimalFormat getInstance(Locale locale, CompactDecimalFormat.CompactStyle style)
NumberFormatter
instead of NumberFormat.
locale
- the desired localestyle
- the compact stylepublic Number parse(String text, ParsePosition parsePosition)
parse
in class DecimalFormat
NumberFormat.isParseIntegerOnly()
,
DecimalFormat.setParseBigDecimal(boolean)
,
Format.parseObject(String, ParsePosition)
public CurrencyAmount parseCurrency(CharSequence text, ParsePosition parsePosition)
parseCurrency
in class DecimalFormat
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.Copyright © 2016 Unicode, Inc. and others.