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