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