decimfmt.h revision 7c971b21cb09c84a9bd948bdf2918b727d46992c
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
39U_NAMESPACE_BEGIN
40
41class DigitList;
42class 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 */
603class U_I18N_API DecimalFormat: public NumberFormat {
604public:
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    * Parse the given string using this object's choices. The method
912    * does string comparisons to try to find an optimal match.
913    * If no object can be parsed, index is unchanged, and NULL is
914    * returned.  The result is returned as the most parsimonious
915    * type of Formattable that will accomodate all of the
916    * necessary precision.  For example, if the result is exactly 12,
917    * it will be returned as a long.  However, if it is 1.5, it will
918    * be returned as a double.
919    *
920    * @param text           The text to be parsed.
921    * @param result         Formattable to be set to the parse result.
922    *                       If parse fails, return contents are undefined.
923    * @param parsePosition  The position to start parsing at on input.
924    *                       On output, moved to after the last successfully
925    *                       parse character. On parse failure, does not change.
926    * @see Formattable
927    * @stable ICU 2.0
928    */
929    virtual void parse(const UnicodeString& text,
930                       Formattable& result,
931                       ParsePosition& parsePosition) const;
932
933    // Declare here again to get rid of function hiding problems.
934    /**
935     * Parse the given string using this object's choices.
936     *
937     * @param text           The text to be parsed.
938     * @param result         Formattable to be set to the parse result.
939     * @param status    Output parameter filled in with success or failure status.
940     * @stable ICU 2.0
941     */
942    virtual void parse(const UnicodeString& text,
943                       Formattable& result,
944                       UErrorCode& status) const;
945
946    /**
947     * Parses text from the given string as a currency amount.  Unlike
948     * the parse() method, this method will attempt to parse a generic
949     * currency name, searching for a match of this object's locale's
950     * currency display names, or for a 3-letter ISO currency code.
951     * This method will fail if this format is not a currency format,
952     * that is, if it does not contain the currency pattern symbol
953     * (U+00A4) in its prefix or suffix.
954     *
955     * @param text the string to parse
956     * @param result output parameter to receive result. This will have
957     * its currency set to the parsed ISO currency code.
958     * @param pos input-output position; on input, the position within
959     * text to match; must have 0 <= pos.getIndex() < text.length();
960     * on output, the position after the last matched character. If
961     * the parse fails, the position in unchanged upon output.
962     * @return a reference to result
963     * @internal
964     */
965    virtual Formattable& parseCurrency(const UnicodeString& text,
966                                       Formattable& result,
967                                       ParsePosition& pos) const;
968
969    /**
970     * Returns the decimal format symbols, which is generally not changed
971     * by the programmer or user.
972     * @return desired DecimalFormatSymbols
973     * @see DecimalFormatSymbols
974     * @stable ICU 2.0
975     */
976    virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
977
978    /**
979     * Sets the decimal format symbols, which is generally not changed
980     * by the programmer or user.
981     * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
982     * @stable ICU 2.0
983     */
984    virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
985
986    /**
987     * Sets the decimal format symbols, which is generally not changed
988     * by the programmer or user.
989     * @param symbols DecimalFormatSymbols.
990     * @stable ICU 2.0
991     */
992    virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
993
994
995    /**
996     * Get the positive prefix.
997     *
998     * @param result    Output param which will receive the positive prefix.
999     * @return          A reference to 'result'.
1000     * Examples: +123, $123, sFr123
1001     * @stable ICU 2.0
1002     */
1003    UnicodeString& getPositivePrefix(UnicodeString& result) const;
1004
1005    /**
1006     * Set the positive prefix.
1007     *
1008     * @param newValue    the new value of the the positive prefix to be set.
1009     * Examples: +123, $123, sFr123
1010     * @stable ICU 2.0
1011     */
1012    virtual void setPositivePrefix(const UnicodeString& newValue);
1013
1014    /**
1015     * Get the negative prefix.
1016     *
1017     * @param result    Output param which will receive the negative prefix.
1018     * @return          A reference to 'result'.
1019     * Examples: -123, ($123) (with negative suffix), sFr-123
1020     * @stable ICU 2.0
1021     */
1022    UnicodeString& getNegativePrefix(UnicodeString& result) const;
1023
1024    /**
1025     * Set the negative prefix.
1026     *
1027     * @param newValue    the new value of the the negative prefix to be set.
1028     * Examples: -123, ($123) (with negative suffix), sFr-123
1029     * @stable ICU 2.0
1030     */
1031    virtual void setNegativePrefix(const UnicodeString& newValue);
1032
1033    /**
1034     * Get the positive suffix.
1035     *
1036     * @param result    Output param which will receive the positive suffix.
1037     * @return          A reference to 'result'.
1038     * Example: 123%
1039     * @stable ICU 2.0
1040     */
1041    UnicodeString& getPositiveSuffix(UnicodeString& result) const;
1042
1043    /**
1044     * Set the positive suffix.
1045     *
1046     * @param newValue    the new value of the positive suffix to be set.
1047     * Example: 123%
1048     * @stable ICU 2.0
1049     */
1050    virtual void setPositiveSuffix(const UnicodeString& newValue);
1051
1052    /**
1053     * Get the negative suffix.
1054     *
1055     * @param result    Output param which will receive the negative suffix.
1056     * @return          A reference to 'result'.
1057     * Examples: -123%, ($123) (with positive suffixes)
1058     * @stable ICU 2.0
1059     */
1060    UnicodeString& getNegativeSuffix(UnicodeString& result) const;
1061
1062    /**
1063     * Set the negative suffix.
1064     *
1065     * @param newValue    the new value of the negative suffix to be set.
1066     * Examples: 123%
1067     * @stable ICU 2.0
1068     */
1069    virtual void setNegativeSuffix(const UnicodeString& newValue);
1070
1071    /**
1072     * Get the multiplier for use in percent, permill, etc.
1073     * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1074     * (For Arabic, use arabic percent symbol).
1075     * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1076     *
1077     * @return    the multiplier for use in percent, permill, etc.
1078     * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1079     * @stable ICU 2.0
1080     */
1081    int32_t getMultiplier(void) const;
1082
1083    /**
1084     * Set the multiplier for use in percent, permill, etc.
1085     * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1086     * (For Arabic, use arabic percent symbol).
1087     * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1088     *
1089     * @param newValue    the new value of the multiplier for use in percent, permill, etc.
1090     * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1091     * @stable ICU 2.0
1092     */
1093    virtual void setMultiplier(int32_t newValue);
1094
1095    /**
1096     * Get the rounding increment.
1097     * @return A positive rounding increment, or 0.0 if rounding
1098     * is not in effect.
1099     * @see #setRoundingIncrement
1100     * @see #getRoundingMode
1101     * @see #setRoundingMode
1102     * @stable ICU 2.0
1103     */
1104    virtual double getRoundingIncrement(void) const;
1105
1106    /**
1107     * Set the rounding increment.  This method also controls whether
1108     * rounding is enabled.
1109     * @param newValue A positive rounding increment, or 0.0 to disable rounding.
1110     * Negative increments are equivalent to 0.0.
1111     * @see #getRoundingIncrement
1112     * @see #getRoundingMode
1113     * @see #setRoundingMode
1114     * @stable ICU 2.0
1115     */
1116    virtual void setRoundingIncrement(double newValue);
1117
1118    /**
1119     * Get the rounding mode.
1120     * @return A rounding mode
1121     * @see #setRoundingIncrement
1122     * @see #getRoundingIncrement
1123     * @see #setRoundingMode
1124     * @stable ICU 2.0
1125     */
1126    virtual ERoundingMode getRoundingMode(void) const;
1127
1128    /**
1129     * Set the rounding mode.  This has no effect unless the rounding
1130     * increment is greater than zero.
1131     * @param roundingMode A rounding mode
1132     * @see #setRoundingIncrement
1133     * @see #getRoundingIncrement
1134     * @see #getRoundingMode
1135     * @stable ICU 2.0
1136     */
1137    virtual void setRoundingMode(ERoundingMode roundingMode);
1138
1139    /**
1140     * Get the width to which the output of format() is padded.
1141     * The width is counted in 16-bit code units.
1142     * @return the format width, or zero if no padding is in effect
1143     * @see #setFormatWidth
1144     * @see #getPadCharacterString
1145     * @see #setPadCharacter
1146     * @see #getPadPosition
1147     * @see #setPadPosition
1148     * @stable ICU 2.0
1149     */
1150    virtual int32_t getFormatWidth(void) const;
1151
1152    /**
1153     * Set the width to which the output of format() is padded.
1154     * The width is counted in 16-bit code units.
1155     * This method also controls whether padding is enabled.
1156     * @param width the width to which to pad the result of
1157     * format(), or zero to disable padding.  A negative
1158     * width is equivalent to 0.
1159     * @see #getFormatWidth
1160     * @see #getPadCharacterString
1161     * @see #setPadCharacter
1162     * @see #getPadPosition
1163     * @see #setPadPosition
1164     * @stable ICU 2.0
1165     */
1166    virtual void setFormatWidth(int32_t width);
1167
1168    /**
1169     * Get the pad character used to pad to the format width.  The
1170     * default is ' '.
1171     * @return a string containing the pad character. This will always
1172     * have a length of one 32-bit code point.
1173     * @see #setFormatWidth
1174     * @see #getFormatWidth
1175     * @see #setPadCharacter
1176     * @see #getPadPosition
1177     * @see #setPadPosition
1178     * @stable ICU 2.0
1179     */
1180    virtual UnicodeString getPadCharacterString() const;
1181
1182    /**
1183     * Set the character used to pad to the format width.  If padding
1184     * is not enabled, then this will take effect if padding is later
1185     * enabled.
1186     * @param padChar a string containing the pad charcter. If the string
1187     * has length 0, then the pad characer is set to ' '.  Otherwise
1188     * padChar.char32At(0) will be used as the pad character.
1189     * @see #setFormatWidth
1190     * @see #getFormatWidth
1191     * @see #getPadCharacterString
1192     * @see #getPadPosition
1193     * @see #setPadPosition
1194     * @stable ICU 2.0
1195     */
1196    virtual void setPadCharacter(const UnicodeString &padChar);
1197
1198    /**
1199     * Get the position at which padding will take place.  This is the location
1200     * at which padding will be inserted if the result of format()
1201     * is shorter than the format width.
1202     * @return the pad position, one of kPadBeforePrefix,
1203     * kPadAfterPrefix, kPadBeforeSuffix, or
1204     * kPadAfterSuffix.
1205     * @see #setFormatWidth
1206     * @see #getFormatWidth
1207     * @see #setPadCharacter
1208     * @see #getPadCharacterString
1209     * @see #setPadPosition
1210     * @see #kPadBeforePrefix
1211     * @see #kPadAfterPrefix
1212     * @see #kPadBeforeSuffix
1213     * @see #kPadAfterSuffix
1214     * @stable ICU 2.0
1215     */
1216    virtual EPadPosition getPadPosition(void) const;
1217
1218    /**
1219     * Set the position at which padding will take place.  This is the location
1220     * at which padding will be inserted if the result of format()
1221     * is shorter than the format width.  This has no effect unless padding is
1222     * enabled.
1223     * @param padPos the pad position, one of kPadBeforePrefix,
1224     * kPadAfterPrefix, kPadBeforeSuffix, or
1225     * kPadAfterSuffix.
1226     * @see #setFormatWidth
1227     * @see #getFormatWidth
1228     * @see #setPadCharacter
1229     * @see #getPadCharacterString
1230     * @see #getPadPosition
1231     * @see #kPadBeforePrefix
1232     * @see #kPadAfterPrefix
1233     * @see #kPadBeforeSuffix
1234     * @see #kPadAfterSuffix
1235     * @stable ICU 2.0
1236     */
1237    virtual void setPadPosition(EPadPosition padPos);
1238
1239    /**
1240     * Return whether or not scientific notation is used.
1241     * @return TRUE if this object formats and parses scientific notation
1242     * @see #setScientificNotation
1243     * @see #getMinimumExponentDigits
1244     * @see #setMinimumExponentDigits
1245     * @see #isExponentSignAlwaysShown
1246     * @see #setExponentSignAlwaysShown
1247     * @stable ICU 2.0
1248     */
1249    virtual UBool isScientificNotation(void);
1250
1251    /**
1252     * Set whether or not scientific notation is used. When scientific notation
1253     * is used, the effective maximum number of integer digits is <= 8.  If the
1254     * maximum number of integer digits is set to more than 8, the effective
1255     * maximum will be 1.  This allows this call to generate a 'default' scientific
1256     * number format without additional changes.
1257     * @param useScientific TRUE if this object formats and parses scientific
1258     * notation
1259     * @see #isScientificNotation
1260     * @see #getMinimumExponentDigits
1261     * @see #setMinimumExponentDigits
1262     * @see #isExponentSignAlwaysShown
1263     * @see #setExponentSignAlwaysShown
1264     * @stable ICU 2.0
1265     */
1266    virtual void setScientificNotation(UBool useScientific);
1267
1268    /**
1269     * Return the minimum exponent digits that will be shown.
1270     * @return the minimum exponent digits that will be shown
1271     * @see #setScientificNotation
1272     * @see #isScientificNotation
1273     * @see #setMinimumExponentDigits
1274     * @see #isExponentSignAlwaysShown
1275     * @see #setExponentSignAlwaysShown
1276     * @stable ICU 2.0
1277     */
1278    virtual int8_t getMinimumExponentDigits(void) const;
1279
1280    /**
1281     * Set the minimum exponent digits that will be shown.  This has no
1282     * effect unless scientific notation is in use.
1283     * @param minExpDig a value >= 1 indicating the fewest exponent digits
1284     * that will be shown.  Values less than 1 will be treated as 1.
1285     * @see #setScientificNotation
1286     * @see #isScientificNotation
1287     * @see #getMinimumExponentDigits
1288     * @see #isExponentSignAlwaysShown
1289     * @see #setExponentSignAlwaysShown
1290     * @stable ICU 2.0
1291     */
1292    virtual void setMinimumExponentDigits(int8_t minExpDig);
1293
1294    /**
1295     * Return whether the exponent sign is always shown.
1296     * @return TRUE if the exponent is always prefixed with either the
1297     * localized minus sign or the localized plus sign, false if only negative
1298     * exponents are prefixed with the localized minus sign.
1299     * @see #setScientificNotation
1300     * @see #isScientificNotation
1301     * @see #setMinimumExponentDigits
1302     * @see #getMinimumExponentDigits
1303     * @see #setExponentSignAlwaysShown
1304     * @stable ICU 2.0
1305     */
1306    virtual UBool isExponentSignAlwaysShown(void);
1307
1308    /**
1309     * Set whether the exponent sign is always shown.  This has no effect
1310     * unless scientific notation is in use.
1311     * @param expSignAlways TRUE if the exponent is always prefixed with either
1312     * the localized minus sign or the localized plus sign, false if only
1313     * negative exponents are prefixed with the localized minus sign.
1314     * @see #setScientificNotation
1315     * @see #isScientificNotation
1316     * @see #setMinimumExponentDigits
1317     * @see #getMinimumExponentDigits
1318     * @see #isExponentSignAlwaysShown
1319     * @stable ICU 2.0
1320     */
1321    virtual void setExponentSignAlwaysShown(UBool expSignAlways);
1322
1323    /**
1324     * Return the grouping size. Grouping size is the number of digits between
1325     * grouping separators in the integer portion of a number.  For example,
1326     * in the number "123,456.78", the grouping size is 3.
1327     *
1328     * @return    the grouping size.
1329     * @see setGroupingSize
1330     * @see NumberFormat::isGroupingUsed
1331     * @see DecimalFormatSymbols::getGroupingSeparator
1332     * @stable ICU 2.0
1333     */
1334    int32_t getGroupingSize(void) const;
1335
1336    /**
1337     * Set the grouping size. Grouping size is the number of digits between
1338     * grouping separators in the integer portion of a number.  For example,
1339     * in the number "123,456.78", the grouping size is 3.
1340     *
1341     * @param newValue    the new value of the grouping size.
1342     * @see getGroupingSize
1343     * @see NumberFormat::setGroupingUsed
1344     * @see DecimalFormatSymbols::setGroupingSeparator
1345     * @stable ICU 2.0
1346     */
1347    virtual void setGroupingSize(int32_t newValue);
1348
1349    /**
1350     * Return the secondary grouping size. In some locales one
1351     * grouping interval is used for the least significant integer
1352     * digits (the primary grouping size), and another is used for all
1353     * others (the secondary grouping size).  A formatter supporting a
1354     * secondary grouping size will return a positive integer unequal
1355     * to the primary grouping size returned by
1356     * getGroupingSize().  For example, if the primary
1357     * grouping size is 4, and the secondary grouping size is 2, then
1358     * the number 123456789 formats as "1,23,45,6789", and the pattern
1359     * appears as "#,##,###0".
1360     * @return the secondary grouping size, or a value less than
1361     * one if there is none
1362     * @see setSecondaryGroupingSize
1363     * @see NumberFormat::isGroupingUsed
1364     * @see DecimalFormatSymbols::getGroupingSeparator
1365     * @stable ICU 2.4
1366     */
1367    int32_t getSecondaryGroupingSize(void) const;
1368
1369    /**
1370     * Set the secondary grouping size. If set to a value less than 1,
1371     * then secondary grouping is turned off, and the primary grouping
1372     * size is used for all intervals, not just the least significant.
1373     *
1374     * @param newValue    the new value of the secondary grouping size.
1375     * @see getSecondaryGroupingSize
1376     * @see NumberFormat#setGroupingUsed
1377     * @see DecimalFormatSymbols::setGroupingSeparator
1378     * @stable ICU 2.4
1379     */
1380    virtual void setSecondaryGroupingSize(int32_t newValue);
1381
1382    /**
1383     * Allows you to get the behavior of the decimal separator with integers.
1384     * (The decimal separator will always appear with decimals.)
1385     *
1386     * @return    TRUE if the decimal separator always appear with decimals.
1387     * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1388     * @stable ICU 2.0
1389     */
1390    UBool isDecimalSeparatorAlwaysShown(void) const;
1391
1392    /**
1393     * Allows you to set the behavior of the decimal separator with integers.
1394     * (The decimal separator will always appear with decimals.)
1395     *
1396     * @param newValue    set TRUE if the decimal separator will always appear with decimals.
1397     * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1398     * @stable ICU 2.0
1399     */
1400    virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
1401
1402    /**
1403     * Synthesizes a pattern string that represents the current state
1404     * of this Format object.
1405     *
1406     * @param result    Output param which will receive the pattern.
1407     *                  Previous contents are deleted.
1408     * @return          A reference to 'result'.
1409     * @see applyPattern
1410     * @stable ICU 2.0
1411     */
1412    virtual UnicodeString& toPattern(UnicodeString& result) const;
1413
1414    /**
1415     * Synthesizes a localized pattern string that represents the current
1416     * state of this Format object.
1417     *
1418     * @param result    Output param which will receive the localized pattern.
1419     *                  Previous contents are deleted.
1420     * @return          A reference to 'result'.
1421     * @see applyPattern
1422     * @stable ICU 2.0
1423     */
1424    virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
1425
1426    /**
1427     * Apply the given pattern to this Format object.  A pattern is a
1428     * short-hand specification for the various formatting properties.
1429     * These properties can also be changed individually through the
1430     * various setter methods.
1431     * <P>
1432     * There is no limit to integer digits are set
1433     * by this routine, since that is the typical end-user desire;
1434     * use setMaximumInteger if you want to set a real value.
1435     * For negative numbers, use a second pattern, separated by a semicolon
1436     * <pre>
1437     * .      Example "#,#00.0#" -> 1,234.56
1438     * </pre>
1439     * This means a minimum of 2 integer digits, 1 fraction digit, and
1440     * a maximum of 2 fraction digits.
1441     * <pre>
1442     * .      Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1443     * </pre>
1444     * In negative patterns, the minimum and maximum counts are ignored;
1445     * these are presumed to be set in the positive pattern.
1446     *
1447     * @param pattern    The pattern to be applied.
1448     * @param parseError Struct to recieve information on position
1449     *                   of error if an error is encountered
1450     * @param status     Output param set to success/failure code on
1451     *                   exit. If the pattern is invalid, this will be
1452     *                   set to a failure result.
1453     * @stable ICU 2.0
1454     */
1455    virtual void applyPattern(const UnicodeString& pattern,
1456                             UParseError& parseError,
1457                             UErrorCode& status);
1458    /**
1459     * Sets the pattern.
1460     * @param pattern   The pattern to be applied.
1461     * @param status    Output param set to success/failure code on
1462     *                  exit. If the pattern is invalid, this will be
1463     *                  set to a failure result.
1464     * @stable ICU 2.0
1465     */
1466    virtual void applyPattern(const UnicodeString& pattern,
1467                             UErrorCode& status);
1468
1469    /**
1470     * Apply the given pattern to this Format object.  The pattern
1471     * is assumed to be in a localized notation. A pattern is a
1472     * short-hand specification for the various formatting properties.
1473     * These properties can also be changed individually through the
1474     * various setter methods.
1475     * <P>
1476     * There is no limit to integer digits are set
1477     * by this routine, since that is the typical end-user desire;
1478     * use setMaximumInteger if you want to set a real value.
1479     * For negative numbers, use a second pattern, separated by a semicolon
1480     * <pre>
1481     * .      Example "#,#00.0#" -> 1,234.56
1482     * </pre>
1483     * This means a minimum of 2 integer digits, 1 fraction digit, and
1484     * a maximum of 2 fraction digits.
1485     *
1486     * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1487     *
1488     * In negative patterns, the minimum and maximum counts are ignored;
1489     * these are presumed to be set in the positive pattern.
1490     *
1491     * @param pattern   The localized pattern to be applied.
1492     * @param parseError Struct to recieve information on position
1493     *                   of error if an error is encountered
1494     * @param status    Output param set to success/failure code on
1495     *                  exit. If the pattern is invalid, this will be
1496     *                  set to a failure result.
1497     * @stable ICU 2.0
1498     */
1499    virtual void applyLocalizedPattern(const UnicodeString& pattern,
1500                                       UParseError& parseError,
1501                                       UErrorCode& status);
1502
1503    /**
1504     * Apply the given pattern to this Format object.
1505     *
1506     * @param pattern   The localized pattern to be applied.
1507     * @param status    Output param set to success/failure code on
1508     *                  exit. If the pattern is invalid, this will be
1509     *                  set to a failure result.
1510     * @stable ICU 2.0
1511     */
1512    virtual void applyLocalizedPattern(const UnicodeString& pattern,
1513                                       UErrorCode& status);
1514
1515
1516    /**
1517     * Sets the maximum number of digits allowed in the integer portion of a
1518     * number. This override limits the integer digit count to 309.
1519     *
1520     * @param newValue    the new value of the maximum number of digits
1521     *                      allowed in the integer portion of a number.
1522     * @see NumberFormat#setMaximumIntegerDigits
1523     * @stable ICU 2.0
1524     */
1525    virtual void setMaximumIntegerDigits(int32_t newValue);
1526
1527    /**
1528     * Sets the minimum number of digits allowed in the integer portion of a
1529     * number. This override limits the integer digit count to 309.
1530     *
1531     * @param newValue    the new value of the minimum number of digits
1532     *                      allowed in the integer portion of a number.
1533     * @see NumberFormat#setMinimumIntegerDigits
1534     * @stable ICU 2.0
1535     */
1536    virtual void setMinimumIntegerDigits(int32_t newValue);
1537
1538    /**
1539     * Sets the maximum number of digits allowed in the fraction portion of a
1540     * number. This override limits the fraction digit count to 340.
1541     *
1542     * @param newValue    the new value of the maximum number of digits
1543     *                    allowed in the fraction portion of a number.
1544     * @see NumberFormat#setMaximumFractionDigits
1545     * @stable ICU 2.0
1546     */
1547    virtual void setMaximumFractionDigits(int32_t newValue);
1548
1549    /**
1550     * Sets the minimum number of digits allowed in the fraction portion of a
1551     * number. This override limits the fraction digit count to 340.
1552     *
1553     * @param newValue    the new value of the minimum number of digits
1554     *                    allowed in the fraction portion of a number.
1555     * @see NumberFormat#setMinimumFractionDigits
1556     * @stable ICU 2.0
1557     */
1558    virtual void setMinimumFractionDigits(int32_t newValue);
1559
1560    /**
1561     * Returns the minimum number of significant digits that will be
1562     * displayed. This value has no effect unless areSignificantDigitsUsed()
1563     * returns true.
1564     * @return the fewest significant digits that will be shown
1565     * @stable ICU 3.0
1566     */
1567    int32_t getMinimumSignificantDigits() const;
1568
1569    /**
1570     * Returns the maximum number of significant digits that will be
1571     * displayed. This value has no effect unless areSignificantDigitsUsed()
1572     * returns true.
1573     * @return the most significant digits that will be shown
1574     * @stable ICU 3.0
1575     */
1576    int32_t getMaximumSignificantDigits() const;
1577
1578    /**
1579     * Sets the minimum number of significant digits that will be
1580     * displayed.  If <code>min</code> is less than one then it is set
1581     * to one.  If the maximum significant digits count is less than
1582     * <code>min</code>, then it is set to <code>min</code>. This
1583     * value has no effect unless areSignificantDigits() returns true.
1584     * @param min the fewest significant digits to be shown
1585     * @stable ICU 3.0
1586     */
1587    void setMinimumSignificantDigits(int32_t min);
1588
1589    /**
1590     * Sets the maximum number of significant digits that will be
1591     * displayed.  If <code>max</code> is less than one then it is set
1592     * to one.  If the minimum significant digits count is greater
1593     * than <code>max</code>, then it is set to <code>max</code>.
1594     * This value has no effect unless areSignificantDigits() returns
1595     * true.
1596     * @param max the most significant digits to be shown
1597     * @stable ICU 3.0
1598     */
1599    void setMaximumSignificantDigits(int32_t max);
1600
1601    /**
1602     * Returns true if significant digits are in use, or false if
1603     * integer and fraction digit counts are in use.
1604     * @return true if significant digits are in use
1605     * @stable ICU 3.0
1606     */
1607    UBool areSignificantDigitsUsed() const;
1608
1609    /**
1610     * Sets whether significant digits are in use, or integer and
1611     * fraction digit counts are in use.
1612     * @param useSignificantDigits true to use significant digits, or
1613     * false to use integer and fraction digit counts
1614     * @stable ICU 3.0
1615     */
1616    void setSignificantDigitsUsed(UBool useSignificantDigits);
1617
1618 public:
1619    /**
1620     * Sets the currency used to display currency
1621     * amounts.  This takes effect immediately, if this format is a
1622     * currency format.  If this format is not a currency format, then
1623     * the currency is used if and when this object becomes a
1624     * currency format through the application of a new pattern.
1625     * @param theCurrency a 3-letter ISO code indicating new currency
1626     * to use.  It need not be null-terminated.  May be the empty
1627     * string or NULL to indicate no currency.
1628     * @param ec input-output error code
1629     * @stable ICU 3.0
1630     */
1631    virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
1632
1633    /**
1634     * Sets the currency used to display currency amounts.  See
1635     * setCurrency(const UChar*, UErrorCode&).
1636     * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&).
1637     */
1638    virtual void setCurrency(const UChar* theCurrency);
1639
1640    /**
1641     * The resource tags we use to retrieve decimal format data from
1642     * locale resource bundles.
1643     * @deprecated ICU 3.4. This string has no public purpose. Please don't use it.
1644     */
1645    static const char fgNumberPatterns[];
1646
1647public:
1648
1649    /**
1650     * Return the class ID for this class.  This is useful only for
1651     * comparing to a return value from getDynamicClassID().  For example:
1652     * <pre>
1653     * .      Base* polymorphic_pointer = createPolymorphicObject();
1654     * .      if (polymorphic_pointer->getDynamicClassID() ==
1655     * .          Derived::getStaticClassID()) ...
1656     * </pre>
1657     * @return          The class ID for all objects of this class.
1658     * @stable ICU 2.0
1659     */
1660    static UClassID U_EXPORT2 getStaticClassID(void);
1661
1662    /**
1663     * Returns a unique class ID POLYMORPHICALLY.  Pure virtual override.
1664     * This method is to implement a simple version of RTTI, since not all
1665     * C++ compilers support genuine RTTI.  Polymorphic operator==() and
1666     * clone() methods call this method.
1667     *
1668     * @return          The class ID for this object. All objects of a
1669     *                  given class have the same class ID.  Objects of
1670     *                  other classes have different class IDs.
1671     * @stable ICU 2.0
1672     */
1673    virtual UClassID getDynamicClassID(void) const;
1674
1675private:
1676    DecimalFormat(); // default constructor not implemented
1677
1678    int32_t precision(UBool isIntegral) const;
1679
1680    /**
1681     * Do real work of constructing a new DecimalFormat.
1682     */
1683    void construct(UErrorCode&               status,
1684                   UParseError&             parseErr,
1685                   const UnicodeString*     pattern = 0,
1686                   DecimalFormatSymbols*    symbolsToAdopt = 0
1687                   );
1688
1689    /**
1690     * Does the real work of generating a pattern.
1691     *
1692     * @param result     Output param which will receive the pattern.
1693     *                   Previous contents are deleted.
1694     * @param localized  TRUE return localized pattern.
1695     * @return           A reference to 'result'.
1696     */
1697    UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
1698
1699    /**
1700     * Does the real work of applying a pattern.
1701     * @param pattern    The pattern to be applied.
1702     * @param localized  If true, the pattern is localized; else false.
1703     * @param parseError Struct to recieve information on position
1704     *                   of error if an error is encountered
1705     * @param status     Output param set to success/failure code on
1706     *                   exit. If the pattern is invalid, this will be
1707     *                   set to a failure result.
1708     */
1709    void applyPattern(const UnicodeString& pattern,
1710                            UBool localized,
1711                            UParseError& parseError,
1712                            UErrorCode& status);
1713    /**
1714     * Do the work of formatting a number, either a double or a long.
1715     *
1716     * @param appendTo       Output parameter to receive result.
1717     *                       Result is appended to existing contents.
1718     * @param fieldPosition  On input: an alignment field, if desired.
1719     *                       On output: the offsets of the alignment field.
1720     * @param digits         the digits to be formatted.
1721     * @param isInteger      if TRUE format the digits as Integer.
1722     * @return               Reference to 'appendTo' parameter.
1723     */
1724    UnicodeString& subformat(UnicodeString& appendTo,
1725                             FieldPosition& fieldPosition,
1726                             DigitList& digits,
1727                             UBool         isInteger) const;
1728
1729    UnicodeString& subformat(UnicodeString& appendTo,
1730                             FieldPosition& fieldPosition,
1731                             AttrBuffer attrBuffer,
1732                             DigitList& digits,
1733                             UBool         isInteger) const;
1734
1735    void parse(const UnicodeString& text,
1736               Formattable& result,
1737               ParsePosition& pos,
1738               UBool parseCurrency) const;
1739
1740    enum {
1741        fgStatusInfinite,
1742        fgStatusLength      // Leave last in list.
1743    } StatusFlags;
1744
1745    UBool subparse(const UnicodeString& text, ParsePosition& parsePosition,
1746                   DigitList& digits, UBool* status,
1747                   UChar* currency) const;
1748
1749    int32_t skipPadding(const UnicodeString& text, int32_t position) const;
1750
1751    int32_t compareAffix(const UnicodeString& input,
1752                         int32_t pos,
1753                         UBool isNegative,
1754                         UBool isPrefix,
1755                         UChar* currency) const;
1756
1757    static int32_t compareSimpleAffix(const UnicodeString& affix,
1758                                      const UnicodeString& input,
1759                                      int32_t pos);
1760
1761    static int32_t skipRuleWhiteSpace(const UnicodeString& text, int32_t pos);
1762
1763    static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
1764
1765    int32_t compareComplexAffix(const UnicodeString& affixPat,
1766                                const UnicodeString& input,
1767                                int32_t pos,
1768                                UChar* currency) const;
1769
1770    static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
1771
1772    static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
1773
1774    /**
1775     * Get a decimal format symbol.
1776     * Returns a const reference to the symbol string.
1777     * @internal
1778     */
1779    inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
1780
1781    int32_t appendAffix(UnicodeString& buf, double number,
1782                        UBool isNegative, UBool isPrefix) const;
1783
1784    int32_t appendAffix(UnicodeString& buf, double number, AttrBuffer attrBuffer,
1785                        UBool isNegative, UBool isPrefix) const;
1786
1787    /**
1788     * Append an affix to the given UnicodeString, using quotes if
1789     * there are special characters.  Single quotes themselves must be
1790     * escaped in either case.
1791     */
1792    void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
1793                            UBool localized) const;
1794
1795    void appendAffixPattern(UnicodeString& appendTo,
1796                            const UnicodeString* affixPattern,
1797                            const UnicodeString& expAffix, UBool localized) const;
1798
1799    void expandAffix(const UnicodeString& pattern,
1800                     UnicodeString& affix,
1801                     double number,
1802                     UBool doFormat) const;
1803
1804    void expandAffix(const UnicodeString& pattern,
1805                     UnicodeString& affix,
1806                     double number,
1807                     AttrBuffer attrBuffer,
1808                     UBool doFormat) const;
1809
1810    void expandAffixes();
1811
1812    static double round(double a, ERoundingMode mode, UBool isNegative);
1813
1814    void addPadding(UnicodeString& appendTo,
1815                    FieldPosition& fieldPosition,
1816                    int32_t prefixLen, int32_t suffixLen) const;
1817
1818    UBool isGroupingPosition(int32_t pos) const;
1819
1820    void setCurrencyForSymbols();
1821
1822    /**
1823     * Constants.
1824     */
1825    //static const int8_t fgMaxDigit; // The largest digit, in this case 9
1826
1827    /*transient*/ //DigitList* fDigitList;
1828
1829    UnicodeString           fPositivePrefix;
1830    UnicodeString           fPositiveSuffix;
1831    UnicodeString           fNegativePrefix;
1832    UnicodeString           fNegativeSuffix;
1833    UnicodeString*          fPosPrefixPattern;
1834    UnicodeString*          fPosSuffixPattern;
1835    UnicodeString*          fNegPrefixPattern;
1836    UnicodeString*          fNegSuffixPattern;
1837
1838    /**
1839     * Formatter for ChoiceFormat-based currency names.  If this field
1840     * is not null, then delegate to it to format currency symbols.
1841     * @since ICU 2.6
1842     */
1843    ChoiceFormat*           fCurrencyChoice;
1844
1845    int32_t                 fMultiplier;
1846    int32_t                 fGroupingSize;
1847    int32_t                 fGroupingSize2;
1848    UBool                   fDecimalSeparatorAlwaysShown;
1849    /*transient*/ UBool     fIsCurrencyFormat;
1850    DecimalFormatSymbols*   fSymbols;
1851
1852    UBool                   fUseSignificantDigits;
1853    int32_t                 fMinSignificantDigits;
1854    int32_t                 fMaxSignificantDigits;
1855
1856    UBool                   fUseExponentialNotation;
1857    int8_t                  fMinExponentDigits;
1858    UBool                   fExponentSignAlwaysShown;
1859
1860    /* If fRoundingIncrement is NULL, there is no rounding.  Otherwise, round to
1861     * fRoundingIncrement.getDouble().  Since this operation may be expensive,
1862     * we cache the result in fRoundingDouble.  All methods that update
1863     * fRoundingIncrement also update fRoundingDouble. */
1864    DigitList*              fRoundingIncrement;
1865    /*transient*/ double    fRoundingDouble;
1866    ERoundingMode           fRoundingMode;
1867
1868    UChar32                 fPad;
1869    int32_t                 fFormatWidth;
1870    EPadPosition            fPadPosition;
1871
1872    void addAttribute(AttrBuffer attrBuffer, char *fieldname, int begin, int end) const;
1873
1874protected:
1875
1876    /**
1877     * Returns the currency in effect for this formatter.  Subclasses
1878     * should override this method as needed.  Unlike getCurrency(),
1879     * this method should never return "".
1880     * @result output parameter for null-terminated result, which must
1881     * have a capacity of at least 4
1882     * @internal
1883     */
1884    virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
1885
1886  /** number of integer digits
1887   * @stable ICU 2.4
1888   */
1889    static const int32_t  kDoubleIntegerDigits;
1890  /** number of fraction digits
1891   * @stable ICU 2.4
1892   */
1893    static const int32_t  kDoubleFractionDigits;
1894
1895    /**
1896     * When someone turns on scientific mode, we assume that more than this
1897     * number of digits is due to flipping from some other mode that didn't
1898     * restrict the maximum, and so we force 1 integer digit.  We don't bother
1899     * to track and see if someone is using exponential notation with more than
1900     * this number, it wouldn't make sense anyway, and this is just to make sure
1901     * that someone turning on scientific mode with default settings doesn't
1902     * end up with lots of zeroes.
1903     * @stable ICU 2.8
1904     */
1905    static const int32_t  kMaxScientificIntegerDigits;
1906};
1907
1908inline UnicodeString&
1909DecimalFormat::format(const Formattable& obj,
1910                      UnicodeString& appendTo,
1911                      UErrorCode& status) const {
1912    // Don't use Format:: - use immediate base class only,
1913    // in case immediate base modifies behavior later.
1914    return NumberFormat::format(obj, appendTo, status);
1915}
1916
1917inline UnicodeString&
1918DecimalFormat::format(double number,
1919                      UnicodeString& appendTo) const {
1920    FieldPosition pos(0);
1921    return format(number, appendTo, pos, NULL);
1922}
1923
1924inline UnicodeString&
1925DecimalFormat::format(int32_t number,
1926                      UnicodeString& appendTo) const {
1927    FieldPosition pos(0);
1928    return format((int64_t)number, appendTo, pos, NULL);
1929}
1930
1931inline const UnicodeString &
1932DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
1933    return fSymbols->getConstSymbol(symbol);
1934}
1935
1936U_NAMESPACE_END
1937
1938#endif /* #if !UCONFIG_NO_FORMATTING */
1939
1940#endif // _DECIMFMT
1941//eof
1942