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