2 ********************************************************************************
3 * Copyright (C) 1997-2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
9 * Modification History:
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
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 ********************************************************************************
28 #include "unicode/utypes.h"
31 * \brief C++ API: Formats decimal numbers.
34 #if !UCONFIG_NO_FORMATTING
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"
44 #ifndef U_HIDE_INTERNAL_API
46 * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE
49 #if UCONFIG_FORMAT_FASTPATHS_49
50 #define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16
52 #endif /* U_HIDE_INTERNAL_API */
57 class CurrencyPluralInfo
;
60 class FieldPositionHandler
;
61 class DecimalFormatStaticSets
;
63 class DecimalFormatImpl
;
65 class VisibleDigitsWithExponent
;
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
>;
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.
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.
89 * <p><strong>Example Usage</strong>
92 * // Normally we would have a GUI with a menu for this
94 * const Locale* locales = NumberFormat::getAvailableLocales(locCount);
96 * double myNumber = -1234.56;
97 * UErrorCode success = U_ZERO_ERROR;
100 * // Print out a number with the localized number, currency and percent
101 * // format for each locale.
102 * UnicodeString countryName;
103 * UnicodeString displayName;
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
116 * form = NumberFormat::createInstance(locales[i], success ); break;
118 * form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
120 * form = NumberFormat::createPercentInstance(locales[i], success ); break;
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);
134 * Another example use createInstance(style)
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;
144 * Formattable fmtable;
145 * for (int j=NumberFormat::kNumberStyle;
146 * j<=NumberFormat::kPluralCurrencyStyle;
148 * NumberFormat* format = NumberFormat::createInstance(locale, j, success);
150 * cout << "format result " << form->format(myNumber, str) << endl;
151 * format->parse(form->format(myNumber, str), fmtable, success);
155 * <p><strong>Patterns</strong>
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.
165 * <p><strong>Special Pattern Characters</strong>
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.
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.
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
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>
199 * <tr valign=top bgcolor="#eeeeff">
200 * <td><code>1-9</code>
203 * <td>'1' through '9' indicate rounding.
205 * <td><code>\htmlonly@\endhtmlonly</code> <!--doxygen doesn't like @-->
208 * <td>Significant digit
209 * <tr valign=top bgcolor="#eeeeff">
213 * <td>Digit, zero shows as absent
218 * <td>Decimal separator or monetary decimal separator
219 * <tr valign=top bgcolor="#eeeeff">
228 * <td>Grouping separator
229 * <tr valign=top bgcolor="#eeeeff">
233 * <td>Separates mantissa and exponent in scientific notation.
234 * <em>Need not be quoted in prefix or suffix.</em>
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">
243 * <td>Subpattern boundary
245 * <td>Separates positive and negative subpatterns
247 * <td><code>\%</code>
248 * <td>Prefix or suffix
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
255 * <td>Multiply by 1000 and show as per mille
257 * <td><code>\htmlonly¤\endhtmlonly</code> (<code>\\u00A4</code>)
258 * <td>Prefix or suffix
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">
268 * <td>Prefix or suffix
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>.
276 * <td>Prefix or suffix boundary
278 * <td>Pad escape, precedes pad character
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#)".
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.
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 "#,##,###,####" == "###,###,####" == "##,#,###,####".
317 * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
318 * DecimalFormat to set a failing UErrorCode.
320 * <p><strong>Pattern BNF</strong>
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
336 * X* 0 or more instances of X
337 * X? 0 or 1 instances of X
339 * C..D any character from C up to D, inclusive
340 * S-T characters in S, except those in T
342 * The first subpattern is for positive numbers. The second (optional)
343 * subpattern is for negative numbers.
345 * <p>Not indicated in the BNF syntax above:
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.
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 * "#,##,###" formats the number 123456789 as
358 * "12,34,56,789".</li>
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.
363 * <li>In place of '0', the digits '1' through '9' may be used to
364 * indicate a rounding increment.
367 * <p><strong>Parsing</strong>
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.
376 * <p>During parsing, grouping separators are ignored.
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".
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
390 * <p><strong>Formatting</strong>
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>.
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.
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
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.
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.
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.
424 * <p><strong>Special Values</strong>
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.
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.
436 * <a name="sci"><strong>Scientific Notation</strong></a>
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
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
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.
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".
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.
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.
487 * <li>Exponential patterns may not contain grouping separators.
490 * <a name="sigdig"><strong>Significant Digits</strong></a>
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
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()
510 * <td><code>\@\@\@</code>
514 * <td><code>12300</code>
515 * <tr valign=top bgcolor="#eeeeff">
516 * <td><code>\@\@\@</code>
520 * <td><code>0.123</code>
522 * <td><code>\@\@##</code>
526 * <td><code>3.142</code>
527 * <tr valign=top bgcolor="#eeeeff">
528 * <td><code>\@\@##</code>
532 * <td><code>1.23</code>
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>.
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
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.
563 * <li>In order to enable significant digits formatting, use a pattern
564 * containing the <code>'@'</code> pattern character. Alternatively,
565 * call setSignificantDigitsUsed(TRUE).
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).
571 * <li>The number of significant digits has no effect on parsing.
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>.
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.
587 * <p><strong>Padding</strong>
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>.
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.
604 * <li>The width is counted in 16-bit code units (UChars).
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
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
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.
627 * <p><strong>Rounding</strong>
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.
636 * <p>In the absense of an explicit rounding increment numbers are
637 * rounded to their formatted width.
640 * <li>Rounding only affects the string produced by formatting. It does
641 * not affect parsing or change any numerical values.
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.
648 * <li>Some locales use rounding in their currency formats to reflect the
649 * smallest currency denomination.
651 * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
652 * behave identically to digit '0'.
655 * <p><strong>Synchronization</strong>
657 * <p>DecimalFormat objects are not synchronized. Multiple
658 * threads should not access one formatter concurrently.
660 * <p><strong>Subclassing</strong>
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.
666 class U_I18N_API DecimalFormat
: public NumberFormat
{
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 */
684 * Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
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.
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
710 * @param status Output param set to success/failure code. If the
711 * pattern is invalid this will be set to a failure code.
714 DecimalFormat(UErrorCode
& status
);
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.
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
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.
730 DecimalFormat(const UnicodeString
& pattern
,
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.
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.
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.
751 DecimalFormat( const UnicodeString
& pattern
,
752 DecimalFormatSymbols
* symbolsToAdopt
,
755 #ifndef U_HIDE_INTERNAL_API
757 * This API is for ICU use only.
758 * Create a DecimalFormat from the given pattern, symbols, and style.
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.
768 DecimalFormat( const UnicodeString
& pattern
,
769 DecimalFormatSymbols
* symbolsToAdopt
,
770 UNumberFormatStyle style
,
773 #if UCONFIG_HAVE_PARSEALLINPUT
777 void setParseAllInput(UNumberFormatAttributeValue value
);
780 #endif /* U_HIDE_INTERNAL_API */
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(...) )
793 virtual DecimalFormat
& setAttribute( UNumberFormatAttribute attr
,
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.
806 virtual int32_t getAttribute( UNumberFormatAttribute attr
,
807 UErrorCode
&status
) const;
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
816 virtual void setGroupingUsed(UBool newValue
);
819 * Sets whether or not numbers should be parsed as integers only.
820 * @param value set True, this format will parse numbers as integers
822 * @see isParseIntegerOnly
825 virtual void setParseIntegerOnly(UBool value
);
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.
836 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
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.
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.
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.
857 DecimalFormat( const UnicodeString
& pattern
,
858 DecimalFormatSymbols
* symbolsToAdopt
,
859 UParseError
& parseError
,
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.
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.
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.
878 DecimalFormat( const UnicodeString
& pattern
,
879 const DecimalFormatSymbols
& symbols
,
885 * @param source the DecimalFormat object to be copied from.
888 DecimalFormat(const DecimalFormat
& source
);
891 * Assignment operator.
893 * @param rhs the DecimalFormat object to be copied.
896 DecimalFormat
& operator=(const DecimalFormat
& rhs
);
902 virtual ~DecimalFormat();
905 * Clone this Format object polymorphically. The caller owns the
906 * result and should delete it when done.
908 * @return a polymorphic copy of this DecimalFormat.
911 virtual Format
* clone(void) const;
914 * Return true if the given Format objects are semantically equal.
915 * Objects of different subclasses are considered unequal.
917 * @param other the object to be compared with.
918 * @return true if the given Format objects are semantically equal.
921 virtual UBool
operator==(const Format
& other
) const;
924 using NumberFormat::format
;
927 * Format a double or long number using base-10 representation.
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.
937 virtual UnicodeString
& format(double number
,
938 UnicodeString
& appendTo
,
939 FieldPosition
& pos
) const;
943 * Format a double or long number using base-10 representation.
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.
951 * @return Reference to 'appendTo' parameter.
954 virtual UnicodeString
& format(double number
,
955 UnicodeString
& appendTo
,
957 UErrorCode
&status
) const;
960 * Format a double or long number using base-10 representation.
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.
968 * @param status Output param filled with success/failure status.
969 * @return Reference to 'appendTo' parameter.
972 virtual UnicodeString
& format(double number
,
973 UnicodeString
& appendTo
,
974 FieldPositionIterator
* posIter
,
975 UErrorCode
& status
) const;
978 * Format a long number using base-10 representation.
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.
988 virtual UnicodeString
& format(int32_t number
,
989 UnicodeString
& appendTo
,
990 FieldPosition
& pos
) const;
993 * Format a long number using base-10 representation.
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.
1003 virtual UnicodeString
& format(int32_t number
,
1004 UnicodeString
& appendTo
,
1006 UErrorCode
&status
) const;
1009 * Format a long number using base-10 representation.
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.
1017 * @param status Output param filled with success/failure status.
1018 * @return Reference to 'appendTo' parameter.
1021 virtual UnicodeString
& format(int32_t number
,
1022 UnicodeString
& appendTo
,
1023 FieldPositionIterator
* posIter
,
1024 UErrorCode
& status
) const;
1027 * Format an int64 number using base-10 representation.
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.
1037 virtual UnicodeString
& format(int64_t number
,
1038 UnicodeString
& appendTo
,
1039 FieldPosition
& pos
) const;
1042 * Format an int64 number using base-10 representation.
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.
1052 virtual UnicodeString
& format(int64_t number
,
1053 UnicodeString
& appendTo
,
1055 UErrorCode
&status
) const;
1058 * Format an int64 number using base-10 representation.
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.
1066 * @param status Output param filled with success/failure status.
1067 * @return Reference to 'appendTo' parameter.
1070 virtual UnicodeString
& format(int64_t number
,
1071 UnicodeString
& appendTo
,
1072 FieldPositionIterator
* posIter
,
1073 UErrorCode
& status
) const;
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
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.
1087 * @param status Output param filled with success/failure status.
1088 * @return Reference to 'appendTo' parameter.
1091 virtual UnicodeString
& format(const StringPiece
&number
,
1092 UnicodeString
& appendTo
,
1093 FieldPositionIterator
* posIter
,
1094 UErrorCode
& status
) const;
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.
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.
1112 virtual UnicodeString
& format(const DigitList
&number
,
1113 UnicodeString
& appendTo
,
1114 FieldPositionIterator
* posIter
,
1115 UErrorCode
& status
) const;
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.
1128 virtual UnicodeString
& format(
1129 const VisibleDigitsWithExponent
&number
,
1130 UnicodeString
& appendTo
,
1132 UErrorCode
& status
) const;
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.
1145 virtual UnicodeString
& format(
1146 const VisibleDigitsWithExponent
&number
,
1147 UnicodeString
& appendTo
,
1148 FieldPositionIterator
* posIter
,
1149 UErrorCode
& status
) const;
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.
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.
1166 virtual UnicodeString
& format(const DigitList
&number
,
1167 UnicodeString
& appendTo
,
1169 UErrorCode
& status
) const;
1171 using NumberFormat::parse
;
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.
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.
1192 virtual void parse(const UnicodeString
& text
,
1193 Formattable
& result
,
1194 ParsePosition
& parsePosition
) const;
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.
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.
1215 virtual CurrencyAmount
* parseCurrency(const UnicodeString
& text
,
1216 ParsePosition
& pos
) const;
1219 * Returns the decimal format symbols, which is generally not changed
1220 * by the programmer or user.
1221 * @return desired DecimalFormatSymbols
1222 * @see DecimalFormatSymbols
1225 virtual const DecimalFormatSymbols
* getDecimalFormatSymbols(void) const;
1228 * Sets the decimal format symbols, which is generally not changed
1229 * by the programmer or user.
1230 * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
1233 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols
* symbolsToAdopt
);
1236 * Sets the decimal format symbols, which is generally not changed
1237 * by the programmer or user.
1238 * @param symbols DecimalFormatSymbols.
1241 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols
& symbols
);
1245 * Returns the currency plural format information,
1246 * which is generally not changed by the programmer or user.
1247 * @return desired CurrencyPluralInfo
1250 virtual const CurrencyPluralInfo
* getCurrencyPluralInfo(void) const;
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.
1258 virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo
* toAdopt
);
1261 * Sets the currency plural format information,
1262 * which is generally not changed by the programmer or user.
1263 * @param info Currency Plural Info.
1266 virtual void setCurrencyPluralInfo(const CurrencyPluralInfo
& info
);
1270 * Get the positive prefix.
1272 * @param result Output param which will receive the positive prefix.
1273 * @return A reference to 'result'.
1274 * Examples: +123, $123, sFr123
1277 UnicodeString
& getPositivePrefix(UnicodeString
& result
) const;
1280 * Set the positive prefix.
1282 * @param newValue the new value of the the positive prefix to be set.
1283 * Examples: +123, $123, sFr123
1286 virtual void setPositivePrefix(const UnicodeString
& newValue
);
1289 * Get the negative prefix.
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
1296 UnicodeString
& getNegativePrefix(UnicodeString
& result
) const;
1299 * Set the negative prefix.
1301 * @param newValue the new value of the the negative prefix to be set.
1302 * Examples: -123, ($123) (with negative suffix), sFr-123
1305 virtual void setNegativePrefix(const UnicodeString
& newValue
);
1308 * Get the positive suffix.
1310 * @param result Output param which will receive the positive suffix.
1311 * @return A reference to 'result'.
1315 UnicodeString
& getPositiveSuffix(UnicodeString
& result
) const;
1318 * Set the positive suffix.
1320 * @param newValue the new value of the positive suffix to be set.
1324 virtual void setPositiveSuffix(const UnicodeString
& newValue
);
1327 * Get the negative suffix.
1329 * @param result Output param which will receive the negative suffix.
1330 * @return A reference to 'result'.
1331 * Examples: -123%, ($123) (with positive suffixes)
1334 UnicodeString
& getNegativeSuffix(UnicodeString
& result
) const;
1337 * Set the negative suffix.
1339 * @param newValue the new value of the negative suffix to be set.
1343 virtual void setNegativeSuffix(const UnicodeString
& newValue
);
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.
1351 * @return the multiplier for use in percent, permill, etc.
1352 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1355 int32_t getMultiplier(void) const;
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.
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
1367 virtual void setMultiplier(int32_t newValue
);
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
1378 virtual double getRoundingIncrement(void) const;
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
1391 virtual void setRoundingIncrement(double newValue
);
1394 * Get the rounding mode.
1395 * @return A rounding mode
1396 * @see #setRoundingIncrement
1397 * @see #getRoundingIncrement
1398 * @see #setRoundingMode
1401 virtual ERoundingMode
getRoundingMode(void) const;
1404 * Set the rounding mode.
1405 * @param roundingMode A rounding mode
1406 * @see #setRoundingIncrement
1407 * @see #getRoundingIncrement
1408 * @see #getRoundingMode
1411 virtual void setRoundingMode(ERoundingMode roundingMode
);
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
1424 virtual int32_t getFormatWidth(void) const;
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
1440 virtual void setFormatWidth(int32_t width
);
1443 * Get the pad character used to pad to the format width. The
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
1454 virtual UnicodeString
getPadCharacterString() const;
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
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
1470 virtual void setPadCharacter(const UnicodeString
&padChar
);
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
1479 * @see #setFormatWidth
1480 * @see #getFormatWidth
1481 * @see #setPadCharacter
1482 * @see #getPadCharacterString
1483 * @see #setPadPosition
1484 * @see #EPadPosition
1487 virtual EPadPosition
getPadPosition(void) const;
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
1494 * @param padPos the pad position, one of kPadBeforePrefix,
1495 * kPadAfterPrefix, kPadBeforeSuffix, or
1497 * @see #setFormatWidth
1498 * @see #getFormatWidth
1499 * @see #setPadCharacter
1500 * @see #getPadCharacterString
1501 * @see #getPadPosition
1502 * @see #EPadPosition
1505 virtual void setPadPosition(EPadPosition padPos
);
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
1517 virtual UBool
isScientificNotation(void) const;
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
1527 * @see #isScientificNotation
1528 * @see #getMinimumExponentDigits
1529 * @see #setMinimumExponentDigits
1530 * @see #isExponentSignAlwaysShown
1531 * @see #setExponentSignAlwaysShown
1534 virtual void setScientificNotation(UBool useScientific
);
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
1546 virtual int8_t getMinimumExponentDigits(void) const;
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
1560 virtual void setMinimumExponentDigits(int8_t minExpDig
);
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
1574 virtual UBool
isExponentSignAlwaysShown(void) const;
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
1589 virtual void setExponentSignAlwaysShown(UBool expSignAlways
);
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.
1596 * @return the grouping size.
1597 * @see setGroupingSize
1598 * @see NumberFormat::isGroupingUsed
1599 * @see DecimalFormatSymbols::getGroupingSeparator
1602 int32_t getGroupingSize(void) const;
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.
1609 * @param newValue the new value of the grouping size.
1610 * @see getGroupingSize
1611 * @see NumberFormat::setGroupingUsed
1612 * @see DecimalFormatSymbols::setGroupingSeparator
1615 virtual void setGroupingSize(int32_t newValue
);
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
1635 int32_t getSecondaryGroupingSize(void) const;
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.
1642 * @param newValue the new value of the secondary grouping size.
1643 * @see getSecondaryGroupingSize
1644 * @see NumberFormat#setGroupingUsed
1645 * @see DecimalFormatSymbols::setGroupingSeparator
1648 virtual void setSecondaryGroupingSize(int32_t newValue
);
1650 #ifndef U_HIDE_INTERNAL_API
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().)
1659 * For example, if this value is 2, and the grouping size is 3, then
1660 * 9999 -> "9999" and 10000 -> "10,000"
1662 * This is a technology preview. This API may change behavior or may be removed.
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.
1669 * @see setMinimumGroupingDigits
1670 * @see getGroupingSize
1671 * @internal technology preview
1673 int32_t getMinimumGroupingDigits() const;
1675 #endif /* U_HIDE_INTERNAL_API */
1677 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following draft method since it is virtual. */
1679 * Sets the minimum grouping digits. Setting to a value less than or
1680 * equal to 1 turns off minimum grouping digits.
1682 * @param newValue the new value of minimum grouping digits.
1683 * @see getMinimumGroupingDigits
1684 * @internal technology preview
1686 virtual void setMinimumGroupingDigits(int32_t newValue
);
1690 * Allows you to get the behavior of the decimal separator with integers.
1691 * (The decimal separator will always appear with decimals.)
1693 * @return TRUE if the decimal separator always appear with decimals.
1694 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1697 UBool
isDecimalSeparatorAlwaysShown(void) const;
1700 * Allows you to set the behavior of the decimal separator with integers.
1701 * (The decimal separator will always appear with decimals.)
1703 * @param newValue set TRUE if the decimal separator will always appear with decimals.
1704 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1707 virtual void setDecimalSeparatorAlwaysShown(UBool newValue
);
1710 * Allows you to get the parse behavior of the pattern decimal mark.
1712 * @return TRUE if input must contain a match to decimal mark in pattern
1715 UBool
isDecimalPatternMatchRequired(void) const;
1718 * Allows you to set the behavior of the pattern decimal mark.
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.
1723 * @param newValue set TRUE if input must contain a match to decimal mark in pattern
1726 virtual void setDecimalPatternMatchRequired(UBool newValue
);
1730 * Synthesizes a pattern string that represents the current state
1731 * of this Format object.
1733 * @param result Output param which will receive the pattern.
1734 * Previous contents are deleted.
1735 * @return A reference to 'result'.
1739 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
1742 * Synthesizes a localized pattern string that represents the current
1743 * state of this Format object.
1745 * @param result Output param which will receive the localized pattern.
1746 * Previous contents are deleted.
1747 * @return A reference to 'result'.
1751 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
) const;
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.
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
1764 * . Example "#,#00.0#" -> 1,234.56
1766 * This means a minimum of 2 integer digits, 1 fraction digit, and
1767 * a maximum of 2 fraction digits.
1769 * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1771 * In negative patterns, the minimum and maximum counts are ignored;
1772 * these are presumed to be set in the positive pattern.
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.
1782 virtual void applyPattern(const UnicodeString
& pattern
,
1783 UParseError
& parseError
,
1784 UErrorCode
& status
);
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.
1793 virtual void applyPattern(const UnicodeString
& pattern
,
1794 UErrorCode
& status
);
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.
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
1808 * . Example "#,#00.0#" -> 1,234.56
1810 * This means a minimum of 2 integer digits, 1 fraction digit, and
1811 * a maximum of 2 fraction digits.
1813 * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1815 * In negative patterns, the minimum and maximum counts are ignored;
1816 * these are presumed to be set in the positive pattern.
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.
1826 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1827 UParseError
& parseError
,
1828 UErrorCode
& status
);
1831 * Apply the given pattern to this Format object.
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.
1839 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1840 UErrorCode
& status
);
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.
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
1852 virtual void setMaximumIntegerDigits(int32_t newValue
);
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.
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
1863 virtual void setMinimumIntegerDigits(int32_t newValue
);
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.
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
1874 virtual void setMaximumFractionDigits(int32_t newValue
);
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.
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
1885 virtual void setMinimumFractionDigits(int32_t newValue
);
1888 * Returns the minimum number of significant digits that will be
1889 * displayed. This value has no effect unless areSignificantDigitsUsed()
1891 * @return the fewest significant digits that will be shown
1894 int32_t getMinimumSignificantDigits() const;
1897 * Returns the maximum number of significant digits that will be
1898 * displayed. This value has no effect unless areSignificantDigitsUsed()
1900 * @return the most significant digits that will be shown
1903 int32_t getMaximumSignificantDigits() const;
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
1916 void setMinimumSignificantDigits(int32_t min
);
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
1929 void setMaximumSignificantDigits(int32_t max
);
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
1937 UBool
areSignificantDigitsUsed() const;
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
1946 void setSignificantDigitsUsed(UBool useSignificantDigits
);
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
1961 virtual void setCurrency(const UChar
* theCurrency
, UErrorCode
& ec
);
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&).
1968 virtual void setCurrency(const UChar
* theCurrency
);
1971 * Sets the <tt>Currency Context</tt> object used to display currency.
1972 * This takes effect immediately, if this format is a
1974 * @param currencyContext new currency context object to use.
1977 void setCurrencyUsage(UCurrencyUsage newUsage
, UErrorCode
* ec
);
1980 * Returns the <tt>Currency Context</tt> object used to display currency
1983 UCurrencyUsage
getCurrencyUsage() const;
1986 #ifndef U_HIDE_DEPRECATED_API
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.
1992 static const char fgNumberPatterns
[];
1993 #endif /* U_HIDE_DEPRECATED_API */
1995 #ifndef U_HIDE_INTERNAL_API
1997 * Get a FixedDecimal corresponding to a double as it would be
1998 * formatted by this DecimalFormat.
1999 * Internal, not intended for public use.
2002 FixedDecimal
getFixedDecimal(double number
, UErrorCode
&status
) const;
2005 * Get a FixedDecimal corresponding to a formattable as it would be
2006 * formatted by this DecimalFormat.
2007 * Internal, not intended for public use.
2010 FixedDecimal
getFixedDecimal(const Formattable
&number
, UErrorCode
&status
) const;
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.
2018 FixedDecimal
getFixedDecimal(DigitList
&number
, UErrorCode
&status
) const;
2021 * Get a VisibleDigitsWithExponent corresponding to a double
2022 * as it would be formatted by this DecimalFormat.
2023 * Internal, not intended for public use.
2026 VisibleDigitsWithExponent
&initVisibleDigitsWithExponent(
2028 VisibleDigitsWithExponent
&digits
,
2029 UErrorCode
&status
) const;
2032 * Get a VisibleDigitsWithExponent corresponding to a formattable
2033 * as it would be formatted by this DecimalFormat.
2034 * Internal, not intended for public use.
2037 VisibleDigitsWithExponent
&initVisibleDigitsWithExponent(
2038 const Formattable
&number
,
2039 VisibleDigitsWithExponent
&digits
,
2040 UErrorCode
&status
) const;
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.
2049 VisibleDigitsWithExponent
&initVisibleDigitsWithExponent(
2051 VisibleDigitsWithExponent
&digits
,
2052 UErrorCode
&status
) const;
2054 #endif /* U_HIDE_INTERNAL_API */
2059 * Return the class ID for this class. This is useful only for
2060 * comparing to a return value from getDynamicClassID(). For example:
2062 * . Base* polymorphic_pointer = createPolymorphicObject();
2063 * . if (polymorphic_pointer->getDynamicClassID() ==
2064 * . Derived::getStaticClassID()) ...
2066 * @return The class ID for all objects of this class.
2069 static UClassID U_EXPORT2
getStaticClassID(void);
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.
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.
2082 virtual UClassID
getDynamicClassID(void) const;
2086 DecimalFormat(); // default constructor not implemented
2089 * Initialize all fields of a new DecimalFormatter to a safe default value.
2090 * Common code for use by constructors.
2095 * Do real work of constructing a new DecimalFormat.
2097 void construct(UErrorCode
& status
,
2098 UParseError
& parseErr
,
2099 const UnicodeString
* pattern
= 0,
2100 DecimalFormatSymbols
* symbolsToAdopt
= 0
2103 void handleCurrencySignInPattern(UErrorCode
& status
);
2105 void parse(const UnicodeString
& text
,
2106 Formattable
& result
,
2108 UChar
* currency
) const;
2112 fgStatusLength
// Leave last in list.
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
,
2122 ParsePosition
& parsePosition
,
2123 DigitList
& digits
, UBool
* status
,
2124 UChar
* currency
) const;
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
,
2135 UChar
* currency
) const;
2137 int32_t skipPadding(const UnicodeString
& text
, int32_t position
) const;
2139 int32_t compareAffix(const UnicodeString
& input
,
2143 const UnicodeString
* affixPat
,
2144 UBool complexCurrencyParsing
,
2146 UChar
* currency
) const;
2148 static UnicodeString
& trimMarksFromAffix(const UnicodeString
& affix
, UnicodeString
& trimmedAffix
);
2150 UBool
equalWithSignCompatibility(UChar32 lhs
, UChar32 rhs
) const;
2152 int32_t compareSimpleAffix(const UnicodeString
& affix
,
2153 const UnicodeString
& input
,
2155 UBool lenient
) const;
2157 static int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
);
2159 static int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
);
2161 static int32_t skipUWhiteSpaceAndMarks(const UnicodeString
& text
, int32_t pos
);
2163 static int32_t skipBidiMarks(const UnicodeString
& text
, int32_t pos
);
2165 int32_t compareComplexAffix(const UnicodeString
& affixPat
,
2166 const UnicodeString
& input
,
2169 UChar
* currency
) const;
2171 static int32_t match(const UnicodeString
& text
, int32_t pos
, UChar32 ch
);
2173 static int32_t match(const UnicodeString
& text
, int32_t pos
, const UnicodeString
& str
);
2175 static UBool
matchSymbol(const UnicodeString
&text
, int32_t position
, int32_t length
, const UnicodeString
&symbol
,
2176 UnicodeSet
*sset
, UChar32 schar
);
2178 static UBool
matchDecimal(UChar32 symbolChar
,
2179 UBool sawDecimal
, UChar32 sawDecimalChar
,
2180 const UnicodeSet
*sset
, UChar32 schar
);
2182 static UBool
matchGrouping(UChar32 groupingChar
,
2183 UBool sawGrouping
, UChar32 sawGroupingChar
,
2184 const UnicodeSet
*sset
,
2185 UChar32 decimalChar
, const UnicodeSet
*decimalSet
,
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
);
2194 // get the currency rounding with respect to currency usage
2195 double getCurrencyRounding(const UChar
* currency
,
2196 UErrorCode
* ec
) const;
2198 // get the currency fraction with respect to currency usage
2199 int getCurrencyFractionDigits(const UChar
* currency
,
2200 UErrorCode
* ec
) const;
2202 // hashtable operations
2203 Hashtable
* initHashForAffixPattern(UErrorCode
& status
);
2205 void deleteHashForAffixPattern();
2207 void copyHashForAffixPattern(const Hashtable
* source
,
2208 Hashtable
* target
, UErrorCode
& status
);
2210 DecimalFormatImpl
*fImpl
;
2217 EnumSet
<UNumberFormatAttribute
,
2218 UNUM_MAX_NONBOOLEAN_ATTRIBUTE
+1,
2219 UNUM_LIMIT_BOOLEAN_ATTRIBUTE
>
2223 // style is only valid when decimal formatter is constructed by
2224 // DecimalFormat(pattern, decimalFormatSymbol, style)
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
;
2243 // Information needed for DecimalFormat to format/parse currency plural.
2244 CurrencyPluralInfo
* fCurrencyPluralInfo
;
2246 #if UCONFIG_HAVE_PARSEALLINPUT
2247 UNumberFormatAttributeValue fParseAllInput
;
2250 // Decimal Format Static Sets singleton.
2251 const DecimalFormatStaticSets
*fStaticSets
;
2255 #ifndef U_HIDE_INTERNAL_API
2257 * Rounds a value according to the rules of this object.
2260 DigitList
& _round(const DigitList
& number
, DigitList
& adjustedNum
, UBool
& isNegative
, UErrorCode
& status
) const;
2261 #endif /* U_HIDE_INTERNAL_API */
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
2271 virtual void getEffectiveCurrency(UChar
* result
, UErrorCode
& ec
) const;
2273 /** number of integer digits
2276 static const int32_t kDoubleIntegerDigits
;
2277 /** number of fraction digits
2280 static const int32_t kDoubleFractionDigits
;
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.
2292 static const int32_t kMaxScientificIntegerDigits
;
2298 #endif /* #if !UCONFIG_NO_FORMATTING */