ICU 51.2
51.2
|
The CompactDecimalFormat produces abbreviated numbers, suitable for display in environments will limited real estate. More...
#include <compactdecimalformat.h>
Public Member Functions | |
CompactDecimalFormat (const CompactDecimalFormat &source) | |
Copy constructor. | |
virtual | ~CompactDecimalFormat () |
Destructor. | |
CompactDecimalFormat & | operator= (const CompactDecimalFormat &rhs) |
Assignment operator. | |
virtual Format * | clone () const |
Clone this Format object polymorphically. | |
virtual UBool | operator== (const Format &other) const |
Return TRUE if the given Format objects are semantically equal. | |
virtual UnicodeString & | format (double number, UnicodeString &appendTo, FieldPosition &pos) const |
Format a double or long number using base-10 representation. | |
virtual UnicodeString & | format (double number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format a double or long number using base-10 representation. | |
virtual UnicodeString & | format (int64_t number, UnicodeString &appendTo, FieldPosition &pos) const |
Format an int64 number using base-10 representation. | |
virtual UnicodeString & | format (int64_t number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format an int64 number using base-10 representation. | |
virtual UnicodeString & | format (const StringPiece &number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format a decimal number. | |
virtual UnicodeString & | format (const DigitList &number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format a decimal number. | |
virtual UnicodeString & | format (const DigitList &number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const |
Format a decimal number. | |
virtual void | parse (const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const |
CompactDecimalFormat does not support parsing. | |
virtual void | parse (const UnicodeString &text, Formattable &result, UErrorCode &status) const |
CompactDecimalFormat does not support parsing. | |
virtual CurrencyAmount * | parseCurrency (const UnicodeString &text, ParsePosition &pos) const |
Parses text from the given string as a currency amount. | |
virtual UClassID | getDynamicClassID () const |
Returns a unique class ID POLYMORPHICALLY. | |
![]() | |
DecimalFormat (UErrorCode &status) | |
Create a DecimalFormat using the default pattern and symbols for the default locale. | |
DecimalFormat (const UnicodeString &pattern, UErrorCode &status) | |
Create a DecimalFormat from the given pattern and the symbols for the default locale. | |
DecimalFormat (const UnicodeString &pattern, DecimalFormatSymbols *symbolsToAdopt, UErrorCode &status) | |
Create a DecimalFormat from the given pattern and symbols. | |
DecimalFormat (const UnicodeString &pattern, DecimalFormatSymbols *symbolsToAdopt, UNumberFormatStyle style, UErrorCode &status) | |
This API is for ICU use only. | |
virtual DecimalFormat & | setAttribute (UNumberFormatAttribute attr, int32_t newvalue, UErrorCode &status) |
Set an integer attribute on this DecimalFormat. | |
virtual int32_t | getAttribute (UNumberFormatAttribute attr, UErrorCode &status) const |
Get an integer May return U_UNSUPPORTED_ERROR if this instance does not support the specified attribute. | |
DecimalFormat (const UnicodeString &pattern, DecimalFormatSymbols *symbolsToAdopt, UParseError &parseError, UErrorCode &status) | |
Create a DecimalFormat from the given pattern and symbols. | |
DecimalFormat (const UnicodeString &pattern, const DecimalFormatSymbols &symbols, UErrorCode &status) | |
Create a DecimalFormat from the given pattern and symbols. | |
DecimalFormat (const DecimalFormat &source) | |
Copy constructor. | |
DecimalFormat & | operator= (const DecimalFormat &rhs) |
Assignment operator. | |
virtual | ~DecimalFormat () |
Destructor. | |
virtual UnicodeString & | format (double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const |
Format a double or long number using base-10 representation. | |
virtual UnicodeString & | format (int32_t number, UnicodeString &appendTo, FieldPosition &pos) const |
Format a long number using base-10 representation. | |
virtual UnicodeString & | format (int32_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const |
Format a long number using base-10 representation. | |
virtual UnicodeString & | format (int32_t number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format a long number using base-10 representation. | |
virtual UnicodeString & | format (int64_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const |
Format an int64 number using base-10 representation. | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const |
Format a Formattable using base-10 representation. | |
UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const |
Redeclared NumberFormat method. | |
UnicodeString & | format (double number, UnicodeString &appendTo) const |
Redeclared NumberFormat method. | |
UnicodeString & | format (int32_t number, UnicodeString &appendTo) const |
Redeclared NumberFormat method. | |
UnicodeString & | format (int64_t number, UnicodeString &appendTo) const |
Redeclared NumberFormat method. | |
virtual const DecimalFormatSymbols * | getDecimalFormatSymbols (void) const |
Returns the decimal format symbols, which is generally not changed by the programmer or user. | |
virtual void | adoptDecimalFormatSymbols (DecimalFormatSymbols *symbolsToAdopt) |
Sets the decimal format symbols, which is generally not changed by the programmer or user. | |
virtual void | setDecimalFormatSymbols (const DecimalFormatSymbols &symbols) |
Sets the decimal format symbols, which is generally not changed by the programmer or user. | |
virtual const CurrencyPluralInfo * | getCurrencyPluralInfo (void) const |
Returns the currency plural format information, which is generally not changed by the programmer or user. | |
virtual void | adoptCurrencyPluralInfo (CurrencyPluralInfo *toAdopt) |
Sets the currency plural format information, which is generally not changed by the programmer or user. | |
virtual void | setCurrencyPluralInfo (const CurrencyPluralInfo &info) |
Sets the currency plural format information, which is generally not changed by the programmer or user. | |
UnicodeString & | getPositivePrefix (UnicodeString &result) const |
Get the positive prefix. | |
virtual void | setPositivePrefix (const UnicodeString &newValue) |
Set the positive prefix. | |
UnicodeString & | getNegativePrefix (UnicodeString &result) const |
Get the negative prefix. | |
virtual void | setNegativePrefix (const UnicodeString &newValue) |
Set the negative prefix. | |
UnicodeString & | getPositiveSuffix (UnicodeString &result) const |
Get the positive suffix. | |
virtual void | setPositiveSuffix (const UnicodeString &newValue) |
Set the positive suffix. | |
UnicodeString & | getNegativeSuffix (UnicodeString &result) const |
Get the negative suffix. | |
virtual void | setNegativeSuffix (const UnicodeString &newValue) |
Set the negative suffix. | |
int32_t | getMultiplier (void) const |
Get the multiplier for use in percent, permill, etc. | |
virtual void | setMultiplier (int32_t newValue) |
Set the multiplier for use in percent, permill, etc. | |
virtual double | getRoundingIncrement (void) const |
Get the rounding increment. | |
virtual void | setRoundingIncrement (double newValue) |
Set the rounding increment. | |
virtual ERoundingMode | getRoundingMode (void) const |
Get the rounding mode. | |
virtual void | setRoundingMode (ERoundingMode roundingMode) |
Set the rounding mode. | |
virtual int32_t | getFormatWidth (void) const |
Get the width to which the output of format() is padded. | |
virtual void | setFormatWidth (int32_t width) |
Set the width to which the output of format() is padded. | |
virtual UnicodeString | getPadCharacterString () const |
Get the pad character used to pad to the format width. | |
virtual void | setPadCharacter (const UnicodeString &padChar) |
Set the character used to pad to the format width. | |
virtual EPadPosition | getPadPosition (void) const |
Get the position at which padding will take place. | |
virtual void | setPadPosition (EPadPosition padPos) |
Set the position at which padding will take place. | |
virtual UBool | isScientificNotation (void) |
Return whether or not scientific notation is used. | |
virtual void | setScientificNotation (UBool useScientific) |
Set whether or not scientific notation is used. | |
virtual int8_t | getMinimumExponentDigits (void) const |
Return the minimum exponent digits that will be shown. | |
virtual void | setMinimumExponentDigits (int8_t minExpDig) |
Set the minimum exponent digits that will be shown. | |
virtual UBool | isExponentSignAlwaysShown (void) |
Return whether the exponent sign is always shown. | |
virtual void | setExponentSignAlwaysShown (UBool expSignAlways) |
Set whether the exponent sign is always shown. | |
int32_t | getGroupingSize (void) const |
Return the grouping size. | |
virtual void | setGroupingSize (int32_t newValue) |
Set the grouping size. | |
int32_t | getSecondaryGroupingSize (void) const |
Return the secondary grouping size. | |
virtual void | setSecondaryGroupingSize (int32_t newValue) |
Set the secondary grouping size. | |
UBool | isDecimalSeparatorAlwaysShown (void) const |
Allows you to get the behavior of the decimal separator with integers. | |
virtual void | setDecimalSeparatorAlwaysShown (UBool newValue) |
Allows you to set the behavior of the decimal separator with integers. | |
virtual UnicodeString & | toPattern (UnicodeString &result) const |
Synthesizes a pattern string that represents the current state of this Format object. | |
virtual UnicodeString & | toLocalizedPattern (UnicodeString &result) const |
Synthesizes a localized pattern string that represents the current state of this Format object. | |
virtual void | applyPattern (const UnicodeString &pattern, UParseError &parseError, UErrorCode &status) |
Apply the given pattern to this Format object. | |
virtual void | applyPattern (const UnicodeString &pattern, UErrorCode &status) |
Sets the pattern. | |
virtual void | applyLocalizedPattern (const UnicodeString &pattern, UParseError &parseError, UErrorCode &status) |
Apply the given pattern to this Format object. | |
virtual void | applyLocalizedPattern (const UnicodeString &pattern, UErrorCode &status) |
Apply the given pattern to this Format object. | |
virtual void | setMaximumIntegerDigits (int32_t newValue) |
Sets the maximum number of digits allowed in the integer portion of a number. | |
virtual void | setMinimumIntegerDigits (int32_t newValue) |
Sets the minimum number of digits allowed in the integer portion of a number. | |
virtual void | setMaximumFractionDigits (int32_t newValue) |
Sets the maximum number of digits allowed in the fraction portion of a number. | |
virtual void | setMinimumFractionDigits (int32_t newValue) |
Sets the minimum number of digits allowed in the fraction portion of a number. | |
int32_t | getMinimumSignificantDigits () const |
Returns the minimum number of significant digits that will be displayed. | |
int32_t | getMaximumSignificantDigits () const |
Returns the maximum number of significant digits that will be displayed. | |
void | setMinimumSignificantDigits (int32_t min) |
Sets the minimum number of significant digits that will be displayed. | |
void | setMaximumSignificantDigits (int32_t max) |
Sets the maximum number of significant digits that will be displayed. | |
UBool | areSignificantDigitsUsed () const |
Returns true if significant digits are in use, or false if integer and fraction digit counts are in use. | |
void | setSignificantDigitsUsed (UBool useSignificantDigits) |
Sets whether significant digits are in use, or integer and fraction digit counts are in use. | |
virtual void | setCurrency (const UChar *theCurrency, UErrorCode &ec) |
Sets the currency used to display currency amounts. | |
virtual void | setCurrency (const UChar *theCurrency) |
Sets the currency used to display currency amounts. | |
![]() | |
virtual | ~NumberFormat () |
Destructor. | |
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const |
Format an object to produce a string. | |
virtual void | parseObject (const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const |
Parse a string to produce an object. | |
UBool | isParseIntegerOnly (void) const |
Return true if this format will parse numbers as integers only. | |
virtual void | setParseIntegerOnly (UBool value) |
Sets whether or not numbers should be parsed as integers only. | |
virtual void | setLenient (UBool enable) |
Sets whether lenient parsing should be enabled (it is off by default). | |
virtual UBool | isLenient (void) const |
Returns whether lenient parsing is enabled (it is off by default). | |
UBool | isGroupingUsed (void) const |
Returns true if grouping is used in this format. | |
virtual void | setGroupingUsed (UBool newValue) |
Set whether or not grouping will be used in this format. | |
int32_t | getMaximumIntegerDigits (void) const |
Returns the maximum number of digits allowed in the integer portion of a number. | |
int32_t | getMinimumIntegerDigits (void) const |
Returns the minimum number of digits allowed in the integer portion of a number. | |
int32_t | getMaximumFractionDigits (void) const |
Returns the maximum number of digits allowed in the fraction portion of a number. | |
int32_t | getMinimumFractionDigits (void) const |
Returns the minimum number of digits allowed in the fraction portion of a number. | |
const UChar * | getCurrency () const |
Gets the currency used to display currency amounts. | |
![]() | |
virtual | ~Format () |
Destructor. | |
UBool | operator!= (const Format &other) const |
Return true if the given Format objects are not semantically equal. | |
void | parseObject (const UnicodeString &source, Formattable &result, UErrorCode &status) const |
Parses a string to produce an object. | |
Locale | getLocale (ULocDataLocaleType type, UErrorCode &status) const |
Get the locale for this format object. | |
const char * | getLocaleID (ULocDataLocaleType type, UErrorCode &status) const |
Get the locale for this format object. | |
![]() | |
virtual | ~UObject () |
Destructor. |
Static Public Member Functions | |
static CompactDecimalFormat * | createInstance (const Locale &inLocale, UNumberCompactStyle style, UErrorCode &status) |
Returns a compact decimal instance for specified locale. | |
static UClassID | getStaticClassID () |
Return the class ID for this class. |
Additional Inherited Members | |
![]() | |
enum | ERoundingMode { kRoundCeiling, kRoundFloor, kRoundDown, kRoundUp, kRoundHalfEven, kRoundHalfDown, kRoundHalfUp, kRoundUnnecessary } |
Rounding mode. More... | |
enum | EPadPosition { kPadBeforePrefix, kPadAfterPrefix, kPadBeforeSuffix, kPadAfterSuffix } |
Pad position. More... | |
![]() | |
static const char | fgNumberPatterns [] |
The resource tags we use to retrieve decimal format data from locale resource bundles. | |
![]() | |
DigitList & | _round (const DigitList &number, DigitList &adjustedNum, UBool &isNegative, UErrorCode &status) const |
Rounds a value according to the rules of this object. | |
virtual void | getEffectiveCurrency (UChar *result, UErrorCode &ec) const |
Returns the currency in effect for this formatter. | |
![]() | |
static NumberFormat * | makeInstance (const Locale &desiredLocale, UNumberFormatStyle style, UBool mustBeDecimalFormat, UErrorCode &errorCode) |
Creates the specified number format style of the desired locale. | |
![]() | |
static const int32_t | kDoubleIntegerDigits |
number of integer digits | |
static const int32_t | kDoubleFractionDigits |
number of fraction digits | |
static const int32_t | kMaxScientificIntegerDigits |
When someone turns on scientific mode, we assume that more than this number of digits is due to flipping from some other mode that didn't restrict the maximum, and so we force 1 integer digit. |
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 3 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, parsing is not supported, and will produce a U_UNSUPPORTED_ERROR. Resetting the pattern prefixes or suffixes is not supported; the method calls are ignored.
Definition at line 53 of file compactdecimalformat.h.
icu::CompactDecimalFormat::CompactDecimalFormat | ( | const CompactDecimalFormat & | source | ) |
Copy constructor.
source | the DecimalFormat object to be copied from. |
|
virtual |
Destructor.
|
virtual |
Clone this Format object polymorphically.
The caller owns the result and should delete it when done.
Reimplemented from icu::DecimalFormat.
|
static |
Returns a compact decimal instance for specified locale.
inLocale | the given locale. |
style | whether to use short or long style. |
status | error code returned here. |
|
virtual |
Format a double or long number using base-10 representation.
number | The value to be formatted. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
pos | On input: an alignment field, if desired. On output: the offsets of the alignment field. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Format a double or long number using base-10 representation.
Currently sets status to U_UNSUPPORTED_ERROR.
number | The value to be formatted. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
posIter | On return, can be used to iterate over positions of fields generated by this format call. Can be NULL. |
status | Output param filled with success/failure status. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Format an int64 number using base-10 representation.
number | The value to be formatted. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
pos | On input: an alignment field, if desired. On output: the offsets of the alignment field. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Format an int64 number using base-10 representation.
Currently sets status to U_UNSUPPORTED_ERROR
number | The value to be formatted. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
posIter | On return, can be used to iterate over positions of fields generated by this format call. Can be NULL. |
status | Output param filled with success/failure status. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Format a decimal number.
Currently sets status to U_UNSUPPORTED_ERROR The syntax of the unformatted number is a "numeric string" as defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal
number | The unformatted number, as a string. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
posIter | On return, can be used to iterate over positions of fields generated by this format call. Can be NULL. |
status | Output param filled with success/failure status. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Format a decimal number.
Currently sets status to U_UNSUPPORTED_ERROR The number is a DigitList wrapper onto a floating point decimal number. The default implementation in NumberFormat converts the decimal number to a double and formats that.
number | The number, a DigitList format Decimal Floating Point. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
posIter | On return, can be used to iterate over positions of fields generated by this format call. |
status | Output param filled with success/failure status. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Format a decimal number.
Currently sets status to U_UNSUPPORTED_ERROR. The number is a DigitList wrapper onto a floating point decimal number. The default implementation in NumberFormat converts the decimal number to a double and formats that.
number | The number, a DigitList format Decimal Floating Point. |
appendTo | Output parameter to receive result. Result is appended to existing contents. |
pos | On input: an alignment field, if desired. On output: the offsets of the alignment field. |
status | Output param filled with success/failure status. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Returns a unique class ID POLYMORPHICALLY.
Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.
Reimplemented from icu::DecimalFormat.
|
static |
Return the class ID for this class.
This is useful only for comparing to a return value from getDynamicClassID(). For example:
. Base* polymorphic_pointer = createPolymorphicObject(); . if (polymorphic_pointer->getDynamicClassID() == . Derived::getStaticClassID()) ...
Reimplemented from icu::DecimalFormat.
CompactDecimalFormat& icu::CompactDecimalFormat::operator= | ( | const CompactDecimalFormat & | rhs | ) |
Assignment operator.
rhs | the DecimalFormat object to be copied. |
Return TRUE if the given Format objects are semantically equal.
Objects of different subclasses are considered unequal.
other | the object to be compared with. |
Reimplemented from icu::DecimalFormat.
|
virtual |
CompactDecimalFormat does not support parsing.
This implementation does nothing.
text | Unused. |
result | Does not change. |
parsePosition | Does not change. |
Reimplemented from icu::DecimalFormat.
|
virtual |
CompactDecimalFormat does not support parsing.
This implementation sets status to U_UNSUPPORTED_ERROR
text | Unused. |
result | Does not change. |
status | Always set to U_UNSUPPORTED_ERROR. |
Reimplemented from icu::DecimalFormat.
|
virtual |
Parses text from the given string as a currency amount.
Unlike the parse() method, this method will attempt to parse a generic currency name, searching for a match of this object's locale's currency display names, or for a 3-letter ISO currency code. This method will fail if this format is not a currency format, that is, if it does not contain the currency pattern symbol (U+00A4) in its prefix or suffix. This implementation always returns NULL.
text | the string to parse |
pos | 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. |
Reimplemented from icu::DecimalFormat.