open class CompactDecimalFormat : 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.
Summary
| Nested classes |
|
Style parameter for CompactDecimalFormat.
|
| Inherited constants |
From class NumberFormat
Int |
ACCOUNTINGCURRENCYSTYLE
[icu] Constant to specify currency style of format which uses currency symbol to represent currency for accounting, for example: "($3.00), instead of "-$3.00" (CURRENCYSTYLE). Overrides any style specified using -cf- key in locale.
|
Int |
CASHCURRENCYSTYLE
[icu] Constant to specify currency cash style of format which uses currency ISO code to represent currency, for example: "NT$3" instead of "NT$3.23".
|
Int |
CURRENCYSTYLE
[icu] Constant to specify general currency style of format. Defaults to STANDARDCURRENCYSTYLE, using currency symbol, for example "$3.00", with non-accounting style for negative values (e.g. minus sign). The specific style may be specified using the -cf- locale key.
|
Int |
FRACTION_FIELD
Field constant used to construct a FieldPosition object. Signifies that the position of the fraction part of a formatted number should be returned.
|
Int |
INTEGERSTYLE
[icu] Constant to specify a integer number style format.
|
Int |
INTEGER_FIELD
Field constant used to construct a FieldPosition object. Signifies that the position of the integer part of a formatted number should be returned.
|
Int |
ISOCURRENCYSTYLE
[icu] Constant to specify currency style of format which uses currency ISO code to represent currency, for example: "USD3.00".
|
Int |
NUMBERSTYLE
[icu] Constant to specify normal number style of format.
|
Int |
PERCENTSTYLE
[icu] Constant to specify a style of format to display percent.
|
Int |
PLURALCURRENCYSTYLE
[icu] Constant to specify currency style of format which uses currency long name with plural format to represent currency, for example, "3.00 US Dollars".
|
Int |
SCIENTIFICSTYLE
[icu] Constant to specify a style of format to display scientific number.
|
Int |
STANDARDCURRENCYSTYLE
[icu] Constant to specify currency style of format which uses currency symbol to represent currency, for example "$3.00", using non-accounting style for negative values (e.g. minus sign). Overrides any style specified using -cf- key in locale.
|
|
|
|
| Public methods |
| open static CompactDecimalFormat! |
NOTE: New users are strongly encouraged to use NumberFormatter instead of NumberFormat.
|
| open static CompactDecimalFormat! |
NOTE: New users are strongly encouraged to use NumberFormatter instead of NumberFormat.
|
| open Number! |
Parsing is currently unsupported, and throws an UnsupportedOperationException.
|
| open CurrencyAmount! |
Parsing is currently unsupported, and throws an UnsupportedOperationException.
|
| Inherited functions |
From class DecimalFormat
Unit |
applyLocalizedPattern(localizedPattern: String!)
Converts the given string to standard notation and then parses it using applyPattern. This method is provided for backwards compatibility and should not be used in new projects.
Localized notation means that instead of using generic placeholders in the pattern, you use the corresponding locale-specific characters instead. For example, in locale fr-FR, the period in the pattern "0.000" means "decimal" in standard notation (as it does in every other locale), but it means "grouping" in localized notation.
|
Unit |
applyPattern(pattern: String!)
Parses the given pattern string and overwrites the settings specified in the pattern string. The properties corresponding to the following setters are overwritten, either with their default values or with the value specified in the pattern string:
setDecimalSeparatorAlwaysShown
setExponentSignAlwaysShown
setFormatWidth
setGroupingSize
setMultiplier (percent/permille)
setMaximumFractionDigits
setMaximumIntegerDigits
setMaximumSignificantDigits
setMinimumExponentDigits
setMinimumFractionDigits
setMinimumIntegerDigits
setMinimumSignificantDigits
setPadPosition
setPadCharacter
- setRoundingIncrement
setSecondaryGroupingSize
All other settings remain untouched.
For more information on pattern strings, see UTS #35.
|
Boolean |
areSignificantDigitsUsed()
[icu] Returns whether significant digits are being used in rounding.
|
Any |
clone()
|
Boolean |
equals(other: Any?)
Tests for equality between this formatter and another formatter.
If two DecimalFormat instances are equal, then they will always produce the same output. However, the reverse is not necessarily true: if two DecimalFormat instances always produce the same output, they are not necessarily equal.
|
StringBuffer! |
format(number: BigDecimal!, result: StringBuffer!, fieldPosition: FieldPosition!)
[icu] Formats an ICU BigDecimal. Specialization of format.
|
StringBuffer! |
format(currAmt: CurrencyAmount!, result: StringBuffer!, fieldPosition: FieldPosition!)
[icu] Formats a CurrencyAmount. Specialization of format.
|
StringBuffer! |
format(number: Double, result: StringBuffer!, fieldPosition: FieldPosition!)
Specialization of format.
|
StringBuffer! |
format(number: BigDecimal!, result: StringBuffer!, fieldPosition: FieldPosition!)
[icu] Formats a BigDecimal. Specialization of format.
|
StringBuffer! |
format(number: BigInteger!, result: StringBuffer!, fieldPosition: FieldPosition!)
[icu] Formats a BigInteger. Specialization of format.
|
StringBuffer! |
format(number: Long, result: StringBuffer!, fieldPosition: FieldPosition!)
Specialization of format.
|
AttributedCharacterIterator! |
formatToCharacterIterator(obj: Any!)
Formats an Object producing an AttributedCharacterIterator. You can use the returned AttributedCharacterIterator to build the resulting String, as well as to determine information about the resulting String.
Each attribute key of the AttributedCharacterIterator will be of type Field. It is up to each Format implementation to define what the legal values are for each attribute in the AttributedCharacterIterator, but typically the attribute key is also used as the attribute value.
The default implementation creates an AttributedCharacterIterator with no attributes. Subclasses that support fields should override this and create an AttributedCharacterIterator with meaningful attributes.
|
Currency! |
getCurrency()
Returns the currency used to display currency amounts. May be null.
|
CurrencyPluralInfo! |
getCurrencyPluralInfo()
[icu] Returns the current instance of CurrencyPluralInfo.
|
Currency.CurrencyUsage! |
getCurrencyUsage()
[icu] Returns the strategy for rounding currency amounts.
|
DecimalFormatSymbols! |
getDecimalFormatSymbols()
Returns a copy of the decimal format symbols used by this formatter.
|
Int |
getFormatWidth()
Returns the minimum number of characters in formatted output.
|
Int |
getGroupingSize()
Returns the primary grouping size in use.
|
MathContext! |
getMathContext()
[icu] Returns the java.math.MathContext being used to round numbers.
|
MathContext! |
getMathContextICU()
[icu] Returns the android.icu.math.MathContext being used to round numbers.
|
Int |
getMaximumFractionDigits()
Returns the effective maximum number of integer digits after the decimal separator.
|
Int |
getMaximumIntegerDigits()
Returns the effective maximum number of digits before the decimal separator.
|
Int |
getMaximumSignificantDigits()
[icu] Returns the effective maximum number of significant digits displayed.
|
Byte |
getMinimumExponentDigits()
[icu] Returns the minimum number of digits printed in the exponent in scientific notation.
|
Int |
getMinimumFractionDigits()
Returns the effective minimum number of integer digits after the decimal separator.
|
Int |
getMinimumGroupingDigits()
[icu] Returns the minimum number of digits before grouping is triggered.
|
Int |
getMinimumIntegerDigits()
Returns the effective minimum number of digits before the decimal separator.
|
Int |
getMinimumSignificantDigits()
[icu] Returns the effective minimum number of significant digits displayed.
|
Int |
getMultiplier()
Returns the multiplier being applied to numbers before they are formatted.
|
String! |
getNegativePrefix()
Affixes: Gets the negative prefix string currently being used to format numbers.
If the affix was specified via the pattern, the string returned by this method will have locale symbols substituted in place of special characters according to the LDML specification. If the affix was specified via setNegativePrefix, the string will be returned literally.
|
String! |
getNegativeSuffix()
Affixes: Gets the negative suffix string currently being used to format numbers.
If the affix was specified via the pattern, the string returned by this method will have locale symbols substituted in place of special characters according to the LDML specification. If the affix was specified via setNegativeSuffix, the string will be returned literally.
|
Char |
getPadCharacter()
[icu] Returns the character used for padding.
|
Int |
getPadPosition()
[icu] Returns the position used for padding.
|
Int |
getParseMaxDigits()
Always returns 1000, the default prior to ICU 59.
|
String! |
getPositivePrefix()
Affixes: Gets the positive prefix string currently being used to format numbers.
If the affix was specified via the pattern, the string returned by this method will have locale symbols substituted in place of special characters according to the LDML specification. If the affix was specified via setPositivePrefix, the string will be returned literally.
|
String! |
getPositiveSuffix()
Affixes: Gets the positive suffix string currently being used to format numbers.
If the affix was specified via the pattern, the string returned by this method will have locale symbols substituted in place of special characters according to the LDML specification. If the affix was specified via setPositiveSuffix, the string will be returned literally.
|
BigDecimal! |
getRoundingIncrement()
[icu] Returns the increment to which numbers are being rounded.
|
Int |
getRoundingMode()
Returns the rounding mode being used to round numbers.
|
Int |
getSecondaryGroupingSize()
[icu] Returns the secondary grouping size in use.
|
Int |
hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the
equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
- It is not required that if two objects are unequal according to the
equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
|
Boolean |
isDecimalPatternMatchRequired()
[icu] Returns whether the presence of a decimal point must match the pattern.
|
Boolean |
isDecimalSeparatorAlwaysShown()
Returns whether the decimal separator is shown on integers.
|
Boolean |
isExponentSignAlwaysShown()
[icu] Returns whether the sign (plus or minus) is always printed in scientific notation.
|
Boolean |
isGroupingUsed()
Returns whether or not grouping separators are being printed in the output.
|
Boolean |
isParseBigDecimal()
Returns whether #parse will always return a BigDecimal.
|
Boolean |
isParseCaseSensitive()
[icu] Returns whether to force case (uppercase/lowercase) to match when parsing.
|
Boolean |
isParseIntegerOnly()
Returns true if this format will parse numbers as integers only. For example in the English locale, with ParseIntegerOnly true, the string "1234." would be parsed as the integer value 1234 and parsing would stop at the "." character. The decimal separator accep | |