decimfmt.h revision 8393335b955da7340c9f19b1b4b2d6c0c2c04be7
1/*
2********************************************************************************
3*   Copyright (C) 1997-2013, 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*   01/30/13    emmons      Added Scaling methods
22********************************************************************************
23*/
24
25#ifndef DECIMFMT_H
26#define DECIMFMT_H
27
28#include "unicode/utypes.h"
29/**
30 * \file
31 * \brief C++ API: Formats decimal numbers.
32 */
33
34#if !UCONFIG_NO_FORMATTING
35
36#include "unicode/dcfmtsym.h"
37#include "unicode/numfmt.h"
38#include "unicode/locid.h"
39#include "unicode/fpositer.h"
40#include "unicode/stringpiece.h"
41#include "unicode/curramt.h"
42#include "unicode/enumset.h"
43
44#ifndef U_HIDE_INTERNAL_API
45/**
46 * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE
47 * @internal
48 */
49#if UCONFIG_FORMAT_FASTPATHS_49
50#define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16
51#endif
52#endif  /* U_HIDE_INTERNAL_API */
53
54U_NAMESPACE_BEGIN
55
56class DigitList;
57class ChoiceFormat;
58class CurrencyPluralInfo;
59class Hashtable;
60class UnicodeSet;
61class FieldPositionHandler;
62
63// explicit template instantiation. see digitlst.h
64#if defined (_MSC_VER)
65template class U_I18N_API    EnumSet<UNumberFormatAttribute,
66            UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
67            UNUM_LIMIT_BOOLEAN_ATTRIBUTE>;
68#endif
69
70/**
71 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal
72 * numbers. It has a variety of features designed to make it possible to parse
73 * and format numbers in any locale, including support for Western, Arabic, or
74 * Indic digits.  It also supports different flavors of numbers, including
75 * integers ("123"), fixed-point numbers ("123.4"), scientific notation
76 * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123",
77 * "123 US dollars").  All of these flavors can be easily localized.
78 *
79 * <p>To obtain a NumberFormat for a specific locale (including the default
80 * locale) call one of NumberFormat's factory methods such as
81 * createInstance(). Do not call the DecimalFormat constructors directly, unless
82 * you know what you are doing, since the NumberFormat factory methods may
83 * return subclasses other than DecimalFormat.
84 *
85 * <p><strong>Example Usage</strong>
86 *
87 * \code
88 *     // Normally we would have a GUI with a menu for this
89 *     int32_t locCount;
90 *     const Locale* locales = NumberFormat::getAvailableLocales(locCount);
91 *
92 *     double myNumber = -1234.56;
93 *     UErrorCode success = U_ZERO_ERROR;
94 *     NumberFormat* form;
95 *
96 *     // Print out a number with the localized number, currency and percent
97 *     // format for each locale.
98 *     UnicodeString countryName;
99 *     UnicodeString displayName;
100 *     UnicodeString str;
101 *     UnicodeString pattern;
102 *     Formattable fmtable;
103 *     for (int32_t j = 0; j < 3; ++j) {
104 *         cout << endl << "FORMAT " << j << endl;
105 *         for (int32_t i = 0; i < locCount; ++i) {
106 *             if (locales[i].getCountry(countryName).size() == 0) {
107 *                 // skip language-only
108 *                 continue;
109 *             }
110 *             switch (j) {
111 *             case 0:
112 *                 form = NumberFormat::createInstance(locales[i], success ); break;
113 *             case 1:
114 *                 form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
115 *             default:
116 *                 form = NumberFormat::createPercentInstance(locales[i], success ); break;
117 *             }
118 *             if (form) {
119 *                 str.remove();
120 *                 pattern = ((DecimalFormat*)form)->toPattern(pattern);
121 *                 cout << locales[i].getDisplayName(displayName) << ": " << pattern;
122 *                 cout << "  ->  " << form->format(myNumber,str) << endl;
123 *                 form->parse(form->format(myNumber,str), fmtable, success);
124 *                 delete form;
125 *             }
126 *         }
127 *     }
128 * \endcode
129 * <P>
130 * Another example use createInstance(style)
131 * <P>
132 * <pre>
133 * <strong>// Print out a number using the localized number, currency,
134 * // percent, scientific, integer, iso currency, and plural currency
135 * // format for each locale</strong>
136 * Locale* locale = new Locale("en", "US");
137 * double myNumber = 1234.56;
138 * UErrorCode success = U_ZERO_ERROR;
139 * UnicodeString str;
140 * Formattable fmtable;
141 * for (int j=NumberFormat::kNumberStyle;
142 *      j<=NumberFormat::kPluralCurrencyStyle;
143 *      ++j) {
144 *     NumberFormat* format = NumberFormat::createInstance(locale, j, success);
145 *     str.remove();
146 *     cout << "format result " << form->format(myNumber, str) << endl;
147 *     format->parse(form->format(myNumber, str), fmtable, success);
148 * }</pre>
149 *
150 *
151 * <p><strong>Patterns</strong>
152 *
153 * <p>A DecimalFormat consists of a <em>pattern</em> and a set of
154 * <em>symbols</em>.  The pattern may be set directly using
155 * applyPattern(), or indirectly using other API methods which
156 * manipulate aspects of the pattern, such as the minimum number of integer
157 * digits.  The symbols are stored in a DecimalFormatSymbols
158 * object.  When using the NumberFormat factory methods, the
159 * pattern and symbols are read from ICU's locale data.
160 *
161 * <p><strong>Special Pattern Characters</strong>
162 *
163 * <p>Many characters in a pattern are taken literally; they are matched during
164 * parsing and output unchanged during formatting.  Special characters, on the
165 * other hand, stand for other characters, strings, or classes of characters.
166 * For example, the '#' character is replaced by a localized digit.  Often the
167 * replacement character is the same as the pattern character; in the U.S. locale,
168 * the ',' grouping character is replaced by ','.  However, the replacement is
169 * still happening, and if the symbols are modified, the grouping character
170 * changes.  Some special characters affect the behavior of the formatter by
171 * their presence; for example, if the percent character is seen, then the
172 * value is multiplied by 100 before being displayed.
173 *
174 * <p>To insert a special character in a pattern as a literal, that is, without
175 * any special meaning, the character must be quoted.  There are some exceptions to
176 * this which are noted below.
177 *
178 * <p>The characters listed here are used in non-localized patterns.  Localized
179 * patterns use the corresponding characters taken from this formatter's
180 * DecimalFormatSymbols object instead, and these characters lose
181 * their special status.  Two exceptions are the currency sign and quote, which
182 * are not localized.
183 *
184 * <table border=0 cellspacing=3 cellpadding=0>
185 *   <tr bgcolor="#ccccff">
186 *     <td align=left><strong>Symbol</strong>
187 *     <td align=left><strong>Location</strong>
188 *     <td align=left><strong>Localized?</strong>
189 *     <td align=left><strong>Meaning</strong>
190 *   <tr valign=top>
191 *     <td><code>0</code>
192 *     <td>Number
193 *     <td>Yes
194 *     <td>Digit
195 *   <tr valign=top bgcolor="#eeeeff">
196 *     <td><code>1-9</code>
197 *     <td>Number
198 *     <td>Yes
199 *     <td>'1' through '9' indicate rounding.
200 *   <tr valign=top>
201 *     <td><code>\htmlonly&#x40;\endhtmlonly</code> <!--doxygen doesn't like @-->
202 *     <td>Number
203 *     <td>No
204 *     <td>Significant digit
205 *   <tr valign=top bgcolor="#eeeeff">
206 *     <td><code>#</code>
207 *     <td>Number
208 *     <td>Yes
209 *     <td>Digit, zero shows as absent
210 *   <tr valign=top>
211 *     <td><code>.</code>
212 *     <td>Number
213 *     <td>Yes
214 *     <td>Decimal separator or monetary decimal separator
215 *   <tr valign=top bgcolor="#eeeeff">
216 *     <td><code>-</code>
217 *     <td>Number
218 *     <td>Yes
219 *     <td>Minus sign
220 *   <tr valign=top>
221 *     <td><code>,</code>
222 *     <td>Number
223 *     <td>Yes
224 *     <td>Grouping separator
225 *   <tr valign=top bgcolor="#eeeeff">
226 *     <td><code>E</code>
227 *     <td>Number
228 *     <td>Yes
229 *     <td>Separates mantissa and exponent in scientific notation.
230 *         <em>Need not be quoted in prefix or suffix.</em>
231 *   <tr valign=top>
232 *     <td><code>+</code>
233 *     <td>Exponent
234 *     <td>Yes
235 *     <td>Prefix positive exponents with localized plus sign.
236 *         <em>Need not be quoted in prefix or suffix.</em>
237 *   <tr valign=top bgcolor="#eeeeff">
238 *     <td><code>;</code>
239 *     <td>Subpattern boundary
240 *     <td>Yes
241 *     <td>Separates positive and negative subpatterns
242 *   <tr valign=top>
243 *     <td><code>\%</code>
244 *     <td>Prefix or suffix
245 *     <td>Yes
246 *     <td>Multiply by 100 and show as percentage
247 *   <tr valign=top bgcolor="#eeeeff">
248 *     <td><code>\\u2030</code>
249 *     <td>Prefix or suffix
250 *     <td>Yes
251 *     <td>Multiply by 1000 and show as per mille
252 *   <tr valign=top>
253 *     <td><code>\htmlonly&curren;\endhtmlonly</code> (<code>\\u00A4</code>)
254 *     <td>Prefix or suffix
255 *     <td>No
256 *     <td>Currency sign, replaced by currency symbol.  If
257 *         doubled, replaced by international currency symbol.
258 *         If tripled, replaced by currency plural names, for example,
259 *         "US dollar" or "US dollars" for America.
260 *         If present in a pattern, the monetary decimal separator
261 *         is used instead of the decimal separator.
262 *   <tr valign=top bgcolor="#eeeeff">
263 *     <td><code>'</code>
264 *     <td>Prefix or suffix
265 *     <td>No
266 *     <td>Used to quote special characters in a prefix or suffix,
267 *         for example, <code>"'#'#"</code> formats 123 to
268 *         <code>"#123"</code>.  To create a single quote
269 *         itself, use two in a row: <code>"# o''clock"</code>.
270 *   <tr valign=top>
271 *     <td><code>*</code>
272 *     <td>Prefix or suffix boundary
273 *     <td>Yes
274 *     <td>Pad escape, precedes pad character
275 * </table>
276 *
277 * <p>A DecimalFormat pattern contains a postive and negative
278 * subpattern, for example, "#,##0.00;(#,##0.00)".  Each subpattern has a
279 * prefix, a numeric part, and a suffix.  If there is no explicit negative
280 * subpattern, the negative subpattern is the localized minus sign prefixed to the
281 * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00".  If there
282 * is an explicit negative subpattern, it serves only to specify the negative
283 * prefix and suffix; the number of digits, minimal digits, and other
284 * characteristics are ignored in the negative subpattern. That means that
285 * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
286 *
287 * <p>The prefixes, suffixes, and various symbols used for infinity, digits,
288 * thousands separators, decimal separators, etc. may be set to arbitrary
289 * values, and they will appear properly during formatting.  However, care must
290 * be taken that the symbols and strings do not conflict, or parsing will be
291 * unreliable.  For example, either the positive and negative prefixes or the
292 * suffixes must be distinct for parse() to be able
293 * to distinguish positive from negative values.  Another example is that the
294 * decimal separator and thousands separator should be distinct characters, or
295 * parsing will be impossible.
296 *
297 * <p>The <em>grouping separator</em> is a character that separates clusters of
298 * integer digits to make large numbers more legible.  It commonly used for
299 * thousands, but in some locales it separates ten-thousands.  The <em>grouping
300 * size</em> is the number of digits between the grouping separators, such as 3
301 * for "100,000,000" or 4 for "1 0000 0000". There are actually two different
302 * grouping sizes: One used for the least significant integer digits, the
303 * <em>primary grouping size</em>, and one used for all others, the
304 * <em>secondary grouping size</em>.  In most locales these are the same, but
305 * sometimes they are different. For example, if the primary grouping interval
306 * is 3, and the secondary is 2, then this corresponds to the pattern
307 * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789".  If a
308 * pattern contains multiple grouping separators, the interval between the last
309 * one and the end of the integer defines the primary grouping size, and the
310 * interval between the last two defines the secondary grouping size. All others
311 * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
312 *
313 * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
314 * DecimalFormat to set a failing UErrorCode.
315 *
316 * <p><strong>Pattern BNF</strong>
317 *
318 * <pre>
319 * pattern    := subpattern (';' subpattern)?
320 * subpattern := prefix? number exponent? suffix?
321 * number     := (integer ('.' fraction)?) | sigDigits
322 * prefix     := '\\u0000'..'\\uFFFD' - specialCharacters
323 * suffix     := '\\u0000'..'\\uFFFD' - specialCharacters
324 * integer    := '#'* '0'* '0'
325 * fraction   := '0'* '#'*
326 * sigDigits  := '#'* '@' '@'* '#'*
327 * exponent   := 'E' '+'? '0'* '0'
328 * padSpec    := '*' padChar
329 * padChar    := '\\u0000'..'\\uFFFD' - quote
330 * &nbsp;
331 * Notation:
332 *   X*       0 or more instances of X
333 *   X?       0 or 1 instances of X
334 *   X|Y      either X or Y
335 *   C..D     any character from C up to D, inclusive
336 *   S-T      characters in S, except those in T
337 * </pre>
338 * The first subpattern is for positive numbers. The second (optional)
339 * subpattern is for negative numbers.
340 *
341 * <p>Not indicated in the BNF syntax above:
342 *
343 * <ul><li>The grouping separator ',' can occur inside the integer and
344 * sigDigits elements, between any two pattern characters of that
345 * element, as long as the integer or sigDigits element is not
346 * followed by the exponent element.
347 *
348 * <li>Two grouping intervals are recognized: That between the
349 *     decimal point and the first grouping symbol, and that
350 *     between the first and second grouping symbols. These
351 *     intervals are identical in most locales, but in some
352 *     locales they differ. For example, the pattern
353 *     &quot;#,##,###&quot; formats the number 123456789 as
354 *     &quot;12,34,56,789&quot;.</li>
355 *
356 * <li>The pad specifier <code>padSpec</code> may appear before the prefix,
357 * after the prefix, before the suffix, after the suffix, or not at all.
358 *
359 * <li>In place of '0', the digits '1' through '9' may be used to
360 * indicate a rounding increment.
361 * </ul>
362 *
363 * <p><strong>Parsing</strong>
364 *
365 * <p>DecimalFormat parses all Unicode characters that represent
366 * decimal digits, as defined by u_charDigitValue().  In addition,
367 * DecimalFormat also recognizes as digits the ten consecutive
368 * characters starting with the localized zero digit defined in the
369 * DecimalFormatSymbols object.  During formatting, the
370 * DecimalFormatSymbols-based digits are output.
371 *
372 * <p>During parsing, grouping separators are ignored if in lenient mode;
373 * otherwise, if present, they must be in appropriate positions.
374 *
375 * <p>For currency parsing, the formatter is able to parse every currency
376 * style formats no matter which style the formatter is constructed with.
377 * For example, a formatter instance gotten from
378 * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse
379 * formats such as "USD1.00" and "3.00 US dollars".
380 *
381 * <p>If parse(UnicodeString&,Formattable&,ParsePosition&)
382 * fails to parse a string, it leaves the parse position unchanged.
383 * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&)
384 * indicates parse failure by setting a failing
385 * UErrorCode.
386 *
387 * <p><strong>Formatting</strong>
388 *
389 * <p>Formatting is guided by several parameters, all of which can be
390 * specified either using a pattern or using the API.  The following
391 * description applies to formats that do not use <a href="#sci">scientific
392 * notation</a> or <a href="#sigdig">significant digits</a>.
393 *
394 * <ul><li>If the number of actual integer digits exceeds the
395 * <em>maximum integer digits</em>, then only the least significant
396 * digits are shown.  For example, 1997 is formatted as "97" if the
397 * maximum integer digits is set to 2.
398 *
399 * <li>If the number of actual integer digits is less than the
400 * <em>minimum integer digits</em>, then leading zeros are added.  For
401 * example, 1997 is formatted as "01997" if the minimum integer digits
402 * is set to 5.
403 *
404 * <li>If the number of actual fraction digits exceeds the <em>maximum
405 * fraction digits</em>, then rounding is performed to the
406 * maximum fraction digits.  For example, 0.125 is formatted as "0.12"
407 * if the maximum fraction digits is 2.  This behavior can be changed
408 * by specifying a rounding increment and/or a rounding mode.
409 *
410 * <li>If the number of actual fraction digits is less than the
411 * <em>minimum fraction digits</em>, then trailing zeros are added.
412 * For example, 0.125 is formatted as "0.1250" if the mimimum fraction
413 * digits is set to 4.
414 *
415 * <li>Trailing fractional zeros are not displayed if they occur
416 * <em>j</em> positions after the decimal, where <em>j</em> is less
417 * than the maximum fraction digits. For example, 0.10004 is
418 * formatted as "0.1" if the maximum fraction digits is four or less.
419 * </ul>
420 *
421 * <p><strong>Special Values</strong>
422 *
423 * <p><code>NaN</code> is represented as a single character, typically
424 * <code>\\uFFFD</code>.  This character is determined by the
425 * DecimalFormatSymbols object.  This is the only value for which
426 * the prefixes and suffixes are not used.
427 *
428 * <p>Infinity is represented as a single character, typically
429 * <code>\\u221E</code>, with the positive or negative prefixes and suffixes
430 * applied.  The infinity character is determined by the
431 * DecimalFormatSymbols object.
432 *
433 * <a name="sci"><strong>Scientific Notation</strong></a>
434 *
435 * <p>Numbers in scientific notation are expressed as the product of a mantissa
436 * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The
437 * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0),
438 * but it need not be.  DecimalFormat supports arbitrary mantissas.
439 * DecimalFormat can be instructed to use scientific
440 * notation through the API or through the pattern.  In a pattern, the exponent
441 * character immediately followed by one or more digit characters indicates
442 * scientific notation.  Example: "0.###E0" formats the number 1234 as
443 * "1.234E3".
444 *
445 * <ul>
446 * <li>The number of digit characters after the exponent character gives the
447 * minimum exponent digit count.  There is no maximum.  Negative exponents are
448 * formatted using the localized minus sign, <em>not</em> the prefix and suffix
449 * from the pattern.  This allows patterns such as "0.###E0 m/s".  To prefix
450 * positive exponents with a localized plus sign, specify '+' between the
451 * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0",
452 * "1E-1", etc.  (In localized patterns, use the localized plus sign rather than
453 * '+'.)
454 *
455 * <li>The minimum number of integer digits is achieved by adjusting the
456 * exponent.  Example: 0.00123 formatted with "00.###E0" yields "12.3E-4".  This
457 * only happens if there is no maximum number of integer digits.  If there is a
458 * maximum, then the minimum number of integer digits is fixed at one.
459 *
460 * <li>The maximum number of integer digits, if present, specifies the exponent
461 * grouping.  The most common use of this is to generate <em>engineering
462 * notation</em>, in which the exponent is a multiple of three, e.g.,
463 * "##0.###E0".  The number 12345 is formatted using "##0.####E0" as "12.345E3".
464 *
465 * <li>When using scientific notation, the formatter controls the
466 * digit counts using significant digits logic.  The maximum number of
467 * significant digits limits the total number of integer and fraction
468 * digits that will be shown in the mantissa; it does not affect
469 * parsing.  For example, 12345 formatted with "##0.##E0" is "12.3E3".
470 * See the section on significant digits for more details.
471 *
472 * <li>The number of significant digits shown is determined as
473 * follows: If areSignificantDigitsUsed() returns false, then the
474 * minimum number of significant digits shown is one, and the maximum
475 * number of significant digits shown is the sum of the <em>minimum
476 * integer</em> and <em>maximum fraction</em> digits, and is
477 * unaffected by the maximum integer digits.  If this sum is zero,
478 * then all significant digits are shown.  If
479 * areSignificantDigitsUsed() returns true, then the significant digit
480 * counts are specified by getMinimumSignificantDigits() and
481 * getMaximumSignificantDigits().  In this case, the number of
482 * integer digits is fixed at one, and there is no exponent grouping.
483 *
484 * <li>Exponential patterns may not contain grouping separators.
485 * </ul>
486 *
487 * <a name="sigdig"><strong>Significant Digits</strong></a>
488 *
489 * <code>DecimalFormat</code> has two ways of controlling how many
490 * digits are shows: (a) significant digits counts, or (b) integer and
491 * fraction digit counts.  Integer and fraction digit counts are
492 * described above.  When a formatter is using significant digits
493 * counts, the number of integer and fraction digits is not specified
494 * directly, and the formatter settings for these counts are ignored.
495 * Instead, the formatter uses however many integer and fraction
496 * digits are required to display the specified number of significant
497 * digits.  Examples:
498 *
499 * <table border=0 cellspacing=3 cellpadding=0>
500 *   <tr bgcolor="#ccccff">
501 *     <td align=left>Pattern
502 *     <td align=left>Minimum significant digits
503 *     <td align=left>Maximum significant digits
504 *     <td align=left>Number
505 *     <td align=left>Output of format()
506 *   <tr valign=top>
507 *     <td><code>\@\@\@</code>
508 *     <td>3
509 *     <td>3
510 *     <td>12345
511 *     <td><code>12300</code>
512 *   <tr valign=top bgcolor="#eeeeff">
513 *     <td><code>\@\@\@</code>
514 *     <td>3
515 *     <td>3
516 *     <td>0.12345
517 *     <td><code>0.123</code>
518 *   <tr valign=top>
519 *     <td><code>\@\@##</code>
520 *     <td>2
521 *     <td>4
522 *     <td>3.14159
523 *     <td><code>3.142</code>
524 *   <tr valign=top bgcolor="#eeeeff">
525 *     <td><code>\@\@##</code>
526 *     <td>2
527 *     <td>4
528 *     <td>1.23004
529 *     <td><code>1.23</code>
530 * </table>
531 *
532 * <ul>
533 * <li>Significant digit counts may be expressed using patterns that
534 * specify a minimum and maximum number of significant digits.  These
535 * are indicated by the <code>'@'</code> and <code>'#'</code>
536 * characters.  The minimum number of significant digits is the number
537 * of <code>'@'</code> characters.  The maximum number of significant
538 * digits is the number of <code>'@'</code> characters plus the number
539 * of <code>'#'</code> characters following on the right.  For
540 * example, the pattern <code>"@@@"</code> indicates exactly 3
541 * significant digits.  The pattern <code>"@##"</code> indicates from
542 * 1 to 3 significant digits.  Trailing zero digits to the right of
543 * the decimal separator are suppressed after the minimum number of
544 * significant digits have been shown.  For example, the pattern
545 * <code>"@##"</code> formats the number 0.1203 as
546 * <code>"0.12"</code>.
547 *
548 * <li>If a pattern uses significant digits, it may not contain a
549 * decimal separator, nor the <code>'0'</code> pattern character.
550 * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are
551 * disallowed.
552 *
553 * <li>Any number of <code>'#'</code> characters may be prepended to
554 * the left of the leftmost <code>'@'</code> character.  These have no
555 * effect on the minimum and maximum significant digits counts, but
556 * may be used to position grouping separators.  For example,
557 * <code>"#,#@#"</code> indicates a minimum of one significant digits,
558 * a maximum of two significant digits, and a grouping size of three.
559 *
560 * <li>In order to enable significant digits formatting, use a pattern
561 * containing the <code>'@'</code> pattern character.  Alternatively,
562 * call setSignificantDigitsUsed(TRUE).
563 *
564 * <li>In order to disable significant digits formatting, use a
565 * pattern that does not contain the <code>'@'</code> pattern
566 * character. Alternatively, call setSignificantDigitsUsed(FALSE).
567 *
568 * <li>The number of significant digits has no effect on parsing.
569 *
570 * <li>Significant digits may be used together with exponential notation. Such
571 * patterns are equivalent to a normal exponential pattern with a minimum and
572 * maximum integer digit count of one, a minimum fraction digit count of
573 * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit
574 * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the
575 * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>.
576 *
577 * <li>If signficant digits are in use, then the integer and fraction
578 * digit counts, as set via the API, are ignored.  If significant
579 * digits are not in use, then the signficant digit counts, as set via
580 * the API, are ignored.
581 *
582 * </ul>
583 *
584 * <p><strong>Padding</strong>
585 *
586 * <p>DecimalFormat supports padding the result of
587 * format() to a specific width.  Padding may be specified either
588 * through the API or through the pattern syntax.  In a pattern the pad escape
589 * character, followed by a single pad character, causes padding to be parsed
590 * and formatted.  The pad escape character is '*' in unlocalized patterns, and
591 * can be localized using DecimalFormatSymbols::setSymbol() with a
592 * DecimalFormatSymbols::kPadEscapeSymbol
593 * selector.  For example, <code>"$*x#,##0.00"</code> formats 123 to
594 * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>.
595 *
596 * <ul>
597 * <li>When padding is in effect, the width of the positive subpattern,
598 * including prefix and suffix, determines the format width.  For example, in
599 * the pattern <code>"* #0 o''clock"</code>, the format width is 10.
600 *
601 * <li>The width is counted in 16-bit code units (UChars).
602 *
603 * <li>Some parameters which usually do not matter have meaning when padding is
604 * used, because the pattern width is significant with padding.  In the pattern
605 * "* ##,##,#,##0.##", the format width is 14.  The initial characters "##,##,"
606 * do not affect the grouping size or maximum integer digits, but they do affect
607 * the format width.
608 *
609 * <li>Padding may be inserted at one of four locations: before the prefix,
610 * after the prefix, before the suffix, or after the suffix.  If padding is
611 * specified in any other location, applyPattern()
612 * sets a failing UErrorCode.  If there is no prefix,
613 * before the prefix and after the prefix are equivalent, likewise for the
614 * suffix.
615 *
616 * <li>When specified in a pattern, the 32-bit code point immediately
617 * following the pad escape is the pad character. This may be any character,
618 * including a special pattern character. That is, the pad escape
619 * <em>escapes</em> the following character. If there is no character after
620 * the pad escape, then the pattern is illegal.
621 *
622 * </ul>
623 *
624 * <p><strong>Rounding</strong>
625 *
626 * <p>DecimalFormat supports rounding to a specific increment.  For
627 * example, 1230 rounded to the nearest 50 is 1250.  1.234 rounded to the
628 * nearest 0.65 is 1.3.  The rounding increment may be specified through the API
629 * or in a pattern.  To specify a rounding increment in a pattern, include the
630 * increment in the pattern itself.  "#,#50" specifies a rounding increment of
631 * 50.  "#,##0.05" specifies a rounding increment of 0.05.
632 *
633 * <p>In the absense of an explicit rounding increment numbers are
634 * rounded to their formatted width.
635 *
636 * <ul>
637 * <li>Rounding only affects the string produced by formatting.  It does
638 * not affect parsing or change any numerical values.
639 *
640 * <li>A <em>rounding mode</em> determines how values are rounded; see
641 * DecimalFormat::ERoundingMode.  The default rounding mode is
642 * DecimalFormat::kRoundHalfEven.  The rounding mode can only be set
643 * through the API; it can not be set with a pattern.
644 *
645 * <li>Some locales use rounding in their currency formats to reflect the
646 * smallest currency denomination.
647 *
648 * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
649 * behave identically to digit '0'.
650 * </ul>
651 *
652 * <p><strong>Synchronization</strong>
653 *
654 * <p>DecimalFormat objects are not synchronized.  Multiple
655 * threads should not access one formatter concurrently.
656 *
657 * <p><strong>Subclassing</strong>
658 *
659 * <p><em>User subclasses are not supported.</em> While clients may write
660 * subclasses, such code will not necessarily work and will not be
661 * guaranteed to work stably from release to release.
662 */
663class U_I18N_API DecimalFormat: public NumberFormat {
664public:
665    /**
666     * Rounding mode.
667     * @stable ICU 2.4
668     */
669    enum ERoundingMode {
670        kRoundCeiling,  /**< Round towards positive infinity */
671        kRoundFloor,    /**< Round towards negative infinity */
672        kRoundDown,     /**< Round towards zero */
673        kRoundUp,       /**< Round away from zero */
674        kRoundHalfEven, /**< Round towards the nearest integer, or
675                             towards the nearest even integer if equidistant */
676        kRoundHalfDown, /**< Round towards the nearest integer, or
677                             towards zero if equidistant */
678        kRoundHalfUp,   /**< Round towards the nearest integer, or
679                             away from zero if equidistant */
680        /**
681          *  Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
682          *  @stable ICU 4.8
683          */
684        kRoundUnnecessary
685    };
686
687    /**
688     * Pad position.
689     * @stable ICU 2.4
690     */
691    enum EPadPosition {
692        kPadBeforePrefix,
693        kPadAfterPrefix,
694        kPadBeforeSuffix,
695        kPadAfterSuffix
696    };
697
698    /**
699     * Create a DecimalFormat using the default pattern and symbols
700     * for the default locale. This is a convenient way to obtain a
701     * DecimalFormat when internationalization is not the main concern.
702     * <P>
703     * To obtain standard formats for a given locale, use the factory methods
704     * on NumberFormat such as createInstance. These factories will
705     * return the most appropriate sub-class of NumberFormat for a given
706     * locale.
707     * @param status    Output param set to success/failure code. If the
708     *                  pattern is invalid this will be set to a failure code.
709     * @stable ICU 2.0
710     */
711    DecimalFormat(UErrorCode& status);
712
713    /**
714     * Create a DecimalFormat from the given pattern and the symbols
715     * for the default locale. This is a convenient way to obtain a
716     * DecimalFormat when internationalization is not the main concern.
717     * <P>
718     * To obtain standard formats for a given locale, use the factory methods
719     * on NumberFormat such as createInstance. These factories will
720     * return the most appropriate sub-class of NumberFormat for a given
721     * locale.
722     * @param pattern   A non-localized pattern string.
723     * @param status    Output param set to success/failure code. If the
724     *                  pattern is invalid this will be set to a failure code.
725     * @stable ICU 2.0
726     */
727    DecimalFormat(const UnicodeString& pattern,
728                  UErrorCode& status);
729
730    /**
731     * Create a DecimalFormat from the given pattern and symbols.
732     * Use this constructor when you need to completely customize the
733     * behavior of the format.
734     * <P>
735     * To obtain standard formats for a given
736     * locale, use the factory methods on NumberFormat such as
737     * createInstance or createCurrencyInstance. If you need only minor adjustments
738     * to a standard format, you can modify the format returned by
739     * a NumberFormat factory method.
740     *
741     * @param pattern           a non-localized pattern string
742     * @param symbolsToAdopt    the set of symbols to be used.  The caller should not
743     *                          delete this object after making this call.
744     * @param status            Output param set to success/failure code. If the
745     *                          pattern is invalid this will be set to a failure code.
746     * @stable ICU 2.0
747     */
748    DecimalFormat(  const UnicodeString& pattern,
749                    DecimalFormatSymbols* symbolsToAdopt,
750                    UErrorCode& status);
751
752#ifndef U_HIDE_INTERNAL_API
753    /**
754     * This API is for ICU use only.
755     * Create a DecimalFormat from the given pattern, symbols, and style.
756     *
757     * @param pattern           a non-localized pattern string
758     * @param symbolsToAdopt    the set of symbols to be used.  The caller should not
759     *                          delete this object after making this call.
760     * @param style             style of decimal format
761     * @param status            Output param set to success/failure code. If the
762     *                          pattern is invalid this will be set to a failure code.
763     * @internal
764     */
765    DecimalFormat(  const UnicodeString& pattern,
766                    DecimalFormatSymbols* symbolsToAdopt,
767                    UNumberFormatStyle style,
768                    UErrorCode& status);
769
770#if UCONFIG_HAVE_PARSEALLINPUT
771    /**
772     * @internal
773     */
774    void setParseAllInput(UNumberFormatAttributeValue value);
775#endif
776
777#endif  /* U_HIDE_INTERNAL_API */
778
779
780    /**
781     * Set an integer attribute on this DecimalFormat.
782     * May return U_UNSUPPORTED_ERROR if this instance does not support
783     * the specified attribute.
784     * @param attr the attribute to set
785     * @param newvalue new value
786     * @param status the error type
787     * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
788     * @draft ICU 51
789     */
790    virtual DecimalFormat& setAttribute( UNumberFormatAttribute attr,
791                                       int32_t newvalue,
792                                       UErrorCode &status);
793
794    /**
795     * Get an integer
796     * May return U_UNSUPPORTED_ERROR if this instance does not support
797     * the specified attribute.
798     * @param attr the attribute to set
799     * @param status the error type
800     * @return the attribute value. Undefined if there is an error.
801     * @draft ICU 51
802     */
803    virtual int32_t getAttribute( UNumberFormatAttribute attr,
804                                  UErrorCode &status) const;
805
806
807
808    /**
809     * Create a DecimalFormat from the given pattern and symbols.
810     * Use this constructor when you need to completely customize the
811     * behavior of the format.
812     * <P>
813     * To obtain standard formats for a given
814     * locale, use the factory methods on NumberFormat such as
815     * createInstance or createCurrencyInstance. If you need only minor adjustments
816     * to a standard format, you can modify the format returned by
817     * a NumberFormat factory method.
818     *
819     * @param pattern           a non-localized pattern string
820     * @param symbolsToAdopt    the set of symbols to be used.  The caller should not
821     *                          delete this object after making this call.
822     * @param parseError        Output param to receive errors occured during parsing
823     * @param status            Output param set to success/failure code. If the
824     *                          pattern is invalid this will be set to a failure code.
825     * @stable ICU 2.0
826     */
827    DecimalFormat(  const UnicodeString& pattern,
828                    DecimalFormatSymbols* symbolsToAdopt,
829                    UParseError& parseError,
830                    UErrorCode& status);
831    /**
832     * Create a DecimalFormat from the given pattern and symbols.
833     * Use this constructor when you need to completely customize the
834     * behavior of the format.
835     * <P>
836     * To obtain standard formats for a given
837     * locale, use the factory methods on NumberFormat such as
838     * createInstance or createCurrencyInstance. If you need only minor adjustments
839     * to a standard format, you can modify the format returned by
840     * a NumberFormat factory method.
841     *
842     * @param pattern           a non-localized pattern string
843     * @param symbols   the set of symbols to be used
844     * @param status            Output param set to success/failure code. If the
845     *                          pattern is invalid this will be set to a failure code.
846     * @stable ICU 2.0
847     */
848    DecimalFormat(  const UnicodeString& pattern,
849                    const DecimalFormatSymbols& symbols,
850                    UErrorCode& status);
851
852    /**
853     * Copy constructor.
854     *
855     * @param source    the DecimalFormat object to be copied from.
856     * @stable ICU 2.0
857     */
858    DecimalFormat(const DecimalFormat& source);
859
860    /**
861     * Assignment operator.
862     *
863     * @param rhs    the DecimalFormat object to be copied.
864     * @stable ICU 2.0
865     */
866    DecimalFormat& operator=(const DecimalFormat& rhs);
867
868    /**
869     * Destructor.
870     * @stable ICU 2.0
871     */
872    virtual ~DecimalFormat();
873
874    /**
875     * Clone this Format object polymorphically. The caller owns the
876     * result and should delete it when done.
877     *
878     * @return    a polymorphic copy of this DecimalFormat.
879     * @stable ICU 2.0
880     */
881    virtual Format* clone(void) const;
882
883    /**
884     * Return true if the given Format objects are semantically equal.
885     * Objects of different subclasses are considered unequal.
886     *
887     * @param other    the object to be compared with.
888     * @return         true if the given Format objects are semantically equal.
889     * @stable ICU 2.0
890     */
891    virtual UBool operator==(const Format& other) const;
892
893
894    using NumberFormat::format;
895
896    /**
897     * Format a double or long number using base-10 representation.
898     *
899     * @param number    The value to be formatted.
900     * @param appendTo  Output parameter to receive result.
901     *                  Result is appended to existing contents.
902     * @param pos       On input: an alignment field, if desired.
903     *                  On output: the offsets of the alignment field.
904     * @return          Reference to 'appendTo' parameter.
905     * @stable ICU 2.0
906     */
907    virtual UnicodeString& format(double number,
908                                  UnicodeString& appendTo,
909                                  FieldPosition& pos) const;
910
911
912    /**
913     * Format a double or long number using base-10 representation.
914     *
915     * @param number    The value to be formatted.
916     * @param appendTo  Output parameter to receive result.
917     *                  Result is appended to existing contents.
918     * @param pos       On input: an alignment field, if desired.
919     *                  On output: the offsets of the alignment field.
920     * @param status
921     * @return          Reference to 'appendTo' parameter.
922     * @internal
923     */
924    virtual UnicodeString& format(double number,
925                                  UnicodeString& appendTo,
926                                  FieldPosition& pos,
927                                  UErrorCode &status) const;
928
929    /**
930     * Format a double or long number using base-10 representation.
931     *
932     * @param number    The value to be formatted.
933     * @param appendTo  Output parameter to receive result.
934     *                  Result is appended to existing contents.
935     * @param posIter   On return, can be used to iterate over positions
936     *                  of fields generated by this format call.
937     *                  Can be NULL.
938     * @param status    Output param filled with success/failure status.
939     * @return          Reference to 'appendTo' parameter.
940     * @stable 4.4
941     */
942    virtual UnicodeString& format(double number,
943                                  UnicodeString& appendTo,
944                                  FieldPositionIterator* posIter,
945                                  UErrorCode& status) const;
946
947    /**
948     * Format a long number using base-10 representation.
949     *
950     * @param number    The value to be formatted.
951     * @param appendTo  Output parameter to receive result.
952     *                  Result is appended to existing contents.
953     * @param pos       On input: an alignment field, if desired.
954     *                  On output: the offsets of the alignment field.
955     * @return          Reference to 'appendTo' parameter.
956     * @stable ICU 2.0
957     */
958    virtual UnicodeString& format(int32_t number,
959                                  UnicodeString& appendTo,
960                                  FieldPosition& pos) const;
961
962    /**
963     * Format a long number using base-10 representation.
964     *
965     * @param number    The value to be formatted.
966     * @param appendTo  Output parameter to receive result.
967     *                  Result is appended to existing contents.
968     * @param pos       On input: an alignment field, if desired.
969     *                  On output: the offsets of the alignment field.
970     * @return          Reference to 'appendTo' parameter.
971     * @internal
972     */
973    virtual UnicodeString& format(int32_t number,
974                                  UnicodeString& appendTo,
975                                  FieldPosition& pos,
976                                  UErrorCode &status) const;
977
978    /**
979     * Format a long number using base-10 representation.
980     *
981     * @param number    The value to be formatted.
982     * @param appendTo  Output parameter to receive result.
983     *                  Result is appended to existing contents.
984     * @param posIter   On return, can be used to iterate over positions
985     *                  of fields generated by this format call.
986     *                  Can be NULL.
987     * @param status    Output param filled with success/failure status.
988     * @return          Reference to 'appendTo' parameter.
989     * @stable 4.4
990     */
991    virtual UnicodeString& format(int32_t number,
992                                  UnicodeString& appendTo,
993                                  FieldPositionIterator* posIter,
994                                  UErrorCode& status) const;
995
996    /**
997     * Format an int64 number using base-10 representation.
998     *
999     * @param number    The value to be formatted.
1000     * @param appendTo  Output parameter to receive result.
1001     *                  Result is appended to existing contents.
1002     * @param pos       On input: an alignment field, if desired.
1003     *                  On output: the offsets of the alignment field.
1004     * @return          Reference to 'appendTo' parameter.
1005     * @stable ICU 2.8
1006     */
1007    virtual UnicodeString& format(int64_t number,
1008                                  UnicodeString& appendTo,
1009                                  FieldPosition& pos) const;
1010
1011    /**
1012     * Format an int64 number using base-10 representation.
1013     *
1014     * @param number    The value to be formatted.
1015     * @param appendTo  Output parameter to receive result.
1016     *                  Result is appended to existing contents.
1017     * @param pos       On input: an alignment field, if desired.
1018     *                  On output: the offsets of the alignment field.
1019     * @return          Reference to 'appendTo' parameter.
1020     * @internal
1021     */
1022    virtual UnicodeString& format(int64_t number,
1023                                  UnicodeString& appendTo,
1024                                  FieldPosition& pos,
1025                                  UErrorCode &status) const;
1026
1027    /**
1028     * Format an int64 number using base-10 representation.
1029     *
1030     * @param number    The value to be formatted.
1031     * @param appendTo  Output parameter to receive result.
1032     *                  Result is appended to existing contents.
1033     * @param posIter   On return, can be used to iterate over positions
1034     *                  of fields generated by this format call.
1035     *                  Can be NULL.
1036     * @param status    Output param filled with success/failure status.
1037     * @return          Reference to 'appendTo' parameter.
1038     * @stable 4.4
1039     */
1040    virtual UnicodeString& format(int64_t number,
1041                                  UnicodeString& appendTo,
1042                                  FieldPositionIterator* posIter,
1043                                  UErrorCode& status) const;
1044
1045    /**
1046     * Format a decimal number.
1047     * The syntax of the unformatted number is a "numeric string"
1048     * as defined in the Decimal Arithmetic Specification, available at
1049     * http://speleotrove.com/decimal
1050     *
1051     * @param number    The unformatted number, as a string.
1052     * @param appendTo  Output parameter to receive result.
1053     *                  Result is appended to existing contents.
1054     * @param posIter   On return, can be used to iterate over positions
1055     *                  of fields generated by this format call.
1056     *                  Can be NULL.
1057     * @param status    Output param filled with success/failure status.
1058     * @return          Reference to 'appendTo' parameter.
1059     * @stable 4.4
1060     */
1061    virtual UnicodeString& format(const StringPiece &number,
1062                                  UnicodeString& appendTo,
1063                                  FieldPositionIterator* posIter,
1064                                  UErrorCode& status) const;
1065
1066
1067    /**
1068     * Format a decimal number.
1069     * The number is a DigitList wrapper onto a floating point decimal number.
1070     * The default implementation in NumberFormat converts the decimal number
1071     * to a double and formats that.
1072     *
1073     * @param number    The number, a DigitList format Decimal Floating Point.
1074     * @param appendTo  Output parameter to receive result.
1075     *                  Result is appended to existing contents.
1076     * @param posIter   On return, can be used to iterate over positions
1077     *                  of fields generated by this format call.
1078     * @param status    Output param filled with success/failure status.
1079     * @return          Reference to 'appendTo' parameter.
1080     * @internal
1081     */
1082    virtual UnicodeString& format(const DigitList &number,
1083                                  UnicodeString& appendTo,
1084                                  FieldPositionIterator* posIter,
1085                                  UErrorCode& status) const;
1086
1087    /**
1088     * Format a decimal number.
1089     * The number is a DigitList wrapper onto a floating point decimal number.
1090     * The default implementation in NumberFormat converts the decimal number
1091     * to a double and formats that.
1092     *
1093     * @param number    The number, a DigitList format Decimal Floating Point.
1094     * @param appendTo  Output parameter to receive result.
1095     *                  Result is appended to existing contents.
1096     * @param pos       On input: an alignment field, if desired.
1097     *                  On output: the offsets of the alignment field.
1098     * @param status    Output param filled with success/failure status.
1099     * @return          Reference to 'appendTo' parameter.
1100     * @internal
1101     */
1102    virtual UnicodeString& format(const DigitList &number,
1103                                  UnicodeString& appendTo,
1104                                  FieldPosition& pos,
1105                                  UErrorCode& status) const;
1106
1107
1108    /**
1109     * Format a Formattable using base-10 representation.
1110     *
1111     * @param obj       The value to be formatted.
1112     * @param appendTo  Output parameter to receive result.
1113     *                  Result is appended to existing contents.
1114     * @param pos       On input: an alignment field, if desired.
1115     *                  On output: the offsets of the alignment field.
1116     * @param status    Error code indicating success or failure.
1117     * @return          Reference to 'appendTo' parameter.
1118     * @stable ICU 2.0
1119     */
1120    virtual UnicodeString& format(const Formattable& obj,
1121                                  UnicodeString& appendTo,
1122                                  FieldPosition& pos,
1123                                  UErrorCode& status) const;
1124
1125    /**
1126     * Redeclared NumberFormat method.
1127     * Formats an object to produce a string.
1128     *
1129     * @param obj       The object to format.
1130     * @param appendTo  Output parameter to receive result.
1131     *                  Result is appended to existing contents.
1132     * @param status    Output parameter filled in with success or failure status.
1133     * @return          Reference to 'appendTo' parameter.
1134     * @stable ICU 2.0
1135     */
1136    UnicodeString& format(const Formattable& obj,
1137                          UnicodeString& appendTo,
1138                          UErrorCode& status) const;
1139
1140    /**
1141     * Redeclared NumberFormat method.
1142     * Format a double number.
1143     *
1144     * @param number    The value to be formatted.
1145     * @param appendTo  Output parameter to receive result.
1146     *                  Result is appended to existing contents.
1147     * @return          Reference to 'appendTo' parameter.
1148     * @stable ICU 2.0
1149     */
1150    UnicodeString& format(double number,
1151                          UnicodeString& appendTo) const;
1152
1153    /**
1154     * Redeclared NumberFormat method.
1155     * Format a long number. These methods call the NumberFormat
1156     * pure virtual format() methods with the default FieldPosition.
1157     *
1158     * @param number    The value to be formatted.
1159     * @param appendTo  Output parameter to receive result.
1160     *                  Result is appended to existing contents.
1161     * @return          Reference to 'appendTo' parameter.
1162     * @stable ICU 2.0
1163     */
1164    UnicodeString& format(int32_t number,
1165                          UnicodeString& appendTo) const;
1166
1167    /**
1168     * Redeclared NumberFormat method.
1169     * Format an int64 number. These methods call the NumberFormat
1170     * pure virtual format() methods with the default FieldPosition.
1171     *
1172     * @param number    The value to be formatted.
1173     * @param appendTo  Output parameter to receive result.
1174     *                  Result is appended to existing contents.
1175     * @return          Reference to 'appendTo' parameter.
1176     * @stable ICU 2.8
1177     */
1178    UnicodeString& format(int64_t number,
1179                          UnicodeString& appendTo) const;
1180   /**
1181    * Parse the given string using this object's choices. The method
1182    * does string comparisons to try to find an optimal match.
1183    * If no object can be parsed, index is unchanged, and NULL is
1184    * returned.  The result is returned as the most parsimonious
1185    * type of Formattable that will accomodate all of the
1186    * necessary precision.  For example, if the result is exactly 12,
1187    * it will be returned as a long.  However, if it is 1.5, it will
1188    * be returned as a double.
1189    *
1190    * @param text           The text to be parsed.
1191    * @param result         Formattable to be set to the parse result.
1192    *                       If parse fails, return contents are undefined.
1193    * @param parsePosition  The position to start parsing at on input.
1194    *                       On output, moved to after the last successfully
1195    *                       parse character. On parse failure, does not change.
1196    * @see Formattable
1197    * @stable ICU 2.0
1198    */
1199    virtual void parse(const UnicodeString& text,
1200                       Formattable& result,
1201                       ParsePosition& parsePosition) const;
1202
1203    // Declare here again to get rid of function hiding problems.
1204    /**
1205     * Parse the given string using this object's choices.
1206     *
1207     * @param text           The text to be parsed.
1208     * @param result         Formattable to be set to the parse result.
1209     * @param status    Output parameter filled in with success or failure status.
1210     * @stable ICU 2.0
1211     */
1212    virtual void parse(const UnicodeString& text,
1213                       Formattable& result,
1214                       UErrorCode& status) const;
1215
1216    /**
1217     * Parses text from the given string as a currency amount.  Unlike
1218     * the parse() method, this method will attempt to parse a generic
1219     * currency name, searching for a match of this object's locale's
1220     * currency display names, or for a 3-letter ISO currency code.
1221     * This method will fail if this format is not a currency format,
1222     * that is, if it does not contain the currency pattern symbol
1223     * (U+00A4) in its prefix or suffix.
1224     *
1225     * @param text the string to parse
1226     * @param pos  input-output position; on input, the position within text
1227     *             to match; must have 0 <= pos.getIndex() < text.length();
1228     *             on output, the position after the last matched character.
1229     *             If the parse fails, the position in unchanged upon output.
1230     * @return     if parse succeeds, a pointer to a newly-created CurrencyAmount
1231     *             object (owned by the caller) containing information about
1232     *             the parsed currency; if parse fails, this is NULL.
1233     * @stable ICU 49
1234     */
1235    virtual CurrencyAmount* parseCurrency(const UnicodeString& text,
1236                                          ParsePosition& pos) const;
1237
1238    /**
1239     * Returns the decimal format symbols, which is generally not changed
1240     * by the programmer or user.
1241     * @return desired DecimalFormatSymbols
1242     * @see DecimalFormatSymbols
1243     * @stable ICU 2.0
1244     */
1245    virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
1246
1247    /**
1248     * Sets the decimal format symbols, which is generally not changed
1249     * by the programmer or user.
1250     * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
1251     * @stable ICU 2.0
1252     */
1253    virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
1254
1255    /**
1256     * Sets the decimal format symbols, which is generally not changed
1257     * by the programmer or user.
1258     * @param symbols DecimalFormatSymbols.
1259     * @stable ICU 2.0
1260     */
1261    virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1262
1263
1264    /**
1265     * Returns the currency plural format information,
1266     * which is generally not changed by the programmer or user.
1267     * @return desired CurrencyPluralInfo
1268     * @stable ICU 4.2
1269     */
1270    virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
1271
1272    /**
1273     * Sets the currency plural format information,
1274     * which is generally not changed by the programmer or user.
1275     * @param toAdopt CurrencyPluralInfo to be adopted.
1276     * @stable ICU 4.2
1277     */
1278    virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt);
1279
1280    /**
1281     * Sets the currency plural format information,
1282     * which is generally not changed by the programmer or user.
1283     * @param info Currency Plural Info.
1284     * @stable ICU 4.2
1285     */
1286    virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info);
1287
1288
1289    /**
1290     * Get the positive prefix.
1291     *
1292     * @param result    Output param which will receive the positive prefix.
1293     * @return          A reference to 'result'.
1294     * Examples: +123, $123, sFr123
1295     * @stable ICU 2.0
1296     */
1297    UnicodeString& getPositivePrefix(UnicodeString& result) const;
1298
1299    /**
1300     * Set the positive prefix.
1301     *
1302     * @param newValue    the new value of the the positive prefix to be set.
1303     * Examples: +123, $123, sFr123
1304     * @stable ICU 2.0
1305     */
1306    virtual void setPositivePrefix(const UnicodeString& newValue);
1307
1308    /**
1309     * Get the negative prefix.
1310     *
1311     * @param result    Output param which will receive the negative prefix.
1312     * @return          A reference to 'result'.
1313     * Examples: -123, ($123) (with negative suffix), sFr-123
1314     * @stable ICU 2.0
1315     */
1316    UnicodeString& getNegativePrefix(UnicodeString& result) const;
1317
1318    /**
1319     * Set the negative prefix.
1320     *
1321     * @param newValue    the new value of the the negative prefix to be set.
1322     * Examples: -123, ($123) (with negative suffix), sFr-123
1323     * @stable ICU 2.0
1324     */
1325    virtual void setNegativePrefix(const UnicodeString& newValue);
1326
1327    /**
1328     * Get the positive suffix.
1329     *
1330     * @param result    Output param which will receive the positive suffix.
1331     * @return          A reference to 'result'.
1332     * Example: 123%
1333     * @stable ICU 2.0
1334     */
1335    UnicodeString& getPositiveSuffix(UnicodeString& result) const;
1336
1337    /**
1338     * Set the positive suffix.
1339     *
1340     * @param newValue    the new value of the positive suffix to be set.
1341     * Example: 123%
1342     * @stable ICU 2.0
1343     */
1344    virtual void setPositiveSuffix(const UnicodeString& newValue);
1345
1346    /**
1347     * Get the negative suffix.
1348     *
1349     * @param result    Output param which will receive the negative suffix.
1350     * @return          A reference to 'result'.
1351     * Examples: -123%, ($123) (with positive suffixes)
1352     * @stable ICU 2.0
1353     */
1354    UnicodeString& getNegativeSuffix(UnicodeString& result) const;
1355
1356    /**
1357     * Set the negative suffix.
1358     *
1359     * @param newValue    the new value of the negative suffix to be set.
1360     * Examples: 123%
1361     * @stable ICU 2.0
1362     */
1363    virtual void setNegativeSuffix(const UnicodeString& newValue);
1364
1365    /**
1366     * Get the multiplier for use in percent, permill, etc.
1367     * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1368     * (For Arabic, use arabic percent symbol).
1369     * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1370     *
1371     * @return    the multiplier for use in percent, permill, etc.
1372     * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1373     * @stable ICU 2.0
1374     */
1375    int32_t getMultiplier(void) const;
1376
1377    /**
1378     * Set the multiplier for use in percent, permill, etc.
1379     * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1380     * (For Arabic, use arabic percent symbol).
1381     * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1382     *
1383     * @param newValue    the new value of the multiplier for use in percent, permill, etc.
1384     * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1385     * @stable ICU 2.0
1386     */
1387    virtual void setMultiplier(int32_t newValue);
1388
1389    /**
1390     * Get the rounding increment.
1391     * @return A positive rounding increment, or 0.0 if a rounding
1392     * increment is not in effect.
1393     * @see #setRoundingIncrement
1394     * @see #getRoundingMode
1395     * @see #setRoundingMode
1396     * @stable ICU 2.0
1397     */
1398    virtual double getRoundingIncrement(void) const;
1399
1400    /**
1401     * Set the rounding increment.  In the absence of a rounding increment,
1402     *    numbers will be rounded to the number of digits displayed.
1403     * @param newValue A positive rounding increment.
1404     * Negative increments are equivalent to 0.0.
1405     * @see #getRoundingIncrement
1406     * @see #getRoundingMode
1407     * @see #setRoundingMode
1408     * @stable ICU 2.0
1409     */
1410    virtual void setRoundingIncrement(double newValue);
1411
1412    /**
1413     * Get the rounding mode.
1414     * @return A rounding mode
1415     * @see #setRoundingIncrement
1416     * @see #getRoundingIncrement
1417     * @see #setRoundingMode
1418     * @stable ICU 2.0
1419     */
1420    virtual ERoundingMode getRoundingMode(void) const;
1421
1422    /**
1423     * Set the rounding mode.
1424     * @param roundingMode A rounding mode
1425     * @see #setRoundingIncrement
1426     * @see #getRoundingIncrement
1427     * @see #getRoundingMode
1428     * @stable ICU 2.0
1429     */
1430    virtual void setRoundingMode(ERoundingMode roundingMode);
1431
1432    /**
1433     * Get the width to which the output of format() is padded.
1434     * The width is counted in 16-bit code units.
1435     * @return the format width, or zero if no padding is in effect
1436     * @see #setFormatWidth
1437     * @see #getPadCharacterString
1438     * @see #setPadCharacter
1439     * @see #getPadPosition
1440     * @see #setPadPosition
1441     * @stable ICU 2.0
1442     */
1443    virtual int32_t getFormatWidth(void) const;
1444
1445    /**
1446     * Set the width to which the output of format() is padded.
1447     * The width is counted in 16-bit code units.
1448     * This method also controls whether padding is enabled.
1449     * @param width the width to which to pad the result of
1450     * format(), or zero to disable padding.  A negative
1451     * width is equivalent to 0.
1452     * @see #getFormatWidth
1453     * @see #getPadCharacterString
1454     * @see #setPadCharacter
1455     * @see #getPadPosition
1456     * @see #setPadPosition
1457     * @stable ICU 2.0
1458     */
1459    virtual void setFormatWidth(int32_t width);
1460
1461    /**
1462     * Get the pad character used to pad to the format width.  The
1463     * default is ' '.
1464     * @return a string containing the pad character. This will always
1465     * have a length of one 32-bit code point.
1466     * @see #setFormatWidth
1467     * @see #getFormatWidth
1468     * @see #setPadCharacter
1469     * @see #getPadPosition
1470     * @see #setPadPosition
1471     * @stable ICU 2.0
1472     */
1473    virtual UnicodeString getPadCharacterString() const;
1474
1475    /**
1476     * Set the character used to pad to the format width.  If padding
1477     * is not enabled, then this will take effect if padding is later
1478     * enabled.
1479     * @param padChar a string containing the pad charcter. If the string
1480     * has length 0, then the pad characer is set to ' '.  Otherwise
1481     * padChar.char32At(0) will be used as the pad character.
1482     * @see #setFormatWidth
1483     * @see #getFormatWidth
1484     * @see #getPadCharacterString
1485     * @see #getPadPosition
1486     * @see #setPadPosition
1487     * @stable ICU 2.0
1488     */
1489    virtual void setPadCharacter(const UnicodeString &padChar);
1490
1491    /**
1492     * Get the position at which padding will take place.  This is the location
1493     * at which padding will be inserted if the result of format()
1494     * is shorter than the format width.
1495     * @return the pad position, one of kPadBeforePrefix,
1496     * kPadAfterPrefix, kPadBeforeSuffix, or
1497     * kPadAfterSuffix.
1498     * @see #setFormatWidth
1499     * @see #getFormatWidth
1500     * @see #setPadCharacter
1501     * @see #getPadCharacterString
1502     * @see #setPadPosition
1503     * @see #EPadPosition
1504     * @stable ICU 2.0
1505     */
1506    virtual EPadPosition getPadPosition(void) const;
1507
1508    /**
1509     * Set the position at which padding will take place.  This is the location
1510     * at which padding will be inserted if the result of format()
1511     * is shorter than the format width.  This has no effect unless padding is
1512     * enabled.
1513     * @param padPos the pad position, one of kPadBeforePrefix,
1514     * kPadAfterPrefix, kPadBeforeSuffix, or
1515     * kPadAfterSuffix.
1516     * @see #setFormatWidth
1517     * @see #getFormatWidth
1518     * @see #setPadCharacter
1519     * @see #getPadCharacterString
1520     * @see #getPadPosition
1521     * @see #EPadPosition
1522     * @stable ICU 2.0
1523     */
1524    virtual void setPadPosition(EPadPosition padPos);
1525
1526    /**
1527     * Return whether or not scientific notation is used.
1528     * @return TRUE if this object formats and parses scientific notation
1529     * @see #setScientificNotation
1530     * @see #getMinimumExponentDigits
1531     * @see #setMinimumExponentDigits
1532     * @see #isExponentSignAlwaysShown
1533     * @see #setExponentSignAlwaysShown
1534     * @stable ICU 2.0
1535     */
1536    virtual UBool isScientificNotation(void);
1537
1538    /**
1539     * Set whether or not scientific notation is used. When scientific notation
1540     * is used, the effective maximum number of integer digits is <= 8.  If the
1541     * maximum number of integer digits is set to more than 8, the effective
1542     * maximum will be 1.  This allows this call to generate a 'default' scientific
1543     * number format without additional changes.
1544     * @param useScientific TRUE if this object formats and parses scientific
1545     * notation
1546     * @see #isScientificNotation
1547     * @see #getMinimumExponentDigits
1548     * @see #setMinimumExponentDigits
1549     * @see #isExponentSignAlwaysShown
1550     * @see #setExponentSignAlwaysShown
1551     * @stable ICU 2.0
1552     */
1553    virtual void setScientificNotation(UBool useScientific);
1554
1555    /**
1556     * Return the minimum exponent digits that will be shown.
1557     * @return the minimum exponent digits that will be shown
1558     * @see #setScientificNotation
1559     * @see #isScientificNotation
1560     * @see #setMinimumExponentDigits
1561     * @see #isExponentSignAlwaysShown
1562     * @see #setExponentSignAlwaysShown
1563     * @stable ICU 2.0
1564     */
1565    virtual int8_t getMinimumExponentDigits(void) const;
1566
1567    /**
1568     * Set the minimum exponent digits that will be shown.  This has no
1569     * effect unless scientific notation is in use.
1570     * @param minExpDig a value >= 1 indicating the fewest exponent digits
1571     * that will be shown.  Values less than 1 will be treated as 1.
1572     * @see #setScientificNotation
1573     * @see #isScientificNotation
1574     * @see #getMinimumExponentDigits
1575     * @see #isExponentSignAlwaysShown
1576     * @see #setExponentSignAlwaysShown
1577     * @stable ICU 2.0
1578     */
1579    virtual void setMinimumExponentDigits(int8_t minExpDig);
1580
1581    /**
1582     * Return whether the exponent sign is always shown.
1583     * @return TRUE if the exponent is always prefixed with either the
1584     * localized minus sign or the localized plus sign, false if only negative
1585     * exponents are prefixed with the localized minus sign.
1586     * @see #setScientificNotation
1587     * @see #isScientificNotation
1588     * @see #setMinimumExponentDigits
1589     * @see #getMinimumExponentDigits
1590     * @see #setExponentSignAlwaysShown
1591     * @stable ICU 2.0
1592     */
1593    virtual UBool isExponentSignAlwaysShown(void);
1594
1595    /**
1596     * Set whether the exponent sign is always shown.  This has no effect
1597     * unless scientific notation is in use.
1598     * @param expSignAlways TRUE if the exponent is always prefixed with either
1599     * the localized minus sign or the localized plus sign, false if only
1600     * negative exponents are prefixed with the localized minus sign.
1601     * @see #setScientificNotation
1602     * @see #isScientificNotation
1603     * @see #setMinimumExponentDigits
1604     * @see #getMinimumExponentDigits
1605     * @see #isExponentSignAlwaysShown
1606     * @stable ICU 2.0
1607     */
1608    virtual void setExponentSignAlwaysShown(UBool expSignAlways);
1609
1610    /**
1611     * Return the grouping size. Grouping size is the number of digits between
1612     * grouping separators in the integer portion of a number.  For example,
1613     * in the number "123,456.78", the grouping size is 3.
1614     *
1615     * @return    the grouping size.
1616     * @see setGroupingSize
1617     * @see NumberFormat::isGroupingUsed
1618     * @see DecimalFormatSymbols::getGroupingSeparator
1619     * @stable ICU 2.0
1620     */
1621    int32_t getGroupingSize(void) const;
1622
1623    /**
1624     * Set the grouping size. Grouping size is the number of digits between
1625     * grouping separators in the integer portion of a number.  For example,
1626     * in the number "123,456.78", the grouping size is 3.
1627     *
1628     * @param newValue    the new value of the grouping size.
1629     * @see getGroupingSize
1630     * @see NumberFormat::setGroupingUsed
1631     * @see DecimalFormatSymbols::setGroupingSeparator
1632     * @stable ICU 2.0
1633     */
1634    virtual void setGroupingSize(int32_t newValue);
1635
1636    /**
1637     * Return the secondary grouping size. In some locales one
1638     * grouping interval is used for the least significant integer
1639     * digits (the primary grouping size), and another is used for all
1640     * others (the secondary grouping size).  A formatter supporting a
1641     * secondary grouping size will return a positive integer unequal
1642     * to the primary grouping size returned by
1643     * getGroupingSize().  For example, if the primary
1644     * grouping size is 4, and the secondary grouping size is 2, then
1645     * the number 123456789 formats as "1,23,45,6789", and the pattern
1646     * appears as "#,##,###0".
1647     * @return the secondary grouping size, or a value less than
1648     * one if there is none
1649     * @see setSecondaryGroupingSize
1650     * @see NumberFormat::isGroupingUsed
1651     * @see DecimalFormatSymbols::getGroupingSeparator
1652     * @stable ICU 2.4
1653     */
1654    int32_t getSecondaryGroupingSize(void) const;
1655
1656    /**
1657     * Set the secondary grouping size. If set to a value less than 1,
1658     * then secondary grouping is turned off, and the primary grouping
1659     * size is used for all intervals, not just the least significant.
1660     *
1661     * @param newValue    the new value of the secondary grouping size.
1662     * @see getSecondaryGroupingSize
1663     * @see NumberFormat#setGroupingUsed
1664     * @see DecimalFormatSymbols::setGroupingSeparator
1665     * @stable ICU 2.4
1666     */
1667    virtual void setSecondaryGroupingSize(int32_t newValue);
1668
1669    /**
1670     * Allows you to get the behavior of the decimal separator with integers.
1671     * (The decimal separator will always appear with decimals.)
1672     *
1673     * @return    TRUE if the decimal separator always appear with decimals.
1674     * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1675     * @stable ICU 2.0
1676     */
1677    UBool isDecimalSeparatorAlwaysShown(void) const;
1678
1679    /**
1680     * Allows you to set the behavior of the decimal separator with integers.
1681     * (The decimal separator will always appear with decimals.)
1682     *
1683     * @param newValue    set TRUE if the decimal separator will always appear with decimals.
1684     * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1685     * @stable ICU 2.0
1686     */
1687    virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
1688
1689    /**
1690     * Synthesizes a pattern string that represents the current state
1691     * of this Format object.
1692     *
1693     * @param result    Output param which will receive the pattern.
1694     *                  Previous contents are deleted.
1695     * @return          A reference to 'result'.
1696     * @see applyPattern
1697     * @stable ICU 2.0
1698     */
1699    virtual UnicodeString& toPattern(UnicodeString& result) const;
1700
1701    /**
1702     * Synthesizes a localized pattern string that represents the current
1703     * state of this Format object.
1704     *
1705     * @param result    Output param which will receive the localized pattern.
1706     *                  Previous contents are deleted.
1707     * @return          A reference to 'result'.
1708     * @see applyPattern
1709     * @stable ICU 2.0
1710     */
1711    virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
1712
1713    /**
1714     * Apply the given pattern to this Format object.  A pattern is a
1715     * short-hand specification for the various formatting properties.
1716     * These properties can also be changed individually through the
1717     * various setter methods.
1718     * <P>
1719     * There is no limit to integer digits are set
1720     * by this routine, since that is the typical end-user desire;
1721     * use setMaximumInteger if you want to set a real value.
1722     * For negative numbers, use a second pattern, separated by a semicolon
1723     * <pre>
1724     * .      Example "#,#00.0#" -> 1,234.56
1725     * </pre>
1726     * This means a minimum of 2 integer digits, 1 fraction digit, and
1727     * a maximum of 2 fraction digits.
1728     * <pre>
1729     * .      Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1730     * </pre>
1731     * In negative patterns, the minimum and maximum counts are ignored;
1732     * these are presumed to be set in the positive pattern.
1733     *
1734     * @param pattern    The pattern to be applied.
1735     * @param parseError Struct to recieve information on position
1736     *                   of error if an error is encountered
1737     * @param status     Output param set to success/failure code on
1738     *                   exit. If the pattern is invalid, this will be
1739     *                   set to a failure result.
1740     * @stable ICU 2.0
1741     */
1742    virtual void applyPattern(const UnicodeString& pattern,
1743                             UParseError& parseError,
1744                             UErrorCode& status);
1745    /**
1746     * Sets the pattern.
1747     * @param pattern   The pattern to be applied.
1748     * @param status    Output param set to success/failure code on
1749     *                  exit. If the pattern is invalid, this will be
1750     *                  set to a failure result.
1751     * @stable ICU 2.0
1752     */
1753    virtual void applyPattern(const UnicodeString& pattern,
1754                             UErrorCode& status);
1755
1756    /**
1757     * Apply the given pattern to this Format object.  The pattern
1758     * is assumed to be in a localized notation. A pattern is a
1759     * short-hand specification for the various formatting properties.
1760     * These properties can also be changed individually through the
1761     * various setter methods.
1762     * <P>
1763     * There is no limit to integer digits are set
1764     * by this routine, since that is the typical end-user desire;
1765     * use setMaximumInteger if you want to set a real value.
1766     * For negative numbers, use a second pattern, separated by a semicolon
1767     * <pre>
1768     * .      Example "#,#00.0#" -> 1,234.56
1769     * </pre>
1770     * This means a minimum of 2 integer digits, 1 fraction digit, and
1771     * a maximum of 2 fraction digits.
1772     *
1773     * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1774     *
1775     * In negative patterns, the minimum and maximum counts are ignored;
1776     * these are presumed to be set in the positive pattern.
1777     *
1778     * @param pattern   The localized pattern to be applied.
1779     * @param parseError Struct to recieve information on position
1780     *                   of error if an error is encountered
1781     * @param status    Output param set to success/failure code on
1782     *                  exit. If the pattern is invalid, this will be
1783     *                  set to a failure result.
1784     * @stable ICU 2.0
1785     */
1786    virtual void applyLocalizedPattern(const UnicodeString& pattern,
1787                                       UParseError& parseError,
1788                                       UErrorCode& status);
1789
1790    /**
1791     * Apply the given pattern to this Format object.
1792     *
1793     * @param pattern   The localized pattern to be applied.
1794     * @param status    Output param set to success/failure code on
1795     *                  exit. If the pattern is invalid, this will be
1796     *                  set to a failure result.
1797     * @stable ICU 2.0
1798     */
1799    virtual void applyLocalizedPattern(const UnicodeString& pattern,
1800                                       UErrorCode& status);
1801
1802
1803    /**
1804     * Sets the maximum number of digits allowed in the integer portion of a
1805     * number. This override limits the integer digit count to 309.
1806     *
1807     * @param newValue    the new value of the maximum number of digits
1808     *                      allowed in the integer portion of a number.
1809     * @see NumberFormat#setMaximumIntegerDigits
1810     * @stable ICU 2.0
1811     */
1812    virtual void setMaximumIntegerDigits(int32_t newValue);
1813
1814    /**
1815     * Sets the minimum number of digits allowed in the integer portion of a
1816     * number. This override limits the integer digit count to 309.
1817     *
1818     * @param newValue    the new value of the minimum number of digits
1819     *                      allowed in the integer portion of a number.
1820     * @see NumberFormat#setMinimumIntegerDigits
1821     * @stable ICU 2.0
1822     */
1823    virtual void setMinimumIntegerDigits(int32_t newValue);
1824
1825    /**
1826     * Sets the maximum number of digits allowed in the fraction portion of a
1827     * number. This override limits the fraction digit count to 340.
1828     *
1829     * @param newValue    the new value of the maximum number of digits
1830     *                    allowed in the fraction portion of a number.
1831     * @see NumberFormat#setMaximumFractionDigits
1832     * @stable ICU 2.0
1833     */
1834    virtual void setMaximumFractionDigits(int32_t newValue);
1835
1836    /**
1837     * Sets the minimum number of digits allowed in the fraction portion of a
1838     * number. This override limits the fraction digit count to 340.
1839     *
1840     * @param newValue    the new value of the minimum number of digits
1841     *                    allowed in the fraction portion of a number.
1842     * @see NumberFormat#setMinimumFractionDigits
1843     * @stable ICU 2.0
1844     */
1845    virtual void setMinimumFractionDigits(int32_t newValue);
1846
1847    /**
1848     * Returns the minimum number of significant digits that will be
1849     * displayed. This value has no effect unless areSignificantDigitsUsed()
1850     * returns true.
1851     * @return the fewest significant digits that will be shown
1852     * @stable ICU 3.0
1853     */
1854    int32_t getMinimumSignificantDigits() const;
1855
1856    /**
1857     * Returns the maximum number of significant digits that will be
1858     * displayed. This value has no effect unless areSignificantDigitsUsed()
1859     * returns true.
1860     * @return the most significant digits that will be shown
1861     * @stable ICU 3.0
1862     */
1863    int32_t getMaximumSignificantDigits() const;
1864
1865    /**
1866     * Sets the minimum number of significant digits that will be
1867     * displayed.  If <code>min</code> is less than one then it is set
1868     * to one.  If the maximum significant digits count is less than
1869     * <code>min</code>, then it is set to <code>min</code>. This
1870     * value has no effect unless areSignificantDigits() returns true.
1871     * @param min the fewest significant digits to be shown
1872     * @stable ICU 3.0
1873     */
1874    void setMinimumSignificantDigits(int32_t min);
1875
1876    /**
1877     * Sets the maximum number of significant digits that will be
1878     * displayed.  If <code>max</code> is less than one then it is set
1879     * to one.  If the minimum significant digits count is greater
1880     * than <code>max</code>, then it is set to <code>max</code>.
1881     * This value has no effect unless areSignificantDigits() returns
1882     * true.
1883     * @param max the most significant digits to be shown
1884     * @stable ICU 3.0
1885     */
1886    void setMaximumSignificantDigits(int32_t max);
1887
1888    /**
1889     * Returns true if significant digits are in use, or false if
1890     * integer and fraction digit counts are in use.
1891     * @return true if significant digits are in use
1892     * @stable ICU 3.0
1893     */
1894    UBool areSignificantDigitsUsed() const;
1895
1896    /**
1897     * Sets whether significant digits are in use, or integer and
1898     * fraction digit counts are in use.
1899     * @param useSignificantDigits true to use significant digits, or
1900     * false to use integer and fraction digit counts
1901     * @stable ICU 3.0
1902     */
1903    void setSignificantDigitsUsed(UBool useSignificantDigits);
1904
1905 public:
1906    /**
1907     * Sets the currency used to display currency
1908     * amounts.  This takes effect immediately, if this format is a
1909     * currency format.  If this format is not a currency format, then
1910     * the currency is used if and when this object becomes a
1911     * currency format through the application of a new pattern.
1912     * @param theCurrency a 3-letter ISO code indicating new currency
1913     * to use.  It need not be null-terminated.  May be the empty
1914     * string or NULL to indicate no currency.
1915     * @param ec input-output error code
1916     * @stable ICU 3.0
1917     */
1918    virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
1919
1920    /**
1921     * Sets the currency used to display currency amounts.  See
1922     * setCurrency(const UChar*, UErrorCode&).
1923     * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&).
1924     */
1925    virtual void setCurrency(const UChar* theCurrency);
1926
1927    /**
1928     * The resource tags we use to retrieve decimal format data from
1929     * locale resource bundles.
1930     * @deprecated ICU 3.4. This string has no public purpose. Please don't use it.
1931     */
1932    static const char fgNumberPatterns[];
1933
1934public:
1935
1936    /**
1937     * Return the class ID for this class.  This is useful only for
1938     * comparing to a return value from getDynamicClassID().  For example:
1939     * <pre>
1940     * .      Base* polymorphic_pointer = createPolymorphicObject();
1941     * .      if (polymorphic_pointer->getDynamicClassID() ==
1942     * .          Derived::getStaticClassID()) ...
1943     * </pre>
1944     * @return          The class ID for all objects of this class.
1945     * @stable ICU 2.0
1946     */
1947    static UClassID U_EXPORT2 getStaticClassID(void);
1948
1949    /**
1950     * Returns a unique class ID POLYMORPHICALLY.  Pure virtual override.
1951     * This method is to implement a simple version of RTTI, since not all
1952     * C++ compilers support genuine RTTI.  Polymorphic operator==() and
1953     * clone() methods call this method.
1954     *
1955     * @return          The class ID for this object. All objects of a
1956     *                  given class have the same class ID.  Objects of
1957     *                  other classes have different class IDs.
1958     * @stable ICU 2.0
1959     */
1960    virtual UClassID getDynamicClassID(void) const;
1961
1962private:
1963
1964    DecimalFormat(); // default constructor not implemented
1965
1966    int32_t precision() const;
1967
1968    /**
1969     *   Initialize all fields of a new DecimalFormatter.
1970     *      Common code for use by constructors.
1971     */
1972    void init(UErrorCode& status);
1973
1974    /**
1975     * Do real work of constructing a new DecimalFormat.
1976     */
1977    void construct(UErrorCode&               status,
1978                   UParseError&             parseErr,
1979                   const UnicodeString*     pattern = 0,
1980                   DecimalFormatSymbols*    symbolsToAdopt = 0
1981                   );
1982
1983    /**
1984     * Does the real work of generating a pattern.
1985     *
1986     * @param result     Output param which will receive the pattern.
1987     *                   Previous contents are deleted.
1988     * @param localized  TRUE return localized pattern.
1989     * @return           A reference to 'result'.
1990     */
1991    UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
1992
1993    /**
1994     * Does the real work of applying a pattern.
1995     * @param pattern    The pattern to be applied.
1996     * @param localized  If true, the pattern is localized; else false.
1997     * @param parseError Struct to recieve information on position
1998     *                   of error if an error is encountered
1999     * @param status     Output param set to success/failure code on
2000     *                   exit. If the pattern is invalid, this will be
2001     *                   set to a failure result.
2002     */
2003    void applyPattern(const UnicodeString& pattern,
2004                            UBool localized,
2005                            UParseError& parseError,
2006                            UErrorCode& status);
2007
2008    /*
2009     * similar to applyPattern, but without re-gen affix for currency
2010     */
2011    void applyPatternInternally(const UnicodeString& pluralCount,
2012                                const UnicodeString& pattern,
2013                                UBool localized,
2014                                UParseError& parseError,
2015                                UErrorCode& status);
2016
2017    /*
2018     * only apply pattern without expand affixes
2019     */
2020    void applyPatternWithoutExpandAffix(const UnicodeString& pattern,
2021                                        UBool localized,
2022                                        UParseError& parseError,
2023                                        UErrorCode& status);
2024
2025
2026    /*
2027     * expand affixes (after apply patter) and re-compute fFormatWidth
2028     */
2029    void expandAffixAdjustWidth(const UnicodeString* pluralCount);
2030
2031
2032    /**
2033     * Do the work of formatting a number, either a double or a long.
2034     *
2035     * @param appendTo       Output parameter to receive result.
2036     *                       Result is appended to existing contents.
2037     * @param handler        Records information about field positions.
2038     * @param digits         the digits to be formatted.
2039     * @param isInteger      if TRUE format the digits as Integer.
2040     * @return               Reference to 'appendTo' parameter.
2041     */
2042    UnicodeString& subformat(UnicodeString& appendTo,
2043                             FieldPositionHandler& handler,
2044                             DigitList&     digits,
2045                             UBool          isInteger,
2046                             UErrorCode &status) const;
2047
2048
2049    void parse(const UnicodeString& text,
2050               Formattable& result,
2051               ParsePosition& pos,
2052               UChar* currency) const;
2053
2054    enum {
2055        fgStatusInfinite,
2056        fgStatusLength      // Leave last in list.
2057    } StatusFlags;
2058
2059    UBool subparse(const UnicodeString& text,
2060                   const UnicodeString* negPrefix,
2061                   const UnicodeString* negSuffix,
2062                   const UnicodeString* posPrefix,
2063                   const UnicodeString* posSuffix,
2064                   UBool currencyParsing,
2065                   int8_t type,
2066                   ParsePosition& parsePosition,
2067                   DigitList& digits, UBool* status,
2068                   UChar* currency) const;
2069
2070    // Mixed style parsing for currency.
2071    // It parses against the current currency pattern
2072    // using complex affix comparison
2073    // parses against the currency plural patterns using complex affix comparison,
2074    // and parses against the current pattern using simple affix comparison.
2075    UBool parseForCurrency(const UnicodeString& text,
2076                           ParsePosition& parsePosition,
2077                           DigitList& digits,
2078                           UBool* status,
2079                           UChar* currency) const;
2080
2081    int32_t skipPadding(const UnicodeString& text, int32_t position) const;
2082
2083    int32_t compareAffix(const UnicodeString& input,
2084                         int32_t pos,
2085                         UBool isNegative,
2086                         UBool isPrefix,
2087                         const UnicodeString* affixPat,
2088                         UBool currencyParsing,
2089                         int8_t type,
2090                         UChar* currency) const;
2091
2092    static int32_t compareSimpleAffix(const UnicodeString& affix,
2093                                      const UnicodeString& input,
2094                                      int32_t pos,
2095                                      UBool lenient);
2096
2097    static int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos);
2098
2099    static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
2100
2101    int32_t compareComplexAffix(const UnicodeString& affixPat,
2102                                const UnicodeString& input,
2103                                int32_t pos,
2104                                int8_t type,
2105                                UChar* currency) const;
2106
2107    static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
2108
2109    static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
2110
2111    static UBool matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol,
2112                             UnicodeSet *sset, UChar32 schar);
2113
2114    static UBool matchDecimal(UChar32 symbolChar,
2115                            UBool sawDecimal,  UChar32 sawDecimalChar,
2116                             const UnicodeSet *sset, UChar32 schar);
2117
2118    static UBool matchGrouping(UChar32 groupingChar,
2119                            UBool sawGrouping, UChar32 sawGroupingChar,
2120                             const UnicodeSet *sset,
2121                             UChar32 decimalChar, const UnicodeSet *decimalSet,
2122                             UChar32 schar);
2123
2124    /**
2125     * Get a decimal format symbol.
2126     * Returns a const reference to the symbol string.
2127     * @internal
2128     */
2129    inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
2130
2131    int32_t appendAffix(UnicodeString& buf,
2132                        double number,
2133                        FieldPositionHandler& handler,
2134                        UBool isNegative,
2135                        UBool isPrefix) const;
2136
2137    /**
2138     * Append an affix to the given UnicodeString, using quotes if
2139     * there are special characters.  Single quotes themselves must be
2140     * escaped in either case.
2141     */
2142    void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
2143                            UBool localized) const;
2144
2145    void appendAffixPattern(UnicodeString& appendTo,
2146                            const UnicodeString* affixPattern,
2147                            const UnicodeString& expAffix, UBool localized) const;
2148
2149    void expandAffix(const UnicodeString& pattern,
2150                     UnicodeString& affix,
2151                     double number,
2152                     FieldPositionHandler& handler,
2153                     UBool doFormat,
2154                     const UnicodeString* pluralCount) const;
2155
2156    void expandAffixes(const UnicodeString* pluralCount);
2157
2158    void addPadding(UnicodeString& appendTo,
2159                    FieldPositionHandler& handler,
2160                    int32_t prefixLen, int32_t suffixLen) const;
2161
2162    UBool isGroupingPosition(int32_t pos) const;
2163
2164    void setCurrencyForSymbols();
2165
2166    // similar to setCurrency without re-compute the affixes for currency.
2167    // If currency changes, the affix pattern for currency is not changed,
2168    // but the affix will be changed. So, affixes need to be
2169    // re-computed in setCurrency(), but not in setCurrencyInternally().
2170    virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec);
2171
2172    // set up currency affix patterns for mix parsing.
2173    // The patterns saved here are the affix patterns of default currency
2174    // pattern and the unique affix patterns of the plural currency patterns.
2175    // Those patterns are used by parseForCurrency().
2176    void setupCurrencyAffixPatterns(UErrorCode& status);
2177
2178    // set up the currency affixes used in currency plural formatting.
2179    // It sets up both fAffixesForCurrency for currency pattern if the current
2180    // pattern contains 3 currency signs,
2181    // and it sets up fPluralAffixesForCurrency for currency plural patterns.
2182    void setupCurrencyAffixes(const UnicodeString& pattern,
2183                              UBool setupForCurrentPattern,
2184                              UBool setupForPluralPattern,
2185                              UErrorCode& status);
2186
2187    // hashtable operations
2188    Hashtable* initHashForAffixPattern(UErrorCode& status);
2189    Hashtable* initHashForAffix(UErrorCode& status);
2190
2191    void deleteHashForAffixPattern();
2192    void deleteHashForAffix(Hashtable*& table);
2193
2194    void copyHashForAffixPattern(const Hashtable* source,
2195                                 Hashtable* target, UErrorCode& status);
2196    void copyHashForAffix(const Hashtable* source,
2197                          Hashtable* target, UErrorCode& status);
2198
2199    UnicodeString& _format(int64_t number,
2200                           UnicodeString& appendTo,
2201                           FieldPositionHandler& handler,
2202                           UErrorCode &status) const;
2203    UnicodeString& _format(double number,
2204                           UnicodeString& appendTo,
2205                           FieldPositionHandler& handler,
2206                           UErrorCode &status) const;
2207    UnicodeString& _format(const DigitList &number,
2208                           UnicodeString& appendTo,
2209                           FieldPositionHandler& handler,
2210                           UErrorCode &status) const;
2211
2212    // currency sign count
2213    enum {
2214        fgCurrencySignCountZero,
2215        fgCurrencySignCountInSymbolFormat,
2216        fgCurrencySignCountInISOFormat,
2217        fgCurrencySignCountInPluralFormat
2218    } CurrencySignCount;
2219
2220    /**
2221     * Constants.
2222     */
2223
2224    UnicodeString           fPositivePrefix;
2225    UnicodeString           fPositiveSuffix;
2226    UnicodeString           fNegativePrefix;
2227    UnicodeString           fNegativeSuffix;
2228    UnicodeString*          fPosPrefixPattern;
2229    UnicodeString*          fPosSuffixPattern;
2230    UnicodeString*          fNegPrefixPattern;
2231    UnicodeString*          fNegSuffixPattern;
2232
2233    /**
2234     * Formatter for ChoiceFormat-based currency names.  If this field
2235     * is not null, then delegate to it to format currency symbols.
2236     * @since ICU 2.6
2237     */
2238    ChoiceFormat*           fCurrencyChoice;
2239
2240    DigitList *             fMultiplier;   // NULL for multiplier of one
2241    int32_t                 fScale;
2242    int32_t                 fGroupingSize;
2243    int32_t                 fGroupingSize2;
2244    UBool                   fDecimalSeparatorAlwaysShown;
2245    DecimalFormatSymbols*   fSymbols;
2246
2247    UBool                   fUseSignificantDigits;
2248    int32_t                 fMinSignificantDigits;
2249    int32_t                 fMaxSignificantDigits;
2250
2251    UBool                   fUseExponentialNotation;
2252    int8_t                  fMinExponentDigits;
2253    UBool                   fExponentSignAlwaysShown;
2254
2255    EnumSet<UNumberFormatAttribute,
2256            UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1,
2257            UNUM_LIMIT_BOOLEAN_ATTRIBUTE>
2258                            fBoolFlags;
2259
2260    DigitList*              fRoundingIncrement;  // NULL if no rounding increment specified.
2261    ERoundingMode           fRoundingMode;
2262
2263    UChar32                 fPad;
2264    int32_t                 fFormatWidth;
2265    EPadPosition            fPadPosition;
2266
2267    /*
2268     * Following are used for currency format
2269     */
2270    // pattern used in this formatter
2271    UnicodeString fFormatPattern;
2272    // style is only valid when decimal formatter is constructed by
2273    // DecimalFormat(pattern, decimalFormatSymbol, style)
2274    int fStyle;
2275    /*
2276     * Represents whether this is a currency format, and which
2277     * currency format style.
2278     * 0: not currency format type;
2279     * 1: currency style -- symbol name, such as "$" for US dollar.
2280     * 2: currency style -- ISO name, such as USD for US dollar.
2281     * 3: currency style -- plural long name, such as "US Dollar" for
2282     *                      "1.00 US Dollar", or "US Dollars" for
2283     *                      "3.00 US Dollars".
2284     */
2285    int fCurrencySignCount;
2286
2287
2288    /* For currency parsing purose,
2289     * Need to remember all prefix patterns and suffix patterns of
2290     * every currency format pattern,
2291     * including the pattern of default currecny style
2292     * and plural currency style. And the patterns are set through applyPattern.
2293     */
2294    // TODO: innerclass?
2295    /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2296    struct AffixPatternsForCurrency : public UMemory {
2297        // negative prefix pattern
2298        UnicodeString negPrefixPatternForCurrency;
2299        // negative suffix pattern
2300        UnicodeString negSuffixPatternForCurrency;
2301        // positive prefix pattern
2302        UnicodeString posPrefixPatternForCurrency;
2303        // positive suffix pattern
2304        UnicodeString posSuffixPatternForCurrency;
2305        int8_t patternType;
2306
2307        AffixPatternsForCurrency(const UnicodeString& negPrefix,
2308                                 const UnicodeString& negSuffix,
2309                                 const UnicodeString& posPrefix,
2310                                 const UnicodeString& posSuffix,
2311                                 int8_t type) {
2312            negPrefixPatternForCurrency = negPrefix;
2313            negSuffixPatternForCurrency = negSuffix;
2314            posPrefixPatternForCurrency = posPrefix;
2315            posSuffixPatternForCurrency = posSuffix;
2316            patternType = type;
2317        }
2318    };
2319    */
2320
2321    /* affix for currency formatting when the currency sign in the pattern
2322     * equals to 3, such as the pattern contains 3 currency sign or
2323     * the formatter style is currency plural format style.
2324     */
2325    /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2326    struct AffixesForCurrency : public UMemory {
2327        // negative prefix
2328        UnicodeString negPrefixForCurrency;
2329        // negative suffix
2330        UnicodeString negSuffixForCurrency;
2331        // positive prefix
2332        UnicodeString posPrefixForCurrency;
2333        // positive suffix
2334        UnicodeString posSuffixForCurrency;
2335
2336        int32_t formatWidth;
2337
2338        AffixesForCurrency(const UnicodeString& negPrefix,
2339                           const UnicodeString& negSuffix,
2340                           const UnicodeString& posPrefix,
2341                           const UnicodeString& posSuffix) {
2342            negPrefixForCurrency = negPrefix;
2343            negSuffixForCurrency = negSuffix;
2344            posPrefixForCurrency = posPrefix;
2345            posSuffixForCurrency = posSuffix;
2346        }
2347    };
2348    */
2349
2350    // Affix pattern set for currency.
2351    // It is a set of AffixPatternsForCurrency,
2352    // each element of the set saves the negative prefix pattern,
2353    // negative suffix pattern, positive prefix pattern,
2354    // and positive suffix  pattern of a pattern.
2355    // It is used for currency mixed style parsing.
2356    // It is actually is a set.
2357    // The set contains the default currency pattern from the locale,
2358    // and the currency plural patterns.
2359    // Since it is a set, it does not contain duplicated items.
2360    // For example, if 2 currency plural patterns are the same, only one pattern
2361    // is included in the set. When parsing, we do not check whether the plural
2362    // count match or not.
2363    Hashtable* fAffixPatternsForCurrency;
2364
2365    // Following 2 are affixes for currency.
2366    // It is a hash map from plural count to AffixesForCurrency.
2367    // AffixesForCurrency saves the negative prefix,
2368    // negative suffix, positive prefix, and positive suffix of a pattern.
2369    // It is used during currency formatting only when the currency sign count
2370    // is 3. In which case, the affixes are getting from here, not
2371    // from the fNegativePrefix etc.
2372    Hashtable* fAffixesForCurrency;  // for current pattern
2373    Hashtable* fPluralAffixesForCurrency;  // for plural pattern
2374
2375    // Information needed for DecimalFormat to format/parse currency plural.
2376    CurrencyPluralInfo* fCurrencyPluralInfo;
2377
2378#if UCONFIG_HAVE_PARSEALLINPUT
2379    UNumberFormatAttributeValue fParseAllInput;
2380#endif
2381
2382
2383protected:
2384
2385#ifndef U_HIDE_INTERNAL_API
2386    /**
2387     * Rounds a value according to the rules of this object.
2388     * @internal
2389     */
2390    DigitList& _round(const DigitList& number, DigitList& adjustedNum, UBool& isNegative, UErrorCode& status) const;
2391#endif  /* U_HIDE_INTERNAL_API */
2392
2393    /**
2394     * Returns the currency in effect for this formatter.  Subclasses
2395     * should override this method as needed.  Unlike getCurrency(),
2396     * this method should never return "".
2397     * @result output parameter for null-terminated result, which must
2398     * have a capacity of at least 4
2399     * @internal
2400     */
2401    virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
2402
2403  /** number of integer digits
2404   * @stable ICU 2.4
2405   */
2406    static const int32_t  kDoubleIntegerDigits;
2407  /** number of fraction digits
2408   * @stable ICU 2.4
2409   */
2410    static const int32_t  kDoubleFractionDigits;
2411
2412    /**
2413     * When someone turns on scientific mode, we assume that more than this
2414     * number of digits is due to flipping from some other mode that didn't
2415     * restrict the maximum, and so we force 1 integer digit.  We don't bother
2416     * to track and see if someone is using exponential notation with more than
2417     * this number, it wouldn't make sense anyway, and this is just to make sure
2418     * that someone turning on scientific mode with default settings doesn't
2419     * end up with lots of zeroes.
2420     * @stable ICU 2.8
2421     */
2422    static const int32_t  kMaxScientificIntegerDigits;
2423
2424#if UCONFIG_FORMAT_FASTPATHS_49
2425 private:
2426    /**
2427     * Internal state.
2428     * @internal
2429     */
2430    uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE];
2431
2432
2433    /**
2434     * Called whenever any state changes. Recomputes whether fastpath is OK to use.
2435     */
2436    void handleChanged();
2437#endif
2438};
2439
2440inline UnicodeString&
2441DecimalFormat::format(const Formattable& obj,
2442                      UnicodeString& appendTo,
2443                      UErrorCode& status) const {
2444    // Don't use Format:: - use immediate base class only,
2445    // in case immediate base modifies behavior later.
2446    return NumberFormat::format(obj, appendTo, status);
2447}
2448
2449inline UnicodeString&
2450DecimalFormat::format(double number,
2451                      UnicodeString& appendTo) const {
2452    FieldPosition pos(0);
2453    return format(number, appendTo, pos);
2454}
2455
2456inline UnicodeString&
2457DecimalFormat::format(int32_t number,
2458                      UnicodeString& appendTo) const {
2459    FieldPosition pos(0);
2460    return format((int64_t)number, appendTo, pos);
2461}
2462
2463inline const UnicodeString &
2464DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
2465    return fSymbols->getConstSymbol(symbol);
2466}
2467
2468U_NAMESPACE_END
2469
2470#endif /* #if !UCONFIG_NO_FORMATTING */
2471
2472#endif // _DECIMFMT
2473//eof
2474