• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ********************************************************************************
3 *   Copyright (C) 1997-2006, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 ********************************************************************************
6 *
7 * File DECIMFMT.H
8 *
9 * Modification History:
10 *
11 *   Date        Name        Description
12 *   02/19/97    aliu        Converted from java.
13 *   03/20/97    clhuang     Updated per C++ implementation.
14 *   04/03/97    aliu        Rewrote parsing and formatting completely, and
15 *                           cleaned up and debugged.  Actually works now.
16 *   04/17/97    aliu        Changed DigitCount to int per code review.
17 *   07/10/97    helena      Made ParsePosition a class and get rid of the function
18 *                           hiding problems.
19 *   09/09/97    aliu        Ported over support for exponential formats.
20 *    07/20/98    stephen        Changed documentation
21 ********************************************************************************
22 */
23 
24 #ifndef DECIMFMT_H
25 #define DECIMFMT_H
26 
27 #include "unicode/utypes.h"
28 /**
29  * \file
30  * \brief C++ API: Formats decimal numbers.
31  */
32 
33 #if !UCONFIG_NO_FORMATTING
34 
35 #include "unicode/dcfmtsym.h"
36 #include "unicode/numfmt.h"
37 #include "unicode/locid.h"
38 
39 U_NAMESPACE_BEGIN
40 
41 class DigitList;
42 class ChoiceFormat;
43 
44 /**
45  * DecimalFormat is a concrete subclass of NumberFormat that formats decimal
46  * numbers. It has a variety of features designed to make it possible to parse
47  * and format numbers in any locale, including support for Western, Arabic, or
48  * Indic digits.  It also supports different flavors of numbers, including
49  * integers ("123"), fixed-point numbers ("123.4"), scientific notation
50  * ("1.23E4"), percentages ("12%"), and currency amounts ("$123").  All of these
51  * flavors can be easily localized.
52  *
53  * <p>To obtain a NumberFormat for a specific locale (including the default
54  * locale) call one of NumberFormat's factory methods such as
55  * createInstance(). Do not call the DecimalFormat constructors directly, unless
56  * you know what you are doing, since the NumberFormat factory methods may
57  * return subclasses other than DecimalFormat.
58  *
59  * <p><strong>Example Usage</strong>
60  *
61  * \code
62  *     // Normally we would have a GUI with a menu for this
63  *     int32_t locCount;
64  *     const Locale* locales = NumberFormat::getAvailableLocales(locCount);
65  *
66  *     double myNumber = -1234.56;
67  *     UErrorCode success = U_ZERO_ERROR;
68  *     NumberFormat* form;
69  *
70  *     // Print out a number with the localized number, currency and percent
71  *     // format for each locale.
72  *     UnicodeString countryName;
73  *     UnicodeString displayName;
74  *     UnicodeString str;
75  *     UnicodeString pattern;
76  *     Formattable fmtable;
77  *     for (int32_t j = 0; j < 3; ++j) {
78  *         cout << endl << "FORMAT " << j << endl;
79  *         for (int32_t i = 0; i < locCount; ++i) {
80  *             if (locales[i].getCountry(countryName).size() == 0) {
81  *                 // skip language-only
82  *                 continue;
83  *             }
84  *             switch (j) {
85  *             case 0:
86  *                 form = NumberFormat::createInstance(locales[i], success ); break;
87  *             case 1:
88  *                 form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
89  *             default:
90  *                 form = NumberFormat::createPercentInstance(locales[i], success ); break;
91  *             }
92  *             if (form) {
93  *                 str.remove();
94  *                 pattern = ((DecimalFormat*)form)->toPattern(pattern);
95  *                 cout << locales[i].getDisplayName(displayName) << ": " << pattern;
96  *                 cout << "  ->  " << form->format(myNumber,str) << endl;
97  *                 form->parse(form->format(myNumber,str), fmtable, success);
98  *                 delete form;
99  *             }
100  *         }
101  *     }
102  * \endcode
103  *
104  * <p><strong>Patterns</strong>
105  *
106  * <p>A DecimalFormat consists of a <em>pattern</em> and a set of
107  * <em>symbols</em>.  The pattern may be set directly using
108  * applyPattern(), or indirectly using other API methods which
109  * manipulate aspects of the pattern, such as the minimum number of integer
110  * digits.  The symbols are stored in a DecimalFormatSymbols
111  * object.  When using the NumberFormat factory methods, the
112  * pattern and symbols are read from ICU's locale data.
113  *
114  * <p><strong>Special Pattern Characters</strong>
115  *
116  * <p>Many characters in a pattern are taken literally; they are matched during
117  * parsing and output unchanged during formatting.  Special characters, on the
118  * other hand, stand for other characters, strings, or classes of characters.
119  * For example, the '#' character is replaced by a localized digit.  Often the
120  * replacement character is the same as the pattern character; in the U.S. locale,
121  * the ',' grouping character is replaced by ','.  However, the replacement is
122  * still happening, and if the symbols are modified, the grouping character
123  * changes.  Some special characters affect the behavior of the formatter by
124  * their presence; for example, if the percent character is seen, then the
125  * value is multiplied by 100 before being displayed.
126  *
127  * <p>To insert a special character in a pattern as a literal, that is, without
128  * any special meaning, the character must be quoted.  There are some exceptions to
129  * this which are noted below.
130  *
131  * <p>The characters listed here are used in non-localized patterns.  Localized
132  * patterns use the corresponding characters taken from this formatter's
133  * DecimalFormatSymbols object instead, and these characters lose
134  * their special status.  Two exceptions are the currency sign and quote, which
135  * are not localized.
136  *
137  * <table border=0 cellspacing=3 cellpadding=0>
138  *   <tr bgcolor="#ccccff">
139  *     <td align=left><strong>Symbol</strong>
140  *     <td align=left><strong>Location</strong>
141  *     <td align=left><strong>Localized?</strong>
142  *     <td align=left><strong>Meaning</strong>
143  *   <tr valign=top>
144  *     <td><code>0</code>
145  *     <td>Number
146  *     <td>Yes
147  *     <td>Digit
148  *   <tr valign=top bgcolor="#eeeeff">
149  *     <td><code>1-9</code>
150  *     <td>Number
151  *     <td>Yes
152  *     <td>'1' through '9' indicate rounding.
153  *   <tr valign=top>
154  *     <td><code>\htmlonly&#x40;\endhtmlonly</code> <!--doxygen doesn't like @-->
155  *     <td>Number
156  *     <td>No
157  *     <td>Significant digit
158  *   <tr valign=top bgcolor="#eeeeff">
159  *     <td><code>#</code>
160  *     <td>Number
161  *     <td>Yes
162  *     <td>Digit, zero shows as absent
163  *   <tr valign=top>
164  *     <td><code>.</code>
165  *     <td>Number
166  *     <td>Yes
167  *     <td>Decimal separator or monetary decimal separator
168  *   <tr valign=top bgcolor="#eeeeff">
169  *     <td><code>-</code>
170  *     <td>Number
171  *     <td>Yes
172  *     <td>Minus sign
173  *   <tr valign=top>
174  *     <td><code>,</code>
175  *     <td>Number
176  *     <td>Yes
177  *     <td>Grouping separator
178  *   <tr valign=top bgcolor="#eeeeff">
179  *     <td><code>E</code>
180  *     <td>Number
181  *     <td>Yes
182  *     <td>Separates mantissa and exponent in scientific notation.
183  *         <em>Need not be quoted in prefix or suffix.</em>
184  *   <tr valign=top>
185  *     <td><code>+</code>
186  *     <td>Exponent
187  *     <td>Yes
188  *     <td>Prefix positive exponents with localized plus sign.
189  *         <em>Need not be quoted in prefix or suffix.</em>
190  *   <tr valign=top bgcolor="#eeeeff">
191  *     <td><code>;</code>
192  *     <td>Subpattern boundary
193  *     <td>Yes
194  *     <td>Separates positive and negative subpatterns
195  *   <tr valign=top>
196  *     <td><code>\%</code>
197  *     <td>Prefix or suffix
198  *     <td>Yes
199  *     <td>Multiply by 100 and show as percentage
200  *   <tr valign=top bgcolor="#eeeeff">
201  *     <td><code>\\u2030</code>
202  *     <td>Prefix or suffix
203  *     <td>Yes
204  *     <td>Multiply by 1000 and show as per mille
205  *   <tr valign=top>
206  *     <td><code>\htmlonly&curren;\endhtmlonly</code> (<code>\\u00A4</code>)
207  *     <td>Prefix or suffix
208  *     <td>No
209  *     <td>Currency sign, replaced by currency symbol.  If
210  *         doubled, replaced by international currency symbol.
211  *         If present in a pattern, the monetary decimal separator
212  *         is used instead of the decimal separator.
213  *   <tr valign=top bgcolor="#eeeeff">
214  *     <td><code>'</code>
215  *     <td>Prefix or suffix
216  *     <td>No
217  *     <td>Used to quote special characters in a prefix or suffix,
218  *         for example, <code>"'#'#"</code> formats 123 to
219  *         <code>"#123"</code>.  To create a single quote
220  *         itself, use two in a row: <code>"# o''clock"</code>.
221  *   <tr valign=top>
222  *     <td><code>*</code>
223  *     <td>Prefix or suffix boundary
224  *     <td>Yes
225  *     <td>Pad escape, precedes pad character
226  * </table>
227  *
228  * <p>A DecimalFormat pattern contains a postive and negative
229  * subpattern, for example, "#,##0.00;(#,##0.00)".  Each subpattern has a
230  * prefix, a numeric part, and a suffix.  If there is no explicit negative
231  * subpattern, the negative subpattern is the localized minus sign prefixed to the
232  * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00".  If there
233  * is an explicit negative subpattern, it serves only to specify the negative
234  * prefix and suffix; the number of digits, minimal digits, and other
235  * characteristics are ignored in the negative subpattern. That means that
236  * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
237  *
238  * <p>The prefixes, suffixes, and various symbols used for infinity, digits,
239  * thousands separators, decimal separators, etc. may be set to arbitrary
240  * values, and they will appear properly during formatting.  However, care must
241  * be taken that the symbols and strings do not conflict, or parsing will be
242  * unreliable.  For example, either the positive and negative prefixes or the
243  * suffixes must be distinct for parse() to be able
244  * to distinguish positive from negative values.  Another example is that the
245  * decimal separator and thousands separator should be distinct characters, or
246  * parsing will be impossible.
247  *
248  * <p>The <em>grouping separator</em> is a character that separates clusters of
249  * integer digits to make large numbers more legible.  It commonly used for
250  * thousands, but in some locales it separates ten-thousands.  The <em>grouping
251  * size</em> is the number of digits between the grouping separators, such as 3
252  * for "100,000,000" or 4 for "1 0000 0000". There are actually two different
253  * grouping sizes: One used for the least significant integer digits, the
254  * <em>primary grouping size</em>, and one used for all others, the
255  * <em>secondary grouping size</em>.  In most locales these are the same, but
256  * sometimes they are different. For example, if the primary grouping interval
257  * is 3, and the secondary is 2, then this corresponds to the pattern
258  * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789".  If a
259  * pattern contains multiple grouping separators, the interval between the last
260  * one and the end of the integer defines the primary grouping size, and the
261  * interval between the last two defines the secondary grouping size. All others
262  * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
263  *
264  * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
265  * DecimalFormat to set a failing UErrorCode.
266  *
267  * <p><strong>Pattern BNF</strong>
268  *
269  * <pre>
270  * pattern    := subpattern (';' subpattern)?
271  * subpattern := prefix? number exponent? suffix?
272  * number     := (integer ('.' fraction)?) | sigDigits
273  * prefix     := '\\u0000'..'\\uFFFD' - specialCharacters
274  * suffix     := '\\u0000'..'\\uFFFD' - specialCharacters
275  * integer    := '#'* '0'* '0'
276  * fraction   := '0'* '#'*
277  * sigDigits  := '#'* '@' '@'* '#'*
278  * exponent   := 'E' '+'? '0'* '0'
279  * padSpec    := '*' padChar
280  * padChar    := '\\u0000'..'\\uFFFD' - quote
281  * &nbsp;
282  * Notation:
283  *   X*       0 or more instances of X
284  *   X?       0 or 1 instances of X
285  *   X|Y      either X or Y
286  *   C..D     any character from C up to D, inclusive
287  *   S-T      characters in S, except those in T
288  * </pre>
289  * The first subpattern is for positive numbers. The second (optional)
290  * subpattern is for negative numbers.
291  *
292  * <p>Not indicated in the BNF syntax above:
293  *
294  * <ul><li>The grouping separator ',' can occur inside the integer and
295  * sigDigits elements, between any two pattern characters of that
296  * element, as long as the integer or sigDigits element is not
297  * followed by the exponent element.
298  *
299  * <li>Two grouping intervals are recognized: That between the
300  *     decimal point and the first grouping symbol, and that
301  *     between the first and second grouping symbols. These
302  *     intervals are identical in most locales, but in some
303  *     locales they differ. For example, the pattern
304  *     &quot;#,##,###&quot; formats the number 123456789 as
305  *     &quot;12,34,56,789&quot;.</li>
306  *
307  * <li>The pad specifier <code>padSpec</code> may appear before the prefix,
308  * after the prefix, before the suffix, after the suffix, or not at all.
309  *
310  * <li>In place of '0', the digits '1' through '9' may be used to
311  * indicate a rounding increment.
312  * </ul>
313  *
314  * <p><strong>Parsing</strong>
315  *
316  * <p>DecimalFormat parses all Unicode characters that represent
317  * decimal digits, as defined by u_charDigitValue().  In addition,
318  * DecimalFormat also recognizes as digits the ten consecutive
319  * characters starting with the localized zero digit defined in the
320  * DecimalFormatSymbols object.  During formatting, the
321  * DecimalFormatSymbols-based digits are output.
322  *
323  * <p>During parsing, grouping separators are ignored.
324  *
325  * <p>If parse(UnicodeString&,Formattable&,ParsePosition&)
326  * fails to parse a string, it leaves the parse position unchanged.
327  * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&)
328  * indicates parse failure by setting a failing
329  * UErrorCode.
330  *
331  * <p><strong>Formatting</strong>
332  *
333  * <p>Formatting is guided by several parameters, all of which can be
334  * specified either using a pattern or using the API.  The following
335  * description applies to formats that do not use <a href="#sci">scientific
336  * notation</a> or <a href="#sigdig">significant digits</a>.
337  *
338  * <ul><li>If the number of actual integer digits exceeds the
339  * <em>maximum integer digits</em>, then only the least significant
340  * digits are shown.  For example, 1997 is formatted as "97" if the
341  * maximum integer digits is set to 2.
342  *
343  * <li>If the number of actual integer digits is less than the
344  * <em>minimum integer digits</em>, then leading zeros are added.  For
345  * example, 1997 is formatted as "01997" if the minimum integer digits
346  * is set to 5.
347  *
348  * <li>If the number of actual fraction digits exceeds the <em>maximum
349  * fraction digits</em>, then half-even rounding it performed to the
350  * maximum fraction digits.  For example, 0.125 is formatted as "0.12"
351  * if the maximum fraction digits is 2.  This behavior can be changed
352  * by specifying a rounding increment and a rounding mode.
353  *
354  * <li>If the number of actual fraction digits is less than the
355  * <em>minimum fraction digits</em>, then trailing zeros are added.
356  * For example, 0.125 is formatted as "0.1250" if the mimimum fraction
357  * digits is set to 4.
358  *
359  * <li>Trailing fractional zeros are not displayed if they occur
360  * <em>j</em> positions after the decimal, where <em>j</em> is less
361  * than the maximum fraction digits. For example, 0.10004 is
362  * formatted as "0.1" if the maximum fraction digits is four or less.
363  * </ul>
364  *
365  * <p><strong>Special Values</strong>
366  *
367  * <p><code>NaN</code> is represented as a single character, typically
368  * <code>\\uFFFD</code>.  This character is determined by the
369  * DecimalFormatSymbols object.  This is the only value for which
370  * the prefixes and suffixes are not used.
371  *
372  * <p>Infinity is represented as a single character, typically
373  * <code>\\u221E</code>, with the positive or negative prefixes and suffixes
374  * applied.  The infinity character is determined by the
375  * DecimalFormatSymbols object.
376  *
377  * <a name="sci"><strong>Scientific Notation</strong></a>
378  *
379  * <p>Numbers in scientific notation are expressed as the product of a mantissa
380  * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The
381  * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0),
382  * but it need not be.  DecimalFormat supports arbitrary mantissas.
383  * DecimalFormat can be instructed to use scientific
384  * notation through the API or through the pattern.  In a pattern, the exponent
385  * character immediately followed by one or more digit characters indicates
386  * scientific notation.  Example: "0.###E0" formats the number 1234 as
387  * "1.234E3".
388  *
389  * <ul>
390  * <li>The number of digit characters after the exponent character gives the
391  * minimum exponent digit count.  There is no maximum.  Negative exponents are
392  * formatted using the localized minus sign, <em>not</em> the prefix and suffix
393  * from the pattern.  This allows patterns such as "0.###E0 m/s".  To prefix
394  * positive exponents with a localized plus sign, specify '+' between the
395  * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0",
396  * "1E-1", etc.  (In localized patterns, use the localized plus sign rather than
397  * '+'.)
398  *
399  * <li>The minimum number of integer digits is achieved by adjusting the
400  * exponent.  Example: 0.00123 formatted with "00.###E0" yields "12.3E-4".  This
401  * only happens if there is no maximum number of integer digits.  If there is a
402  * maximum, then the minimum number of integer digits is fixed at one.
403  *
404  * <li>The maximum number of integer digits, if present, specifies the exponent
405  * grouping.  The most common use of this is to generate <em>engineering
406  * notation</em>, in which the exponent is a multiple of three, e.g.,
407  * "##0.###E0".  The number 12345 is formatted using "##0.####E0" as "12.345E3".
408  *
409  * <li>When using scientific notation, the formatter controls the
410  * digit counts using significant digits logic.  The maximum number of
411  * significant digits limits the total number of integer and fraction
412  * digits that will be shown in the mantissa; it does not affect
413  * parsing.  For example, 12345 formatted with "##0.##E0" is "12.3E3".
414  * See the section on significant digits for more details.
415  *
416  * <li>The number of significant digits shown is determined as
417  * follows: If areSignificantDigitsUsed() returns false, then the
418  * minimum number of significant digits shown is one, and the maximum
419  * number of significant digits shown is the sum of the <em>minimum
420  * integer</em> and <em>maximum fraction</em> digits, and is
421  * unaffected by the maximum integer digits.  If this sum is zero,
422  * then all significant digits are shown.  If
423  * areSignificantDigitsUsed() returns true, then the significant digit
424  * counts are specified by getMinimumSignificantDigits() and
425  * getMaximumSignificantDigits().  In this case, the number of
426  * integer digits is fixed at one, and there is no exponent grouping.
427  *
428  * <li>Exponential patterns may not contain grouping separators.
429  * </ul>
430  *
431  * <a name="sigdig"><strong>Significant Digits</strong></a>
432  *
433  * <code>DecimalFormat</code> has two ways of controlling how many
434  * digits are shows: (a) significant digits counts, or (b) integer and
435  * fraction digit counts.  Integer and fraction digit counts are
436  * described above.  When a formatter is using significant digits
437  * counts, the number of integer and fraction digits is not specified
438  * directly, and the formatter settings for these counts are ignored.
439  * Instead, the formatter uses however many integer and fraction
440  * digits are required to display the specified number of significant
441  * digits.  Examples:
442  *
443  * <table border=0 cellspacing=3 cellpadding=0>
444  *   <tr bgcolor="#ccccff">
445  *     <td align=left>Pattern
446  *     <td align=left>Minimum significant digits
447  *     <td align=left>Maximum significant digits
448  *     <td align=left>Number
449  *     <td align=left>Output of format()
450  *   <tr valign=top>
451  *     <td><code>\@\@\@</code>
452  *     <td>3
453  *     <td>3
454  *     <td>12345
455  *     <td><code>12300</code>
456  *   <tr valign=top bgcolor="#eeeeff">
457  *     <td><code>\@\@\@</code>
458  *     <td>3
459  *     <td>3
460  *     <td>0.12345
461  *     <td><code>0.123</code>
462  *   <tr valign=top>
463  *     <td><code>\@\@##</code>
464  *     <td>2
465  *     <td>4
466  *     <td>3.14159
467  *     <td><code>3.142</code>
468  *   <tr valign=top bgcolor="#eeeeff">
469  *     <td><code>\@\@##</code>
470  *     <td>2
471  *     <td>4
472  *     <td>1.23004
473  *     <td><code>1.23</code>
474  * </table>
475  *
476  * <ul>
477  * <li>Significant digit counts may be expressed using patterns that
478  * specify a minimum and maximum number of significant digits.  These
479  * are indicated by the <code>'@'</code> and <code>'#'</code>
480  * characters.  The minimum number of significant digits is the number
481  * of <code>'@'</code> characters.  The maximum number of significant
482  * digits is the number of <code>'@'</code> characters plus the number
483  * of <code>'#'</code> characters following on the right.  For
484  * example, the pattern <code>"@@@"</code> indicates exactly 3
485  * significant digits.  The pattern <code>"@##"</code> indicates from
486  * 1 to 3 significant digits.  Trailing zero digits to the right of
487  * the decimal separator are suppressed after the minimum number of
488  * significant digits have been shown.  For example, the pattern
489  * <code>"@##"</code> formats the number 0.1203 as
490  * <code>"0.12"</code>.
491  *
492  * <li>If a pattern uses significant digits, it may not contain a
493  * decimal separator, nor the <code>'0'</code> pattern character.
494  * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are
495  * disallowed.
496  *
497  * <li>Any number of <code>'#'</code> characters may be prepended to
498  * the left of the leftmost <code>'@'</code> character.  These have no
499  * effect on the minimum and maximum significant digits counts, but
500  * may be used to position grouping separators.  For example,
501  * <code>"#,#@#"</code> indicates a minimum of one significant digits,
502  * a maximum of two significant digits, and a grouping size of three.
503  *
504  * <li>In order to enable significant digits formatting, use a pattern
505  * containing the <code>'@'</code> pattern character.  Alternatively,
506  * call setSignificantDigitsUsed(TRUE).
507  *
508  * <li>In order to disable significant digits formatting, use a
509  * pattern that does not contain the <code>'@'</code> pattern
510  * character. Alternatively, call setSignificantDigitsUsed(FALSE).
511  *
512  * <li>The number of significant digits has no effect on parsing.
513  *
514  * <li>Significant digits may be used together with exponential notation. Such
515  * patterns are equivalent to a normal exponential pattern with a minimum and
516  * maximum integer digit count of one, a minimum fraction digit count of
517  * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit
518  * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the
519  * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>.
520  *
521  * <li>If signficant digits are in use, then the integer and fraction
522  * digit counts, as set via the API, are ignored.  If significant
523  * digits are not in use, then the signficant digit counts, as set via
524  * the API, are ignored.
525  *
526  * </ul>
527  *
528  * <p><strong>Padding</strong>
529  *
530  * <p>DecimalFormat supports padding the result of
531  * format() to a specific width.  Padding may be specified either
532  * through the API or through the pattern syntax.  In a pattern the pad escape
533  * character, followed by a single pad character, causes padding to be parsed
534  * and formatted.  The pad escape character is '*' in unlocalized patterns, and
535  * can be localized using DecimalFormatSymbols::setSymbol() with a
536  * DecimalFormatSymbols::kPadEscapeSymbol
537  * selector.  For example, <code>"$*x#,##0.00"</code> formats 123 to
538  * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>.
539  *
540  * <ul>
541  * <li>When padding is in effect, the width of the positive subpattern,
542  * including prefix and suffix, determines the format width.  For example, in
543  * the pattern <code>"* #0 o''clock"</code>, the format width is 10.
544  *
545  * <li>The width is counted in 16-bit code units (UChars).
546  *
547  * <li>Some parameters which usually do not matter have meaning when padding is
548  * used, because the pattern width is significant with padding.  In the pattern
549  * "* ##,##,#,##0.##", the format width is 14.  The initial characters "##,##,"
550  * do not affect the grouping size or maximum integer digits, but they do affect
551  * the format width.
552  *
553  * <li>Padding may be inserted at one of four locations: before the prefix,
554  * after the prefix, before the suffix, or after the suffix.  If padding is
555  * specified in any other location, applyPattern()
556  * sets a failing UErrorCode.  If there is no prefix,
557  * before the prefix and after the prefix are equivalent, likewise for the
558  * suffix.
559  *
560  * <li>When specified in a pattern, the 32-bit code point immediately
561  * following the pad escape is the pad character. This may be any character,
562  * including a special pattern character. That is, the pad escape
563  * <em>escapes</em> the following character. If there is no character after
564  * the pad escape, then the pattern is illegal.
565  *
566  * </ul>
567  *
568  * <p><strong>Rounding</strong>
569  *
570  * <p>DecimalFormat supports rounding to a specific increment.  For
571  * example, 1230 rounded to the nearest 50 is 1250.  1.234 rounded to the
572  * nearest 0.65 is 1.3.  The rounding increment may be specified through the API
573  * or in a pattern.  To specify a rounding increment in a pattern, include the
574  * increment in the pattern itself.  "#,#50" specifies a rounding increment of
575  * 50.  "#,##0.05" specifies a rounding increment of 0.05.
576  *
577  * <ul>
578  * <li>Rounding only affects the string produced by formatting.  It does
579  * not affect parsing or change any numerical values.
580  *
581  * <li>A <em>rounding mode</em> determines how values are rounded; see
582  * DecimalFormat::ERoundingMode.  Rounding increments specified in
583  * patterns use the default mode, DecimalFormat::kRoundHalfEven.
584  *
585  * <li>Some locales use rounding in their currency formats to reflect the
586  * smallest currency denomination.
587  *
588  * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
589  * behave identically to digit '0'.
590  * </ul>
591  *
592  * <p><strong>Synchronization</strong>
593  *
594  * <p>DecimalFormat objects are not synchronized.  Multiple
595  * threads should not access one formatter concurrently.
596  *
597  * <p><strong>Subclassing</strong>
598  *
599  * <p><em>User subclasses are not supported.</em> While clients may write
600  * subclasses, such code will not necessarily work and will not be
601  * guaranteed to work stably from release to release.
602  */
603 class U_I18N_API DecimalFormat: public NumberFormat {
604 public:
605     /**
606      * Rounding mode.
607      * @stable ICU 2.4
608      */
609     enum ERoundingMode {
610         kRoundCeiling,  /**< Round towards positive infinity */
611         kRoundFloor,    /**< Round towards negative infinity */
612         kRoundDown,     /**< Round towards zero */
613         kRoundUp,       /**< Round away from zero */
614         kRoundHalfEven, /**< Round towards the nearest integer, or
615                              towards the nearest even integer if equidistant */
616         kRoundHalfDown, /**< Round towards the nearest integer, or
617                              towards zero if equidistant */
618         kRoundHalfUp    /**< Round towards the nearest integer, or
619                              away from zero if equidistant */
620         // We don't support ROUND_UNNECESSARY
621     };
622 
623     /**
624      * Pad position.
625      * @stable ICU 2.4
626      */
627     enum EPadPosition {
628         kPadBeforePrefix,
629         kPadAfterPrefix,
630         kPadBeforeSuffix,
631         kPadAfterSuffix
632     };
633 
634     typedef struct attributeBuffer {
635         char * buffer;
636         size_t bufferSize;
637     } AttributeBuffer, *AttrBuffer;
638 
639     /**
640      * Create a DecimalFormat using the default pattern and symbols
641      * for the default locale. This is a convenient way to obtain a
642      * DecimalFormat when internationalization is not the main concern.
643      * <P>
644      * To obtain standard formats for a given locale, use the factory methods
645      * on NumberFormat such as createInstance. These factories will
646      * return the most appropriate sub-class of NumberFormat for a given
647      * locale.
648      * @param status    Output param set to success/failure code. If the
649      *                  pattern is invalid this will be set to a failure code.
650      * @stable ICU 2.0
651      */
652     DecimalFormat(UErrorCode& status);
653 
654     /**
655      * Create a DecimalFormat from the given pattern and the symbols
656      * for the default locale. This is a convenient way to obtain a
657      * DecimalFormat when internationalization is not the main concern.
658      * <P>
659      * To obtain standard formats for a given locale, use the factory methods
660      * on NumberFormat such as createInstance. These factories will
661      * return the most appropriate sub-class of NumberFormat for a given
662      * locale.
663      * @param pattern   A non-localized pattern string.
664      * @param status    Output param set to success/failure code. If the
665      *                  pattern is invalid this will be set to a failure code.
666      * @stable ICU 2.0
667      */
668     DecimalFormat(const UnicodeString& pattern,
669                   UErrorCode& status);
670 
671     /**
672      * Create a DecimalFormat from the given pattern and symbols.
673      * Use this constructor when you need to completely customize the
674      * behavior of the format.
675      * <P>
676      * To obtain standard formats for a given
677      * locale, use the factory methods on NumberFormat such as
678      * createInstance or createCurrencyInstance. If you need only minor adjustments
679      * to a standard format, you can modify the format returned by
680      * a NumberFormat factory method.
681      *
682      * @param pattern           a non-localized pattern string
683      * @param symbolsToAdopt    the set of symbols to be used.  The caller should not
684      *                          delete this object after making this call.
685      * @param status            Output param set to success/failure code. If the
686      *                          pattern is invalid this will be set to a failure code.
687      * @stable ICU 2.0
688      */
689     DecimalFormat(  const UnicodeString& pattern,
690                     DecimalFormatSymbols* symbolsToAdopt,
691                     UErrorCode& status);
692 
693     /**
694      * Create a DecimalFormat from the given pattern and symbols.
695      * Use this constructor when you need to completely customize the
696      * behavior of the format.
697      * <P>
698      * To obtain standard formats for a given
699      * locale, use the factory methods on NumberFormat such as
700      * createInstance or createCurrencyInstance. If you need only minor adjustments
701      * to a standard format, you can modify the format returned by
702      * a NumberFormat factory method.
703      *
704      * @param pattern           a non-localized pattern string
705      * @param symbolsToAdopt    the set of symbols to be used.  The caller should not
706      *                          delete this object after making this call.
707      * @param parseError        Output param to receive errors occured during parsing
708      * @param status            Output param set to success/failure code. If the
709      *                          pattern is invalid this will be set to a failure code.
710      * @stable ICU 2.0
711      */
712     DecimalFormat(  const UnicodeString& pattern,
713                     DecimalFormatSymbols* symbolsToAdopt,
714                     UParseError& parseError,
715                     UErrorCode& status);
716     /**
717      * Create a DecimalFormat from the given pattern and symbols.
718      * Use this constructor when you need to completely customize the
719      * behavior of the format.
720      * <P>
721      * To obtain standard formats for a given
722      * locale, use the factory methods on NumberFormat such as
723      * createInstance or createCurrencyInstance. If you need only minor adjustments
724      * to a standard format, you can modify the format returned by
725      * a NumberFormat factory method.
726      *
727      * @param pattern           a non-localized pattern string
728      * @param symbols   the set of symbols to be used
729      * @param status            Output param set to success/failure code. If the
730      *                          pattern is invalid this will be set to a failure code.
731      * @stable ICU 2.0
732      */
733     DecimalFormat(  const UnicodeString& pattern,
734                     const DecimalFormatSymbols& symbols,
735                     UErrorCode& status);
736 
737     /**
738      * Copy constructor.
739      *
740      * @param source    the DecimalFormat object to be copied from.
741      * @stable ICU 2.0
742      */
743     DecimalFormat(const DecimalFormat& source);
744 
745     /**
746      * Assignment operator.
747      *
748      * @param rhs    the DecimalFormat object to be copied.
749      * @stable ICU 2.0
750      */
751     DecimalFormat& operator=(const DecimalFormat& rhs);
752 
753     /**
754      * Destructor.
755      * @stable ICU 2.0
756      */
757     virtual ~DecimalFormat();
758 
759     /**
760      * Clone this Format object polymorphically. The caller owns the
761      * result and should delete it when done.
762      *
763      * @return    a polymorphic copy of this DecimalFormat.
764      * @stable ICU 2.0
765      */
766     virtual Format* clone(void) const;
767 
768     /**
769      * Return true if the given Format objects are semantically equal.
770      * Objects of different subclasses are considered unequal.
771      *
772      * @param other    the object to be compared with.
773      * @return         true if the given Format objects are semantically equal.
774      * @stable ICU 2.0
775      */
776     virtual UBool operator==(const Format& other) const;
777 
778     /**
779      * Format a double or long number using base-10 representation.
780      *
781      * @param number    The value to be formatted.
782      * @param appendTo  Output parameter to receive result.
783      *                  Result is appended to existing contents.
784      * @param pos       On input: an alignment field, if desired.
785      *                  On output: the offsets of the alignment field.
786      * @return          Reference to 'appendTo' parameter.
787      * @stable ICU 2.0
788     */
789     virtual UnicodeString& format(double number,
790                                   UnicodeString& appendTo,
791                                   FieldPosition& pos) const;
792 
793     virtual UnicodeString& format(double number,
794                                   UnicodeString& appendTo,
795                                   FieldPosition& pos,
796                                   AttrBuffer attrBuffer) const;
797 
798     /**
799      * Format a long number using base-10 representation.
800      *
801      * @param number    The value to be formatted.
802      * @param appendTo  Output parameter to receive result.
803      *                  Result is appended to existing contents.
804      * @param pos       On input: an alignment field, if desired.
805      *                  On output: the offsets of the alignment field.
806      * @return          Reference to 'appendTo' parameter.
807      * @stable ICU 2.0
808      */
809     virtual UnicodeString& format(int32_t number,
810                                   UnicodeString& appendTo,
811                                   FieldPosition& pos) const;
812 
813     virtual UnicodeString& format(int32_t number,
814                                   UnicodeString& appendTo,
815                                   FieldPosition& pos,
816                                   AttrBuffer attrBuffer) const;
817 
818     /**
819      * Format an int64 number using base-10 representation.
820      *
821      * @param number    The value to be formatted.
822      * @param appendTo  Output parameter to receive result.
823      *                  Result is appended to existing contents.
824      * @param pos       On input: an alignment field, if desired.
825      *                  On output: the offsets of the alignment field.
826      * @return          Reference to 'appendTo' parameter.
827      * @stable ICU 2.8
828      */
829     virtual UnicodeString& format(int64_t number,
830                                   UnicodeString& appendTo,
831                                   FieldPosition& pos) const;
832 
833     virtual UnicodeString& format(int64_t number,
834                                   UnicodeString& appendTo,
835                                   FieldPosition& pos,
836                                   AttrBuffer attrBuffer) const;
837 
838     /**
839      * Format a Formattable using base-10 representation.
840      *
841      * @param obj       The value to be formatted.
842      * @param appendTo  Output parameter to receive result.
843      *                  Result is appended to existing contents.
844      * @param pos       On input: an alignment field, if desired.
845      *                  On output: the offsets of the alignment field.
846      * @param status    Error code indicating success or failure.
847      * @return          Reference to 'appendTo' parameter.
848      * @stable ICU 2.0
849      */
850     virtual UnicodeString& format(const Formattable& obj,
851                                   UnicodeString& appendTo,
852                                   FieldPosition& pos,
853                                   UErrorCode& status) const;
854 
855     /**
856      * Redeclared NumberFormat method.
857      * Formats an object to produce a string.
858      *
859      * @param obj       The object to format.
860      * @param appendTo  Output parameter to receive result.
861      *                  Result is appended to existing contents.
862      * @param status    Output parameter filled in with success or failure status.
863      * @return          Reference to 'appendTo' parameter.
864      * @stable ICU 2.0
865      */
866     UnicodeString& format(const Formattable& obj,
867                           UnicodeString& appendTo,
868                           UErrorCode& status) const;
869 
870     /**
871      * Redeclared NumberFormat method.
872      * Format a double number.
873      *
874      * @param number    The value to be formatted.
875      * @param appendTo  Output parameter to receive result.
876      *                  Result is appended to existing contents.
877      * @return          Reference to 'appendTo' parameter.
878      * @stable ICU 2.0
879      */
880     UnicodeString& format(double number,
881                           UnicodeString& appendTo) const;
882 
883     /**
884      * Redeclared NumberFormat method.
885      * Format a long number. These methods call the NumberFormat
886      * pure virtual format() methods with the default FieldPosition.
887      *
888      * @param number    The value to be formatted.
889      * @param appendTo  Output parameter to receive result.
890      *                  Result is appended to existing contents.
891      * @return          Reference to 'appendTo' parameter.
892      * @stable ICU 2.0
893      */
894     UnicodeString& format(int32_t number,
895                           UnicodeString& appendTo) const;
896 
897     /**
898      * Redeclared NumberFormat method.
899      * Format an int64 number. These methods call the NumberFormat
900      * pure virtual format() methods with the default FieldPosition.
901      *
902      * @param number    The value to be formatted.
903      * @param appendTo  Output parameter to receive result.
904      *                  Result is appended to existing contents.
905      * @return          Reference to 'appendTo' parameter.
906      * @stable ICU 2.8
907      */
908     UnicodeString& format(int64_t number,
909                           UnicodeString& appendTo) const;
910 
911     // BEGIN android-added
912     UnicodeString& subformat(UnicodeString& appendTo,
913                              FieldPosition& fieldPosition,
914                              AttrBuffer attrBuffer,
915                              DigitList& digits,
916                              UBool         isInteger) const;
917     // END android-changed
918 
919    /**
920     * Parse the given string using this object's choices. The method
921     * does string comparisons to try to find an optimal match.
922     * If no object can be parsed, index is unchanged, and NULL is
923     * returned.  The result is returned as the most parsimonious
924     * type of Formattable that will accomodate all of the
925     * necessary precision.  For example, if the result is exactly 12,
926     * it will be returned as a long.  However, if it is 1.5, it will
927     * be returned as a double.
928     *
929     * @param text           The text to be parsed.
930     * @param result         Formattable to be set to the parse result.
931     *                       If parse fails, return contents are undefined.
932     * @param parsePosition  The position to start parsing at on input.
933     *                       On output, moved to after the last successfully
934     *                       parse character. On parse failure, does not change.
935     * @see Formattable
936     * @stable ICU 2.0
937     */
938     virtual void parse(const UnicodeString& text,
939                        Formattable& result,
940                        ParsePosition& parsePosition) const;
941 
942     // Declare here again to get rid of function hiding problems.
943     /**
944      * Parse the given string using this object's choices.
945      *
946      * @param text           The text to be parsed.
947      * @param result         Formattable to be set to the parse result.
948      * @param status    Output parameter filled in with success or failure status.
949      * @stable ICU 2.0
950      */
951     virtual void parse(const UnicodeString& text,
952                        Formattable& result,
953                        UErrorCode& status) const;
954 
955     // BEGIN android-added
956     // A way to access parsing directly as workaround for missing
957     // BigNum parsing
958     /**
959      * Parses the given text as either a number or a currency amount.
960      * @param text the string to parse
961      * @param resultAssigned indicates whether or not the param result is assigned
962      * @param result output parameter for the result
963      *    ATTENTION: result is assigned ONLY for types long and int64
964      * @param parsePosition input-output position; on input, the
965      * position within text to match; must have 0 <= pos.getIndex() <
966      * text.length(); on output, the position after the last matched
967      * character. If the parse fails, the position in unchanged upon
968      * output.
969      * @param parseCurrency if true, a currency amount is parsed;
970      * otherwise a Number is parsed
971      * @param digits The DigitList that represents the result will be returned
972      * @param scale the scale with which the number in the DigitList
973      * has to be scaled
974     *    ATTENTION: list and scale are only returned when result was not assigned
975      */
976     virtual void parse(const UnicodeString& text,
977                        bool& resultAssigned,
978                        Formattable& result,
979                        ParsePosition& parsePosition,
980                        UBool parseCurrency,
981                        DigitList& digits) const;
982     // END android-added
983 
984     /**
985      * Parses text from the given string as a currency amount.  Unlike
986      * the parse() method, this method will attempt to parse a generic
987      * currency name, searching for a match of this object's locale's
988      * currency display names, or for a 3-letter ISO currency code.
989      * This method will fail if this format is not a currency format,
990      * that is, if it does not contain the currency pattern symbol
991      * (U+00A4) in its prefix or suffix.
992      *
993      * @param text the string to parse
994      * @param result output parameter to receive result. This will have
995      * its currency set to the parsed ISO currency code.
996      * @param pos input-output position; on input, the position within
997      * text to match; must have 0 <= pos.getIndex() < text.length();
998      * on output, the position after the last matched character. If
999      * the parse fails, the position in unchanged upon output.
1000      * @return a reference to result
1001      * @internal
1002      */
1003     virtual Formattable& parseCurrency(const UnicodeString& text,
1004                                        Formattable& result,
1005                                        ParsePosition& pos) const;
1006 
1007     /**
1008      * Returns the decimal format symbols, which is generally not changed
1009      * by the programmer or user.
1010      * @return desired DecimalFormatSymbols
1011      * @see DecimalFormatSymbols
1012      * @stable ICU 2.0
1013      */
1014     virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
1015 
1016     /**
1017      * Sets the decimal format symbols, which is generally not changed
1018      * by the programmer or user.
1019      * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
1020      * @stable ICU 2.0
1021      */
1022     virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
1023 
1024     /**
1025      * Sets the decimal format symbols, which is generally not changed
1026      * by the programmer or user.
1027      * @param symbols DecimalFormatSymbols.
1028      * @stable ICU 2.0
1029      */
1030     virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1031 
1032 
1033     /**
1034      * Get the positive prefix.
1035      *
1036      * @param result    Output param which will receive the positive prefix.
1037      * @return          A reference to 'result'.
1038      * Examples: +123, $123, sFr123
1039      * @stable ICU 2.0
1040      */
1041     UnicodeString& getPositivePrefix(UnicodeString& result) const;
1042 
1043     /**
1044      * Set the positive prefix.
1045      *
1046      * @param newValue    the new value of the the positive prefix to be set.
1047      * Examples: +123, $123, sFr123
1048      * @stable ICU 2.0
1049      */
1050     virtual void setPositivePrefix(const UnicodeString& newValue);
1051 
1052     /**
1053      * Get the negative prefix.
1054      *
1055      * @param result    Output param which will receive the negative prefix.
1056      * @return          A reference to 'result'.
1057      * Examples: -123, ($123) (with negative suffix), sFr-123
1058      * @stable ICU 2.0
1059      */
1060     UnicodeString& getNegativePrefix(UnicodeString& result) const;
1061 
1062     /**
1063      * Set the negative prefix.
1064      *
1065      * @param newValue    the new value of the the negative prefix to be set.
1066      * Examples: -123, ($123) (with negative suffix), sFr-123
1067      * @stable ICU 2.0
1068      */
1069     virtual void setNegativePrefix(const UnicodeString& newValue);
1070 
1071     /**
1072      * Get the positive suffix.
1073      *
1074      * @param result    Output param which will receive the positive suffix.
1075      * @return          A reference to 'result'.
1076      * Example: 123%
1077      * @stable ICU 2.0
1078      */
1079     UnicodeString& getPositiveSuffix(UnicodeString& result) const;
1080 
1081     /**
1082      * Set the positive suffix.
1083      *
1084      * @param newValue    the new value of the positive suffix to be set.
1085      * Example: 123%
1086      * @stable ICU 2.0
1087      */
1088     virtual void setPositiveSuffix(const UnicodeString& newValue);
1089 
1090     /**
1091      * Get the negative suffix.
1092      *
1093      * @param result    Output param which will receive the negative suffix.
1094      * @return          A reference to 'result'.
1095      * Examples: -123%, ($123) (with positive suffixes)
1096      * @stable ICU 2.0
1097      */
1098     UnicodeString& getNegativeSuffix(UnicodeString& result) const;
1099 
1100     /**
1101      * Set the negative suffix.
1102      *
1103      * @param newValue    the new value of the negative suffix to be set.
1104      * Examples: 123%
1105      * @stable ICU 2.0
1106      */
1107     virtual void setNegativeSuffix(const UnicodeString& newValue);
1108 
1109     /**
1110      * Get the multiplier for use in percent, permill, etc.
1111      * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1112      * (For Arabic, use arabic percent symbol).
1113      * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1114      *
1115      * @return    the multiplier for use in percent, permill, etc.
1116      * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1117      * @stable ICU 2.0
1118      */
1119     int32_t getMultiplier(void) const;
1120 
1121     /**
1122      * Set the multiplier for use in percent, permill, etc.
1123      * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1124      * (For Arabic, use arabic percent symbol).
1125      * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1126      *
1127      * @param newValue    the new value of the multiplier for use in percent, permill, etc.
1128      * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1129      * @stable ICU 2.0
1130      */
1131     virtual void setMultiplier(int32_t newValue);
1132 
1133     /**
1134      * Get the rounding increment.
1135      * @return A positive rounding increment, or 0.0 if rounding
1136      * is not in effect.
1137      * @see #setRoundingIncrement
1138      * @see #getRoundingMode
1139      * @see #setRoundingMode
1140      * @stable ICU 2.0
1141      */
1142     virtual double getRoundingIncrement(void) const;
1143 
1144     /**
1145      * Set the rounding increment.  This method also controls whether
1146      * rounding is enabled.
1147      * @param newValue A positive rounding increment, or 0.0 to disable rounding.
1148      * Negative increments are equivalent to 0.0.
1149      * @see #getRoundingIncrement
1150      * @see #getRoundingMode
1151      * @see #setRoundingMode
1152      * @stable ICU 2.0
1153      */
1154     virtual void setRoundingIncrement(double newValue);
1155 
1156     /**
1157      * Get the rounding mode.
1158      * @return A rounding mode
1159      * @see #setRoundingIncrement
1160      * @see #getRoundingIncrement
1161      * @see #setRoundingMode
1162      * @stable ICU 2.0
1163      */
1164     virtual ERoundingMode getRoundingMode(void) const;
1165 
1166     /**
1167      * Set the rounding mode.  This has no effect unless the rounding
1168      * increment is greater than zero.
1169      * @param roundingMode A rounding mode
1170      * @see #setRoundingIncrement
1171      * @see #getRoundingIncrement
1172      * @see #getRoundingMode
1173      * @stable ICU 2.0
1174      */
1175     virtual void setRoundingMode(ERoundingMode roundingMode);
1176 
1177     /**
1178      * Get the width to which the output of format() is padded.
1179      * The width is counted in 16-bit code units.
1180      * @return the format width, or zero if no padding is in effect
1181      * @see #setFormatWidth
1182      * @see #getPadCharacterString
1183      * @see #setPadCharacter
1184      * @see #getPadPosition
1185      * @see #setPadPosition
1186      * @stable ICU 2.0
1187      */
1188     virtual int32_t getFormatWidth(void) const;
1189 
1190     /**
1191      * Set the width to which the output of format() is padded.
1192      * The width is counted in 16-bit code units.
1193      * This method also controls whether padding is enabled.
1194      * @param width the width to which to pad the result of
1195      * format(), or zero to disable padding.  A negative
1196      * width is equivalent to 0.
1197      * @see #getFormatWidth
1198      * @see #getPadCharacterString
1199      * @see #setPadCharacter
1200      * @see #getPadPosition
1201      * @see #setPadPosition
1202      * @stable ICU 2.0
1203      */
1204     virtual void setFormatWidth(int32_t width);
1205 
1206     /**
1207      * Get the pad character used to pad to the format width.  The
1208      * default is ' '.
1209      * @return a string containing the pad character. This will always
1210      * have a length of one 32-bit code point.
1211      * @see #setFormatWidth
1212      * @see #getFormatWidth
1213      * @see #setPadCharacter
1214      * @see #getPadPosition
1215      * @see #setPadPosition
1216      * @stable ICU 2.0
1217      */
1218     virtual UnicodeString getPadCharacterString() const;
1219 
1220     /**
1221      * Set the character used to pad to the format width.  If padding
1222      * is not enabled, then this will take effect if padding is later
1223      * enabled.
1224      * @param padChar a string containing the pad charcter. If the string
1225      * has length 0, then the pad characer is set to ' '.  Otherwise
1226      * padChar.char32At(0) will be used as the pad character.
1227      * @see #setFormatWidth
1228      * @see #getFormatWidth
1229      * @see #getPadCharacterString
1230      * @see #getPadPosition
1231      * @see #setPadPosition
1232      * @stable ICU 2.0
1233      */
1234     virtual void setPadCharacter(const UnicodeString &padChar);
1235 
1236     /**
1237      * Get the position at which padding will take place.  This is the location
1238      * at which padding will be inserted if the result of format()
1239      * is shorter than the format width.
1240      * @return the pad position, one of kPadBeforePrefix,
1241      * kPadAfterPrefix, kPadBeforeSuffix, or
1242      * kPadAfterSuffix.
1243      * @see #setFormatWidth
1244      * @see #getFormatWidth
1245      * @see #setPadCharacter
1246      * @see #getPadCharacterString
1247      * @see #setPadPosition
1248      * @see #kPadBeforePrefix
1249      * @see #kPadAfterPrefix
1250      * @see #kPadBeforeSuffix
1251      * @see #kPadAfterSuffix
1252      * @stable ICU 2.0
1253      */
1254     virtual EPadPosition getPadPosition(void) const;
1255 
1256     /**
1257      * Set the position at which padding will take place.  This is the location
1258      * at which padding will be inserted if the result of format()
1259      * is shorter than the format width.  This has no effect unless padding is
1260      * enabled.
1261      * @param padPos the pad position, one of kPadBeforePrefix,
1262      * kPadAfterPrefix, kPadBeforeSuffix, or
1263      * kPadAfterSuffix.
1264      * @see #setFormatWidth
1265      * @see #getFormatWidth
1266      * @see #setPadCharacter
1267      * @see #getPadCharacterString
1268      * @see #getPadPosition
1269      * @see #kPadBeforePrefix
1270      * @see #kPadAfterPrefix
1271      * @see #kPadBeforeSuffix
1272      * @see #kPadAfterSuffix
1273      * @stable ICU 2.0
1274      */
1275     virtual void setPadPosition(EPadPosition padPos);
1276 
1277     /**
1278      * Return whether or not scientific notation is used.
1279      * @return TRUE if this object formats and parses scientific notation
1280      * @see #setScientificNotation
1281      * @see #getMinimumExponentDigits
1282      * @see #setMinimumExponentDigits
1283      * @see #isExponentSignAlwaysShown
1284      * @see #setExponentSignAlwaysShown
1285      * @stable ICU 2.0
1286      */
1287     virtual UBool isScientificNotation(void);
1288 
1289     /**
1290      * Set whether or not scientific notation is used. When scientific notation
1291      * is used, the effective maximum number of integer digits is <= 8.  If the
1292      * maximum number of integer digits is set to more than 8, the effective
1293      * maximum will be 1.  This allows this call to generate a 'default' scientific
1294      * number format without additional changes.
1295      * @param useScientific TRUE if this object formats and parses scientific
1296      * notation
1297      * @see #isScientificNotation
1298      * @see #getMinimumExponentDigits
1299      * @see #setMinimumExponentDigits
1300      * @see #isExponentSignAlwaysShown
1301      * @see #setExponentSignAlwaysShown
1302      * @stable ICU 2.0
1303      */
1304     virtual void setScientificNotation(UBool useScientific);
1305 
1306     /**
1307      * Return the minimum exponent digits that will be shown.
1308      * @return the minimum exponent digits that will be shown
1309      * @see #setScientificNotation
1310      * @see #isScientificNotation
1311      * @see #setMinimumExponentDigits
1312      * @see #isExponentSignAlwaysShown
1313      * @see #setExponentSignAlwaysShown
1314      * @stable ICU 2.0
1315      */
1316     virtual int8_t getMinimumExponentDigits(void) const;
1317 
1318     /**
1319      * Set the minimum exponent digits that will be shown.  This has no
1320      * effect unless scientific notation is in use.
1321      * @param minExpDig a value >= 1 indicating the fewest exponent digits
1322      * that will be shown.  Values less than 1 will be treated as 1.
1323      * @see #setScientificNotation
1324      * @see #isScientificNotation
1325      * @see #getMinimumExponentDigits
1326      * @see #isExponentSignAlwaysShown
1327      * @see #setExponentSignAlwaysShown
1328      * @stable ICU 2.0
1329      */
1330     virtual void setMinimumExponentDigits(int8_t minExpDig);
1331 
1332     /**
1333      * Return whether the exponent sign is always shown.
1334      * @return TRUE if the exponent is always prefixed with either the
1335      * localized minus sign or the localized plus sign, false if only negative
1336      * exponents are prefixed with the localized minus sign.
1337      * @see #setScientificNotation
1338      * @see #isScientificNotation
1339      * @see #setMinimumExponentDigits
1340      * @see #getMinimumExponentDigits
1341      * @see #setExponentSignAlwaysShown
1342      * @stable ICU 2.0
1343      */
1344     virtual UBool isExponentSignAlwaysShown(void);
1345 
1346     /**
1347      * Set whether the exponent sign is always shown.  This has no effect
1348      * unless scientific notation is in use.
1349      * @param expSignAlways TRUE if the exponent is always prefixed with either
1350      * the localized minus sign or the localized plus sign, false if only
1351      * negative exponents are prefixed with the localized minus sign.
1352      * @see #setScientificNotation
1353      * @see #isScientificNotation
1354      * @see #setMinimumExponentDigits
1355      * @see #getMinimumExponentDigits
1356      * @see #isExponentSignAlwaysShown
1357      * @stable ICU 2.0
1358      */
1359     virtual void setExponentSignAlwaysShown(UBool expSignAlways);
1360 
1361     /**
1362      * Return the grouping size. Grouping size is the number of digits between
1363      * grouping separators in the integer portion of a number.  For example,
1364      * in the number "123,456.78", the grouping size is 3.
1365      *
1366      * @return    the grouping size.
1367      * @see setGroupingSize
1368      * @see NumberFormat::isGroupingUsed
1369      * @see DecimalFormatSymbols::getGroupingSeparator
1370      * @stable ICU 2.0
1371      */
1372     int32_t getGroupingSize(void) const;
1373 
1374     /**
1375      * Set the grouping size. Grouping size is the number of digits between
1376      * grouping separators in the integer portion of a number.  For example,
1377      * in the number "123,456.78", the grouping size is 3.
1378      *
1379      * @param newValue    the new value of the grouping size.
1380      * @see getGroupingSize
1381      * @see NumberFormat::setGroupingUsed
1382      * @see DecimalFormatSymbols::setGroupingSeparator
1383      * @stable ICU 2.0
1384      */
1385     virtual void setGroupingSize(int32_t newValue);
1386 
1387     /**
1388      * Return the secondary grouping size. In some locales one
1389      * grouping interval is used for the least significant integer
1390      * digits (the primary grouping size), and another is used for all
1391      * others (the secondary grouping size).  A formatter supporting a
1392      * secondary grouping size will return a positive integer unequal
1393      * to the primary grouping size returned by
1394      * getGroupingSize().  For example, if the primary
1395      * grouping size is 4, and the secondary grouping size is 2, then
1396      * the number 123456789 formats as "1,23,45,6789", and the pattern
1397      * appears as "#,##,###0".
1398      * @return the secondary grouping size, or a value less than
1399      * one if there is none
1400      * @see setSecondaryGroupingSize
1401      * @see NumberFormat::isGroupingUsed
1402      * @see DecimalFormatSymbols::getGroupingSeparator
1403      * @stable ICU 2.4
1404      */
1405     int32_t getSecondaryGroupingSize(void) const;
1406 
1407     /**
1408      * Set the secondary grouping size. If set to a value less than 1,
1409      * then secondary grouping is turned off, and the primary grouping
1410      * size is used for all intervals, not just the least significant.
1411      *
1412      * @param newValue    the new value of the secondary grouping size.
1413      * @see getSecondaryGroupingSize
1414      * @see NumberFormat#setGroupingUsed
1415      * @see DecimalFormatSymbols::setGroupingSeparator
1416      * @stable ICU 2.4
1417      */
1418     virtual void setSecondaryGroupingSize(int32_t newValue);
1419 
1420     /**
1421      * Allows you to get the behavior of the decimal separator with integers.
1422      * (The decimal separator will always appear with decimals.)
1423      *
1424      * @return    TRUE if the decimal separator always appear with decimals.
1425      * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1426      * @stable ICU 2.0
1427      */
1428     UBool isDecimalSeparatorAlwaysShown(void) const;
1429 
1430     /**
1431      * Allows you to set the behavior of the decimal separator with integers.
1432      * (The decimal separator will always appear with decimals.)
1433      *
1434      * @param newValue    set TRUE if the decimal separator will always appear with decimals.
1435      * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1436      * @stable ICU 2.0
1437      */
1438     virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
1439 
1440     /**
1441      * Synthesizes a pattern string that represents the current state
1442      * of this Format object.
1443      *
1444      * @param result    Output param which will receive the pattern.
1445      *                  Previous contents are deleted.
1446      * @return          A reference to 'result'.
1447      * @see applyPattern
1448      * @stable ICU 2.0
1449      */
1450     virtual UnicodeString& toPattern(UnicodeString& result) const;
1451 
1452     /**
1453      * Synthesizes a localized pattern string that represents the current
1454      * state of this Format object.
1455      *
1456      * @param result    Output param which will receive the localized pattern.
1457      *                  Previous contents are deleted.
1458      * @return          A reference to 'result'.
1459      * @see applyPattern
1460      * @stable ICU 2.0
1461      */
1462     virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
1463 
1464     /**
1465      * Apply the given pattern to this Format object.  A pattern is a
1466      * short-hand specification for the various formatting properties.
1467      * These properties can also be changed individually through the
1468      * various setter methods.
1469      * <P>
1470      * There is no limit to integer digits are set
1471      * by this routine, since that is the typical end-user desire;
1472      * use setMaximumInteger if you want to set a real value.
1473      * For negative numbers, use a second pattern, separated by a semicolon
1474      * <pre>
1475      * .      Example "#,#00.0#" -> 1,234.56
1476      * </pre>
1477      * This means a minimum of 2 integer digits, 1 fraction digit, and
1478      * a maximum of 2 fraction digits.
1479      * <pre>
1480      * .      Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1481      * </pre>
1482      * In negative patterns, the minimum and maximum counts are ignored;
1483      * these are presumed to be set in the positive pattern.
1484      *
1485      * @param pattern    The pattern to be applied.
1486      * @param parseError Struct to recieve information on position
1487      *                   of error if an error is encountered
1488      * @param status     Output param set to success/failure code on
1489      *                   exit. If the pattern is invalid, this will be
1490      *                   set to a failure result.
1491      * @stable ICU 2.0
1492      */
1493     virtual void applyPattern(const UnicodeString& pattern,
1494                              UParseError& parseError,
1495                              UErrorCode& status);
1496     /**
1497      * Sets the pattern.
1498      * @param pattern   The pattern to be applied.
1499      * @param status    Output param set to success/failure code on
1500      *                  exit. If the pattern is invalid, this will be
1501      *                  set to a failure result.
1502      * @stable ICU 2.0
1503      */
1504     virtual void applyPattern(const UnicodeString& pattern,
1505                              UErrorCode& status);
1506 
1507     /**
1508      * Apply the given pattern to this Format object.  The pattern
1509      * is assumed to be in a localized notation. A pattern is a
1510      * short-hand specification for the various formatting properties.
1511      * These properties can also be changed individually through the
1512      * various setter methods.
1513      * <P>
1514      * There is no limit to integer digits are set
1515      * by this routine, since that is the typical end-user desire;
1516      * use setMaximumInteger if you want to set a real value.
1517      * For negative numbers, use a second pattern, separated by a semicolon
1518      * <pre>
1519      * .      Example "#,#00.0#" -> 1,234.56
1520      * </pre>
1521      * This means a minimum of 2 integer digits, 1 fraction digit, and
1522      * a maximum of 2 fraction digits.
1523      *
1524      * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1525      *
1526      * In negative patterns, the minimum and maximum counts are ignored;
1527      * these are presumed to be set in the positive pattern.
1528      *
1529      * @param pattern   The localized pattern to be applied.
1530      * @param parseError Struct to recieve information on position
1531      *                   of error if an error is encountered
1532      * @param status    Output param set to success/failure code on
1533      *                  exit. If the pattern is invalid, this will be
1534      *                  set to a failure result.
1535      * @stable ICU 2.0
1536      */
1537     virtual void applyLocalizedPattern(const UnicodeString& pattern,
1538                                        UParseError& parseError,
1539                                        UErrorCode& status);
1540 
1541     /**
1542      * Apply the given pattern to this Format object.
1543      *
1544      * @param pattern   The localized pattern to be applied.
1545      * @param status    Output param set to success/failure code on
1546      *                  exit. If the pattern is invalid, this will be
1547      *                  set to a failure result.
1548      * @stable ICU 2.0
1549      */
1550     virtual void applyLocalizedPattern(const UnicodeString& pattern,
1551                                        UErrorCode& status);
1552 
1553 
1554     /**
1555      * Sets the maximum number of digits allowed in the integer portion of a
1556      * number. This override limits the integer digit count to 309.
1557      *
1558      * @param newValue    the new value of the maximum number of digits
1559      *                      allowed in the integer portion of a number.
1560      * @see NumberFormat#setMaximumIntegerDigits
1561      * @stable ICU 2.0
1562      */
1563     virtual void setMaximumIntegerDigits(int32_t newValue);
1564 
1565     /**
1566      * Sets the minimum number of digits allowed in the integer portion of a
1567      * number. This override limits the integer digit count to 309.
1568      *
1569      * @param newValue    the new value of the minimum number of digits
1570      *                      allowed in the integer portion of a number.
1571      * @see NumberFormat#setMinimumIntegerDigits
1572      * @stable ICU 2.0
1573      */
1574     virtual void setMinimumIntegerDigits(int32_t newValue);
1575 
1576     /**
1577      * Sets the maximum number of digits allowed in the fraction portion of a
1578      * number. This override limits the fraction digit count to 340.
1579      *
1580      * @param newValue    the new value of the maximum number of digits
1581      *                    allowed in the fraction portion of a number.
1582      * @see NumberFormat#setMaximumFractionDigits
1583      * @stable ICU 2.0
1584      */
1585     virtual void setMaximumFractionDigits(int32_t newValue);
1586 
1587     /**
1588      * Sets the minimum number of digits allowed in the fraction portion of a
1589      * number. This override limits the fraction digit count to 340.
1590      *
1591      * @param newValue    the new value of the minimum number of digits
1592      *                    allowed in the fraction portion of a number.
1593      * @see NumberFormat#setMinimumFractionDigits
1594      * @stable ICU 2.0
1595      */
1596     virtual void setMinimumFractionDigits(int32_t newValue);
1597 
1598     /**
1599      * Returns the minimum number of significant digits that will be
1600      * displayed. This value has no effect unless areSignificantDigitsUsed()
1601      * returns true.
1602      * @return the fewest significant digits that will be shown
1603      * @stable ICU 3.0
1604      */
1605     int32_t getMinimumSignificantDigits() const;
1606 
1607     /**
1608      * Returns the maximum number of significant digits that will be
1609      * displayed. This value has no effect unless areSignificantDigitsUsed()
1610      * returns true.
1611      * @return the most significant digits that will be shown
1612      * @stable ICU 3.0
1613      */
1614     int32_t getMaximumSignificantDigits() const;
1615 
1616     /**
1617      * Sets the minimum number of significant digits that will be
1618      * displayed.  If <code>min</code> is less than one then it is set
1619      * to one.  If the maximum significant digits count is less than
1620      * <code>min</code>, then it is set to <code>min</code>. This
1621      * value has no effect unless areSignificantDigits() returns true.
1622      * @param min the fewest significant digits to be shown
1623      * @stable ICU 3.0
1624      */
1625     void setMinimumSignificantDigits(int32_t min);
1626 
1627     /**
1628      * Sets the maximum number of significant digits that will be
1629      * displayed.  If <code>max</code> is less than one then it is set
1630      * to one.  If the minimum significant digits count is greater
1631      * than <code>max</code>, then it is set to <code>max</code>.
1632      * This value has no effect unless areSignificantDigits() returns
1633      * true.
1634      * @param max the most significant digits to be shown
1635      * @stable ICU 3.0
1636      */
1637     void setMaximumSignificantDigits(int32_t max);
1638 
1639     /**
1640      * Returns true if significant digits are in use, or false if
1641      * integer and fraction digit counts are in use.
1642      * @return true if significant digits are in use
1643      * @stable ICU 3.0
1644      */
1645     UBool areSignificantDigitsUsed() const;
1646 
1647     /**
1648      * Sets whether significant digits are in use, or integer and
1649      * fraction digit counts are in use.
1650      * @param useSignificantDigits true to use significant digits, or
1651      * false to use integer and fraction digit counts
1652      * @stable ICU 3.0
1653      */
1654     void setSignificantDigitsUsed(UBool useSignificantDigits);
1655 
1656  public:
1657     /**
1658      * Sets the currency used to display currency
1659      * amounts.  This takes effect immediately, if this format is a
1660      * currency format.  If this format is not a currency format, then
1661      * the currency is used if and when this object becomes a
1662      * currency format through the application of a new pattern.
1663      * @param theCurrency a 3-letter ISO code indicating new currency
1664      * to use.  It need not be null-terminated.  May be the empty
1665      * string or NULL to indicate no currency.
1666      * @param ec input-output error code
1667      * @stable ICU 3.0
1668      */
1669     virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
1670 
1671     /**
1672      * Sets the currency used to display currency amounts.  See
1673      * setCurrency(const UChar*, UErrorCode&).
1674      * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&).
1675      */
1676     virtual void setCurrency(const UChar* theCurrency);
1677 
1678     /**
1679      * The resource tags we use to retrieve decimal format data from
1680      * locale resource bundles.
1681      * @deprecated ICU 3.4. This string has no public purpose. Please don't use it.
1682      */
1683     static const char fgNumberPatterns[];
1684 
1685 public:
1686 
1687     /**
1688      * Return the class ID for this class.  This is useful only for
1689      * comparing to a return value from getDynamicClassID().  For example:
1690      * <pre>
1691      * .      Base* polymorphic_pointer = createPolymorphicObject();
1692      * .      if (polymorphic_pointer->getDynamicClassID() ==
1693      * .          Derived::getStaticClassID()) ...
1694      * </pre>
1695      * @return          The class ID for all objects of this class.
1696      * @stable ICU 2.0
1697      */
1698     static UClassID U_EXPORT2 getStaticClassID(void);
1699 
1700     /**
1701      * Returns a unique class ID POLYMORPHICALLY.  Pure virtual override.
1702      * This method is to implement a simple version of RTTI, since not all
1703      * C++ compilers support genuine RTTI.  Polymorphic operator==() and
1704      * clone() methods call this method.
1705      *
1706      * @return          The class ID for this object. All objects of a
1707      *                  given class have the same class ID.  Objects of
1708      *                  other classes have different class IDs.
1709      * @stable ICU 2.0
1710      */
1711     virtual UClassID getDynamicClassID(void) const;
1712 
1713 private:
1714     DecimalFormat(); // default constructor not implemented
1715 
1716     int32_t precision(UBool isIntegral) const;
1717 
1718     /**
1719      * Do real work of constructing a new DecimalFormat.
1720      */
1721     void construct(UErrorCode&               status,
1722                    UParseError&             parseErr,
1723                    const UnicodeString*     pattern = 0,
1724                    DecimalFormatSymbols*    symbolsToAdopt = 0
1725                    );
1726 
1727     /**
1728      * Does the real work of generating a pattern.
1729      *
1730      * @param result     Output param which will receive the pattern.
1731      *                   Previous contents are deleted.
1732      * @param localized  TRUE return localized pattern.
1733      * @return           A reference to 'result'.
1734      */
1735     UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
1736 
1737     /**
1738      * Does the real work of applying a pattern.
1739      * @param pattern    The pattern to be applied.
1740      * @param localized  If true, the pattern is localized; else false.
1741      * @param parseError Struct to recieve information on position
1742      *                   of error if an error is encountered
1743      * @param status     Output param set to success/failure code on
1744      *                   exit. If the pattern is invalid, this will be
1745      *                   set to a failure result.
1746      */
1747     void applyPattern(const UnicodeString& pattern,
1748                             UBool localized,
1749                             UParseError& parseError,
1750                             UErrorCode& status);
1751     /**
1752      * Do the work of formatting a number, either a double or a long.
1753      *
1754      * @param appendTo       Output parameter to receive result.
1755      *                       Result is appended to existing contents.
1756      * @param fieldPosition  On input: an alignment field, if desired.
1757      *                       On output: the offsets of the alignment field.
1758      * @param digits         the digits to be formatted.
1759      * @param isInteger      if TRUE format the digits as Integer.
1760      * @return               Reference to 'appendTo' parameter.
1761      */
1762     UnicodeString& subformat(UnicodeString& appendTo,
1763                              FieldPosition& fieldPosition,
1764                              DigitList& digits,
1765                              UBool         isInteger) const;
1766 
1767     // BEGIN android-removed
1768     // UnicodeString& subformat(UnicodeString& appendTo,
1769     //                          FieldPosition& fieldPosition,
1770     //                          AttrBuffer attrBuffer,
1771     //                          DigitList& digits,
1772     //                          UBool         isInteger) const;
1773     // END android-removed
1774 
1775     void parse(const UnicodeString& text,
1776                Formattable& result,
1777                ParsePosition& pos,
1778                UBool parseCurrency) const;
1779 
1780     enum {
1781         fgStatusInfinite,
1782         fgStatusLength      // Leave last in list.
1783     } StatusFlags;
1784 
1785     UBool subparse(const UnicodeString& text, ParsePosition& parsePosition,
1786                    DigitList& digits, UBool* status,
1787                    UChar* currency) const;
1788 
1789     int32_t skipPadding(const UnicodeString& text, int32_t position) const;
1790 
1791     int32_t compareAffix(const UnicodeString& input,
1792                          int32_t pos,
1793                          UBool isNegative,
1794                          UBool isPrefix,
1795                          UChar* currency) const;
1796 
1797     static int32_t compareSimpleAffix(const UnicodeString& affix,
1798                                       const UnicodeString& input,
1799                                       int32_t pos);
1800 
1801     static int32_t skipRuleWhiteSpace(const UnicodeString& text, int32_t pos);
1802 
1803     static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
1804 
1805     int32_t compareComplexAffix(const UnicodeString& affixPat,
1806                                 const UnicodeString& input,
1807                                 int32_t pos,
1808                                 UChar* currency) const;
1809 
1810     static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
1811 
1812     static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
1813 
1814     /**
1815      * Get a decimal format symbol.
1816      * Returns a const reference to the symbol string.
1817      * @internal
1818      */
1819     inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
1820 
1821     int32_t appendAffix(UnicodeString& buf, double number,
1822                         UBool isNegative, UBool isPrefix) const;
1823 
1824     int32_t appendAffix(UnicodeString& buf, double number, AttrBuffer attrBuffer,
1825                         UBool isNegative, UBool isPrefix) const;
1826 
1827     /**
1828      * Append an affix to the given UnicodeString, using quotes if
1829      * there are special characters.  Single quotes themselves must be
1830      * escaped in either case.
1831      */
1832     void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
1833                             UBool localized) const;
1834 
1835     void appendAffixPattern(UnicodeString& appendTo,
1836                             const UnicodeString* affixPattern,
1837                             const UnicodeString& expAffix, UBool localized) const;
1838 
1839     void expandAffix(const UnicodeString& pattern,
1840                      UnicodeString& affix,
1841                      double number,
1842                      UBool doFormat) const;
1843 
1844     void expandAffix(const UnicodeString& pattern,
1845                      UnicodeString& affix,
1846                      double number,
1847                      AttrBuffer attrBuffer,
1848                      UBool doFormat) const;
1849 
1850     void expandAffixes();
1851 
1852     static double round(double a, ERoundingMode mode, UBool isNegative);
1853 
1854     void addPadding(UnicodeString& appendTo,
1855                     FieldPosition& fieldPosition,
1856                     int32_t prefixLen, int32_t suffixLen) const;
1857 
1858     UBool isGroupingPosition(int32_t pos) const;
1859 
1860     void setCurrencyForSymbols();
1861 
1862     /**
1863      * Constants.
1864      */
1865     //static const int8_t fgMaxDigit; // The largest digit, in this case 9
1866 
1867     /*transient*/ //DigitList* fDigitList;
1868 
1869     UnicodeString           fPositivePrefix;
1870     UnicodeString           fPositiveSuffix;
1871     UnicodeString           fNegativePrefix;
1872     UnicodeString           fNegativeSuffix;
1873     UnicodeString*          fPosPrefixPattern;
1874     UnicodeString*          fPosSuffixPattern;
1875     UnicodeString*          fNegPrefixPattern;
1876     UnicodeString*          fNegSuffixPattern;
1877 
1878     /**
1879      * Formatter for ChoiceFormat-based currency names.  If this field
1880      * is not null, then delegate to it to format currency symbols.
1881      * @since ICU 2.6
1882      */
1883     ChoiceFormat*           fCurrencyChoice;
1884 
1885     int32_t                 fMultiplier;
1886     int32_t                 fGroupingSize;
1887     int32_t                 fGroupingSize2;
1888     UBool                   fDecimalSeparatorAlwaysShown;
1889     /*transient*/ UBool     fIsCurrencyFormat;
1890     DecimalFormatSymbols*   fSymbols;
1891 
1892     UBool                   fUseSignificantDigits;
1893     int32_t                 fMinSignificantDigits;
1894     int32_t                 fMaxSignificantDigits;
1895 
1896     UBool                   fUseExponentialNotation;
1897     int8_t                  fMinExponentDigits;
1898     UBool                   fExponentSignAlwaysShown;
1899 
1900     /* If fRoundingIncrement is NULL, there is no rounding.  Otherwise, round to
1901      * fRoundingIncrement.getDouble().  Since this operation may be expensive,
1902      * we cache the result in fRoundingDouble.  All methods that update
1903      * fRoundingIncrement also update fRoundingDouble. */
1904     DigitList*              fRoundingIncrement;
1905     /*transient*/ double    fRoundingDouble;
1906     ERoundingMode           fRoundingMode;
1907 
1908     UChar32                 fPad;
1909     int32_t                 fFormatWidth;
1910     EPadPosition            fPadPosition;
1911 
1912     void addAttribute(AttrBuffer attrBuffer, char *fieldname, int begin, int end) const;
1913 
1914 protected:
1915 
1916     /**
1917      * Returns the currency in effect for this formatter.  Subclasses
1918      * should override this method as needed.  Unlike getCurrency(),
1919      * this method should never return "".
1920      * @result output parameter for null-terminated result, which must
1921      * have a capacity of at least 4
1922      * @internal
1923      */
1924     virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
1925 
1926   /** number of integer digits
1927    * @stable ICU 2.4
1928    */
1929     static const int32_t  kDoubleIntegerDigits;
1930   /** number of fraction digits
1931    * @stable ICU 2.4
1932    */
1933     static const int32_t  kDoubleFractionDigits;
1934 
1935     /**
1936      * When someone turns on scientific mode, we assume that more than this
1937      * number of digits is due to flipping from some other mode that didn't
1938      * restrict the maximum, and so we force 1 integer digit.  We don't bother
1939      * to track and see if someone is using exponential notation with more than
1940      * this number, it wouldn't make sense anyway, and this is just to make sure
1941      * that someone turning on scientific mode with default settings doesn't
1942      * end up with lots of zeroes.
1943      * @stable ICU 2.8
1944      */
1945     static const int32_t  kMaxScientificIntegerDigits;
1946 };
1947 
1948 inline UnicodeString&
format(const Formattable & obj,UnicodeString & appendTo,UErrorCode & status)1949 DecimalFormat::format(const Formattable& obj,
1950                       UnicodeString& appendTo,
1951                       UErrorCode& status) const {
1952     // Don't use Format:: - use immediate base class only,
1953     // in case immediate base modifies behavior later.
1954     return NumberFormat::format(obj, appendTo, status);
1955 }
1956 
1957 inline UnicodeString&
format(double number,UnicodeString & appendTo)1958 DecimalFormat::format(double number,
1959                       UnicodeString& appendTo) const {
1960     FieldPosition pos(0);
1961     return format(number, appendTo, pos, NULL);
1962 }
1963 
1964 inline UnicodeString&
format(int32_t number,UnicodeString & appendTo)1965 DecimalFormat::format(int32_t number,
1966                       UnicodeString& appendTo) const {
1967     FieldPosition pos(0);
1968     return format((int64_t)number, appendTo, pos, NULL);
1969 }
1970 
1971 inline const UnicodeString &
getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol)1972 DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
1973     return fSymbols->getConstSymbol(symbol);
1974 }
1975 
1976 U_NAMESPACE_END
1977 
1978 #endif /* #if !UCONFIG_NO_FORMATTING */
1979 
1980 #endif // _DECIMFMT
1981 //eof
1982