#include <decimfmt.h>
Inheritance diagram for DecimalFormat:
Public Types | |
enum | ERoundingMode { kRoundCeiling, kRoundFloor, kRoundDown, kRoundUp, kRoundHalfEven, kRoundHalfDown, kRoundHalfUp } |
Rounding mode ICU 2.4. | |
enum | EPadPosition { kPadBeforePrefix, kPadAfterPrefix, kPadBeforeSuffix, kPadAfterSuffix } |
Pad position ICU 2.4. | |
Public Member Functions | |
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, 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 Format * | clone (void) 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 (int32_t number, UnicodeString &appendTo, FieldPosition &pos) const |
Format a 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 (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 void | parse (const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const |
Parse the given string using this object's choices. | |
virtual void | parse (const UnicodeString &text, Formattable &result, UErrorCode &status) const |
Parse the given string using this object's choices. | |
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. | |
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) |
Get the rounding increment. | |
virtual void | setRoundingIncrement (double newValue) |
Set the rounding increment. | |
virtual ERoundingMode | getRoundingMode (void) |
Get the rounding mode. | |
virtual void | setRoundingMode (ERoundingMode roundingMode) |
Set the rounding mode. | |
virtual int32_t | getFormatWidth (void) |
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 () |
Get the grapheme string (a character, possibly with modifier letters) used to pad to the format width. | |
virtual void | setPadCharacter (const UnicodeString &padChar) |
Set the grapheme string (a character, possibly with modifier letters) used to pad to the format width. | |
virtual EPadPosition | getPadPosition (void) |
Get the position at which padding will take place. | |
virtual void | setPadPosition (EPadPosition padPos) |
<font face="helvetica" color="red">NEW</font> 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) |
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. | |
virtual void | setCurrency (const UChar *theCurrency) |
Sets the currency used to display currency amounts. | |
virtual UClassID | getDynamicClassID (void) const |
Returns a unique class ID POLYMORPHICALLY. | |
Static Public Member Functions | |
UClassID | getStaticClassID (void) |
Return the class ID for this class. | |
Static Public Attributes | |
const char | fgNumberPatterns [] |
The resource tags we use to retrieve decimal format data from locale resource bundles. | |
Static Protected Attributes | |
const int32_t | kDoubleIntegerDigits |
number of integer digits ICU 2.4 | |
const int32_t | kDoubleFractionDigits |
number of fraction digits ICU 2.4 | |
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. |
Normally, you get the proper NumberFormat for a specific locale (including the default locale) using the NumberFormat factory methods, rather than constructing a DecimalNumberFormat directly.
Either the prefixes or the suffixes must be different for the parse to distinguish positive from negative. Parsing will be unreliable if the digits, thousands or decimal separators are the same, or if any of them occur in the prefixes or suffixes.
[Special cases:]
NaN is formatted as a single character, typically \uFFFD.
+/-Infinity is formatted as a single character, typically \u221E, plus the positive and negative pre/suffixes.
Note: this class is designed for common users; for very large or small numbers, use a format that can express exponential values.
[Example:]
[The following shows the structure of the pattern.]// normally we would have a GUI with a menu for this int32_t locCount; const Locale* locales = NumberFormat::getAvailableLocales(locCount); if (locCount > 12) locCount = 12; //limit output double myNumber = -1234.56; UErrorCode success = U_ZERO_ERROR; NumberFormat* form; //= NumberFormat::createInstance(success); // just for fun, we print out a number with the locale number, currency // and percent format for each locale we can. UnicodeString countryName; UnicodeString displayName; UnicodeString str; UnicodeString pattern; Formattable fmtable; for (int32_t j = 0; j < 3; ++j) { cout << endl << "FORMAT " << j << endl; for (int32_t i = 0; i < locCount; ++i) { if (locales[i].getCountry(countryName).size() == 0) { // skip language-only continue; } switch (j) { default: form = NumberFormat::createInstance(locales[i], success ); break; case 1: form = NumberFormat::createCurrencyInstance(locales[i], success ); break; case 0: form = NumberFormat::createPercentInstance(locales[i], success ); break; } if (form) { str.remove(); pattern = ((DecimalFormat*)form)->toPattern(pattern); cout << locales[i].getDisplayName(displayName) << ": " << pattern; cout << " -> " << form->format(myNumber,str) << endl; form->parse(form->format(myNumber,str), fmtable, success); //cout << " parsed: " << fmtable << endl; delete form; } } }
[Notes]pattern := subpattern{;subpattern} subpattern := {prefix}integer{.fraction}{suffix} prefix := '\\u0000'..'\\uFFFD' - specialCharacters suffix := '\\u0000'..'\\uFFFD' - specialCharacters integer := '#'* '0'* '0' fraction := '0'* '#'* Notation: X* 0 or more instances of X (X | Y) either X or Y. X..Y any character from X up to Y, inclusive. S - T characters in S, except those in T \code /pre> The first subpattern is for positive numbers. The second (optional) subpattern is used for negative numbers. (In both cases, ',' can occur inside the integer portion--it is just too messy to indicate in BNF.) For the second subpattern, only the PREFIX and SUFFIX are noted; other attributes are taken only from the first subpattern. <P> Here are the special characters used in the parts of the subpattern, with notes on their usage. <pre> \code Symbol Meaning 0 a digit, showing up a zero if it is zero # a digit, supressed if zero . placeholder for decimal separator , placeholder for grouping separator. E separates mantissa and exponent for exponential formats. ; separates formats. - default negative prefix. % multiply by 100 and show as percentage \u2030 multiply by 1000 and show as per mille \u00A4 currency sign; replaced by currency symbol; if doubled, replaced by international currency symbol. If present in a pattern, the monetary decimal separator is used instead of the decimal separator. X any other characters can be used in the prefix or suffix ' used to quote special characters in a prefix or suffix.
If there is no explicit negative subpattern, - is prefixed to the positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
Illegal formats, such as "#.#.#" in the same format, will cause a failing UErrorCode to be returned.
The grouping separator is commonly used for thousands, but in some countries for ten-thousands. The interval is a constant number of digits between the grouping characters, such as 100,000,000 or 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer determines the primary grouping size, and the interval between the last two determines the secondary grouping size (see below); all others are ignored. So "#,##,###,####" == "###,###,####" == "##,#,###,####".
Some locales have two different grouping intervals: One used for the least significant integer digits (the primary grouping size), and one used for all others (the secondary grouping size). For example, if the primary grouping interval is 3, and the secondary is 2, then this corresponds to the pattern "#,##,##0", and the number 123456789 is formatted as "12,34,56,789".
This class only handles localized digits where the 10 digits are contiguous in Unicode, from 0 to 9. Other digits sets (such as superscripts) would need a different subclass.
|
Create a DecimalFormat using the default pattern and symbols for the default locale. This is a convenient way to obtain a DecimalFormat when internationalization is not the main concern. To obtain standard formats for a given locale, use the factory methods on NumberFormat such as createInstance. These factories will return the most appropriate sub-class of NumberFormat for a given locale.
|
|
Create a DecimalFormat from the given pattern and the symbols for the default locale. This is a convenient way to obtain a DecimalFormat when internationalization is not the main concern. To obtain standard formats for a given locale, use the factory methods on NumberFormat such as createInstance. These factories will return the most appropriate sub-class of NumberFormat for a given locale.
|
|
Create a DecimalFormat from the given pattern and symbols. Use this constructor when you need to completely customize the behavior of the format. To obtain standard formats for a given locale, use the factory methods on NumberFormat such as createInstance or createCurrencyInstance. If you need only minor adjustments to a standard format, you can modify the format returned by a NumberFormat factory method.
|
|
Create a DecimalFormat from the given pattern and symbols. Use this constructor when you need to completely customize the behavior of the format. To obtain standard formats for a given locale, use the factory methods on NumberFormat such as createInstance or createCurrencyInstance. If you need only minor adjustments to a standard format, you can modify the format returned by a NumberFormat factory method.
|
|
Create a DecimalFormat from the given pattern and symbols. Use this constructor when you need to completely customize the behavior of the format. To obtain standard formats for a given locale, use the factory methods on NumberFormat such as createInstance or createCurrencyInstance. If you need only minor adjustments to a standard format, you can modify the format returned by a NumberFormat factory method.
|
|
Copy constructor.
|
|
Destructor. ICU 2.0 |
|
Sets the decimal format symbols, which is generally not changed by the programmer or user.
|
|
Apply the given pattern to this Format object.
|
|
Apply the given pattern to this Format object. The pattern is assumed to be in a localized notation. A pattern is a short-hand specification for the various formatting properties. These properties can also be changed individually through the various setter methods. There is no limit to integer digits are set by this routine, since that is the typical end-user desire; use setMaximumInteger if you want to set a real value. For negative numbers, use a second pattern, separated by a semicolon . Example "#,#00.0#" -> 1,234.56This means a minimum of 2 integer digits, 1 fraction digit, and a maximum of 2 fraction digits. Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses. In negative patterns, the minimum and maximum counts are ignored; these are presumed to be set in the positive pattern.
|
|
Sets the pattern.
|
|
Apply the given pattern to this Format object. A pattern is a short-hand specification for the various formatting properties. These properties can also be changed individually through the various setter methods. There is no limit to integer digits are set by this routine, since that is the typical end-user desire; use setMaximumInteger if you want to set a real value. For negative numbers, use a second pattern, separated by a semicolon . Example "#,#00.0#" -> 1,234.56This means a minimum of 2 integer digits, 1 fraction digit, and a maximum of 2 fraction digits. . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.In negative patterns, the minimum and maximum counts are ignored; these are presumed to be set in the positive pattern.
|
|
Clone this Format object polymorphically. The caller owns the result and should delete it when done.
Implements Format. |
|
Redeclared NumberFormat method. Format an int64 number. These methods call the NumberFormat pure virtual format() methods with the default FieldPosition.
Reimplemented from NumberFormat. |
|
Redeclared NumberFormat method. Format a long number. These methods call the NumberFormat pure virtual format() methods with the default FieldPosition.
Reimplemented from NumberFormat. |
|
Redeclared NumberFormat method. Format a double number.
Reimplemented from NumberFormat. |
|
Redeclared NumberFormat method. Formats an object to produce a string.
Reimplemented from NumberFormat. |
|
Format a Formattable using base-10 representation.
Reimplemented from NumberFormat. |
|
Format an int64 number using base-10 representation.
Reimplemented from NumberFormat. |
|
Format a long number using base-10 representation.
Implements NumberFormat. |
|
Format a double or long number using base-10 representation.
Implements NumberFormat. |
|
Returns the decimal format symbols, which is generally not changed by the programmer or user.
|
|
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.
Implements NumberFormat. |
|
Get the width to which the output of
|
|
Return the grouping size. Grouping size is the number of digits between grouping separators in the integer portion of a number. For example, in the number "123,456.78", the grouping size is 3.
|
|
Return the minimum exponent digits that will be shown.
|
|
Get the multiplier for use in percent, permill, etc. For a percentage, set the suffixes to have "%" and the multiplier to be 100. (For Arabic, use arabic percent symbol). For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000.
|
|
Get the negative prefix.
|
|
Get the negative suffix.
|
|
Get the grapheme string (a character, possibly with modifier letters) used to pad to the format width. The default is " ". Note: The current implementation only stores the first code unit of the pad string.
|
|
Get the position at which padding will take place.
This is the location at which padding will be inserted if the result of
|
|
Get the positive prefix.
|
|
Get the positive suffix.
|
|
Get the rounding increment.
|
|
Get the rounding mode.
|
|
Return the secondary grouping size.
In some locales one grouping interval is used for the least significant integer digits (the primary grouping size), and another is used for all others (the secondary grouping size). A formatter supporting a secondary grouping size will return a positive integer unequal to the primary grouping size returned by
|
|
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()) ...
|
|
Allows you to get the behavior of the decimal separator with integers. (The decimal separator will always appear with decimals.)
|
|
Return whether the exponent sign is always shown.
|
|
Return whether or not scientific notation is used.
|
|
Assignment operator.
|
|
Return true if the given Format objects are semantically equal. Objects of different subclasses are considered unequal.
Reimplemented from NumberFormat. |
|
Parse the given string using this object's choices.
Reimplemented from NumberFormat. |
|
Parse the given string using this object's choices.
The method does string comparisons to try to find an optimal match. If no object can be parsed, index is unchanged, and NULL is returned. The result is returned as the most parsimonious type of
Implements NumberFormat. |
|
Sets the currency used to display currency amounts. This takes effect immediately, if this format is a currency format. If this format is not a currency format, then the currency is used if and when this object becomes a currency format through the application of a new pattern.
Reimplemented from NumberFormat. |
|
Sets the decimal format symbols, which is generally not changed by the programmer or user.
|
|
Allows you to set the behavior of the decimal separator with integers. (The decimal separator will always appear with decimals.)
|
|
Set whether the exponent sign is always shown. This has no effect unless scientific notation is in use.
|
|
Set the width to which the output of This method also controls whether padding is enabled.
|
|
Set the grouping size. Grouping size is the number of digits between grouping separators in the integer portion of a number. For example, in the number "123,456.78", the grouping size is 3.
|
|
Sets the maximum number of digits allowed in the fraction portion of a number. This override limits the fraction digit count to 340.
Reimplemented from NumberFormat. |
|
Sets the maximum number of digits allowed in the integer portion of a number. This override limits the integer digit count to 309.
Reimplemented from NumberFormat. |
|
Set the minimum exponent digits that will be shown. This has no effect unless scientific notation is in use.
|
|
Sets the minimum number of digits allowed in the fraction portion of a number. This override limits the fraction digit count to 340.
Reimplemented from NumberFormat. |
|
Sets the minimum number of digits allowed in the integer portion of a number. This override limits the integer digit count to 309.
Reimplemented from NumberFormat. |
|
Set the multiplier for use in percent, permill, etc. For a percentage, set the suffixes to have "%" and the multiplier to be 100. (For Arabic, use arabic percent symbol). For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000.
|
|
Set the negative prefix.
|
|
Set the negative suffix.
|
|
Set the grapheme string (a character, possibly with modifier letters) used to pad to the format width. This has no effect unless padding is enabled. Note: The current implementation only stores the first code unit of the pad string.
|
|
<font face="helvetica" color="red">NEW</font> Set the position at which padding will take place.
This is the location at which padding will be inserted if the result of
|
|
Set the positive prefix.
|
|
Set the positive suffix.
|
|
Set the rounding increment. This method also controls whether rounding is enabled.
|
|
Set the rounding mode. This has no effect unless the rounding increment is greater than zero.
|
|
Set whether or not scientific notation is used. When scientific notation is used, the effective maximum number of integer digits is <= 8. If the maximum number of integer digits is set to more than 8, the effective maximum will be 1. This allows this call to generate a 'default' scientific number format without additional changes.
|
|
Set the secondary grouping size. If set to a value less than 1, then secondary grouping is turned off, and the primary grouping size is used for all intervals, not just the least significant.
|
|
Synthesizes a localized pattern string that represents the current state of this Format object.
|
|
Synthesizes a pattern string that represents the current state of this Format object.
|
|
The resource tags we use to retrieve decimal format data from locale resource bundles. ICU 2.0 |
|
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. We don't bother to track and see if someone is using exponential notation with more than this number, it wouldn't make sense anyway, and this is just to make sure that someone turning on scientific mode with default settings doesn't end up with lots of zeroes. |