2 ********************************************************************************
3 * Copyright (C) 1997-2012, 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 ********************************************************************************
27 #include "unicode/utypes.h"
30 * \brief C++ API: Formats decimal numbers.
33 #if !UCONFIG_NO_FORMATTING
35 #include "unicode/dcfmtsym.h"
36 #include "unicode/numfmt.h"
37 #include "unicode/locid.h"
38 #include "unicode/fpositer.h"
39 #include "unicode/stringpiece.h"
40 #include "unicode/curramt.h"
46 class CurrencyPluralInfo
;
49 class FieldPositionHandler
;
52 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal
53 * numbers. It has a variety of features designed to make it possible to parse
54 * and format numbers in any locale, including support for Western, Arabic, or
55 * Indic digits. It also supports different flavors of numbers, including
56 * integers ("123"), fixed-point numbers ("123.4"), scientific notation
57 * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123",
58 * "123 US dollars"). All of these flavors can be easily localized.
60 * <p>To obtain a NumberFormat for a specific locale (including the default
61 * locale) call one of NumberFormat's factory methods such as
62 * createInstance(). Do not call the DecimalFormat constructors directly, unless
63 * you know what you are doing, since the NumberFormat factory methods may
64 * return subclasses other than DecimalFormat.
66 * <p><strong>Example Usage</strong>
69 * // Normally we would have a GUI with a menu for this
71 * const Locale* locales = NumberFormat::getAvailableLocales(locCount);
73 * double myNumber = -1234.56;
74 * UErrorCode success = U_ZERO_ERROR;
77 * // Print out a number with the localized number, currency and percent
78 * // format for each locale.
79 * UnicodeString countryName;
80 * UnicodeString displayName;
82 * UnicodeString pattern;
83 * Formattable fmtable;
84 * for (int32_t j = 0; j < 3; ++j) {
85 * cout << endl << "FORMAT " << j << endl;
86 * for (int32_t i = 0; i < locCount; ++i) {
87 * if (locales[i].getCountry(countryName).size() == 0) {
88 * // skip language-only
93 * form = NumberFormat::createInstance(locales[i], success ); break;
95 * form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
97 * form = NumberFormat::createPercentInstance(locales[i], success ); break;
101 * pattern = ((DecimalFormat*)form)->toPattern(pattern);
102 * cout << locales[i].getDisplayName(displayName) << ": " << pattern;
103 * cout << " -> " << form->format(myNumber,str) << endl;
104 * form->parse(form->format(myNumber,str), fmtable, success);
111 * Another example use createInstance(style)
114 * <strong>// Print out a number using the localized number, currency,
115 * // percent, scientific, integer, iso currency, and plural currency
116 * // format for each locale</strong>
117 * Locale* locale = new Locale("en", "US");
118 * double myNumber = 1234.56;
119 * UErrorCode success = U_ZERO_ERROR;
121 * Formattable fmtable;
122 * for (int j=NumberFormat::kNumberStyle;
123 * j<=NumberFormat::kPluralCurrencyStyle;
125 * NumberFormat* format = NumberFormat::createInstance(locale, j, success);
127 * cout << "format result " << form->format(myNumber, str) << endl;
128 * format->parse(form->format(myNumber, str), fmtable, success);
132 * <p><strong>Patterns</strong>
134 * <p>A DecimalFormat consists of a <em>pattern</em> and a set of
135 * <em>symbols</em>. The pattern may be set directly using
136 * applyPattern(), or indirectly using other API methods which
137 * manipulate aspects of the pattern, such as the minimum number of integer
138 * digits. The symbols are stored in a DecimalFormatSymbols
139 * object. When using the NumberFormat factory methods, the
140 * pattern and symbols are read from ICU's locale data.
142 * <p><strong>Special Pattern Characters</strong>
144 * <p>Many characters in a pattern are taken literally; they are matched during
145 * parsing and output unchanged during formatting. Special characters, on the
146 * other hand, stand for other characters, strings, or classes of characters.
147 * For example, the '#' character is replaced by a localized digit. Often the
148 * replacement character is the same as the pattern character; in the U.S. locale,
149 * the ',' grouping character is replaced by ','. However, the replacement is
150 * still happening, and if the symbols are modified, the grouping character
151 * changes. Some special characters affect the behavior of the formatter by
152 * their presence; for example, if the percent character is seen, then the
153 * value is multiplied by 100 before being displayed.
155 * <p>To insert a special character in a pattern as a literal, that is, without
156 * any special meaning, the character must be quoted. There are some exceptions to
157 * this which are noted below.
159 * <p>The characters listed here are used in non-localized patterns. Localized
160 * patterns use the corresponding characters taken from this formatter's
161 * DecimalFormatSymbols object instead, and these characters lose
162 * their special status. Two exceptions are the currency sign and quote, which
165 * <table border=0 cellspacing=3 cellpadding=0>
166 * <tr bgcolor="#ccccff">
167 * <td align=left><strong>Symbol</strong>
168 * <td align=left><strong>Location</strong>
169 * <td align=left><strong>Localized?</strong>
170 * <td align=left><strong>Meaning</strong>
176 * <tr valign=top bgcolor="#eeeeff">
177 * <td><code>1-9</code>
180 * <td>'1' through '9' indicate rounding.
182 * <td><code>\htmlonly@\endhtmlonly</code> <!--doxygen doesn't like @-->
185 * <td>Significant digit
186 * <tr valign=top bgcolor="#eeeeff">
190 * <td>Digit, zero shows as absent
195 * <td>Decimal separator or monetary decimal separator
196 * <tr valign=top bgcolor="#eeeeff">
205 * <td>Grouping separator
206 * <tr valign=top bgcolor="#eeeeff">
210 * <td>Separates mantissa and exponent in scientific notation.
211 * <em>Need not be quoted in prefix or suffix.</em>
216 * <td>Prefix positive exponents with localized plus sign.
217 * <em>Need not be quoted in prefix or suffix.</em>
218 * <tr valign=top bgcolor="#eeeeff">
220 * <td>Subpattern boundary
222 * <td>Separates positive and negative subpatterns
224 * <td><code>\%</code>
225 * <td>Prefix or suffix
227 * <td>Multiply by 100 and show as percentage
228 * <tr valign=top bgcolor="#eeeeff">
229 * <td><code>\\u2030</code>
230 * <td>Prefix or suffix
232 * <td>Multiply by 1000 and show as per mille
234 * <td><code>\htmlonly¤\endhtmlonly</code> (<code>\\u00A4</code>)
235 * <td>Prefix or suffix
237 * <td>Currency sign, replaced by currency symbol. If
238 * doubled, replaced by international currency symbol.
239 * If tripled, replaced by currency plural names, for example,
240 * "US dollar" or "US dollars" for America.
241 * If present in a pattern, the monetary decimal separator
242 * is used instead of the decimal separator.
243 * <tr valign=top bgcolor="#eeeeff">
245 * <td>Prefix or suffix
247 * <td>Used to quote special characters in a prefix or suffix,
248 * for example, <code>"'#'#"</code> formats 123 to
249 * <code>"#123"</code>. To create a single quote
250 * itself, use two in a row: <code>"# o''clock"</code>.
253 * <td>Prefix or suffix boundary
255 * <td>Pad escape, precedes pad character
258 * <p>A DecimalFormat pattern contains a postive and negative
259 * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a
260 * prefix, a numeric part, and a suffix. If there is no explicit negative
261 * subpattern, the negative subpattern is the localized minus sign prefixed to the
262 * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there
263 * is an explicit negative subpattern, it serves only to specify the negative
264 * prefix and suffix; the number of digits, minimal digits, and other
265 * characteristics are ignored in the negative subpattern. That means that
266 * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
268 * <p>The prefixes, suffixes, and various symbols used for infinity, digits,
269 * thousands separators, decimal separators, etc. may be set to arbitrary
270 * values, and they will appear properly during formatting. However, care must
271 * be taken that the symbols and strings do not conflict, or parsing will be
272 * unreliable. For example, either the positive and negative prefixes or the
273 * suffixes must be distinct for parse() to be able
274 * to distinguish positive from negative values. Another example is that the
275 * decimal separator and thousands separator should be distinct characters, or
276 * parsing will be impossible.
278 * <p>The <em>grouping separator</em> is a character that separates clusters of
279 * integer digits to make large numbers more legible. It commonly used for
280 * thousands, but in some locales it separates ten-thousands. The <em>grouping
281 * size</em> is the number of digits between the grouping separators, such as 3
282 * for "100,000,000" or 4 for "1 0000 0000". There are actually two different
283 * grouping sizes: One used for the least significant integer digits, the
284 * <em>primary grouping size</em>, and one used for all others, the
285 * <em>secondary grouping size</em>. In most locales these are the same, but
286 * sometimes they are different. For example, if the primary grouping interval
287 * is 3, and the secondary is 2, then this corresponds to the pattern
288 * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a
289 * pattern contains multiple grouping separators, the interval between the last
290 * one and the end of the integer defines the primary grouping size, and the
291 * interval between the last two defines the secondary grouping size. All others
292 * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
294 * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
295 * DecimalFormat to set a failing UErrorCode.
297 * <p><strong>Pattern BNF</strong>
300 * pattern := subpattern (';' subpattern)?
301 * subpattern := prefix? number exponent? suffix?
302 * number := (integer ('.' fraction)?) | sigDigits
303 * prefix := '\\u0000'..'\\uFFFD' - specialCharacters
304 * suffix := '\\u0000'..'\\uFFFD' - specialCharacters
305 * integer := '#'* '0'* '0'
306 * fraction := '0'* '#'*
307 * sigDigits := '#'* '@' '@'* '#'*
308 * exponent := 'E' '+'? '0'* '0'
309 * padSpec := '*' padChar
310 * padChar := '\\u0000'..'\\uFFFD' - quote
313 * X* 0 or more instances of X
314 * X? 0 or 1 instances of X
316 * C..D any character from C up to D, inclusive
317 * S-T characters in S, except those in T
319 * The first subpattern is for positive numbers. The second (optional)
320 * subpattern is for negative numbers.
322 * <p>Not indicated in the BNF syntax above:
324 * <ul><li>The grouping separator ',' can occur inside the integer and
325 * sigDigits elements, between any two pattern characters of that
326 * element, as long as the integer or sigDigits element is not
327 * followed by the exponent element.
329 * <li>Two grouping intervals are recognized: That between the
330 * decimal point and the first grouping symbol, and that
331 * between the first and second grouping symbols. These
332 * intervals are identical in most locales, but in some
333 * locales they differ. For example, the pattern
334 * "#,##,###" formats the number 123456789 as
335 * "12,34,56,789".</li>
337 * <li>The pad specifier <code>padSpec</code> may appear before the prefix,
338 * after the prefix, before the suffix, after the suffix, or not at all.
340 * <li>In place of '0', the digits '1' through '9' may be used to
341 * indicate a rounding increment.
344 * <p><strong>Parsing</strong>
346 * <p>DecimalFormat parses all Unicode characters that represent
347 * decimal digits, as defined by u_charDigitValue(). In addition,
348 * DecimalFormat also recognizes as digits the ten consecutive
349 * characters starting with the localized zero digit defined in the
350 * DecimalFormatSymbols object. During formatting, the
351 * DecimalFormatSymbols-based digits are output.
353 * <p>During parsing, grouping separators are ignored.
355 * <p>For currency parsing, the formatter is able to parse every currency
356 * style formats no matter which style the formatter is constructed with.
357 * For example, a formatter instance gotten from
358 * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse
359 * formats such as "USD1.00" and "3.00 US dollars".
361 * <p>If parse(UnicodeString&,Formattable&,ParsePosition&)
362 * fails to parse a string, it leaves the parse position unchanged.
363 * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&)
364 * indicates parse failure by setting a failing
367 * <p><strong>Formatting</strong>
369 * <p>Formatting is guided by several parameters, all of which can be
370 * specified either using a pattern or using the API. The following
371 * description applies to formats that do not use <a href="#sci">scientific
372 * notation</a> or <a href="#sigdig">significant digits</a>.
374 * <ul><li>If the number of actual integer digits exceeds the
375 * <em>maximum integer digits</em>, then only the least significant
376 * digits are shown. For example, 1997 is formatted as "97" if the
377 * maximum integer digits is set to 2.
379 * <li>If the number of actual integer digits is less than the
380 * <em>minimum integer digits</em>, then leading zeros are added. For
381 * example, 1997 is formatted as "01997" if the minimum integer digits
384 * <li>If the number of actual fraction digits exceeds the <em>maximum
385 * fraction digits</em>, then rounding is performed to the
386 * maximum fraction digits. For example, 0.125 is formatted as "0.12"
387 * if the maximum fraction digits is 2. This behavior can be changed
388 * by specifying a rounding increment and/or a rounding mode.
390 * <li>If the number of actual fraction digits is less than the
391 * <em>minimum fraction digits</em>, then trailing zeros are added.
392 * For example, 0.125 is formatted as "0.1250" if the mimimum fraction
393 * digits is set to 4.
395 * <li>Trailing fractional zeros are not displayed if they occur
396 * <em>j</em> positions after the decimal, where <em>j</em> is less
397 * than the maximum fraction digits. For example, 0.10004 is
398 * formatted as "0.1" if the maximum fraction digits is four or less.
401 * <p><strong>Special Values</strong>
403 * <p><code>NaN</code> is represented as a single character, typically
404 * <code>\\uFFFD</code>. This character is determined by the
405 * DecimalFormatSymbols object. This is the only value for which
406 * the prefixes and suffixes are not used.
408 * <p>Infinity is represented as a single character, typically
409 * <code>\\u221E</code>, with the positive or negative prefixes and suffixes
410 * applied. The infinity character is determined by the
411 * DecimalFormatSymbols object.
413 * <a name="sci"><strong>Scientific Notation</strong></a>
415 * <p>Numbers in scientific notation are expressed as the product of a mantissa
416 * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The
417 * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0),
418 * but it need not be. DecimalFormat supports arbitrary mantissas.
419 * DecimalFormat can be instructed to use scientific
420 * notation through the API or through the pattern. In a pattern, the exponent
421 * character immediately followed by one or more digit characters indicates
422 * scientific notation. Example: "0.###E0" formats the number 1234 as
426 * <li>The number of digit characters after the exponent character gives the
427 * minimum exponent digit count. There is no maximum. Negative exponents are
428 * formatted using the localized minus sign, <em>not</em> the prefix and suffix
429 * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix
430 * positive exponents with a localized plus sign, specify '+' between the
431 * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0",
432 * "1E-1", etc. (In localized patterns, use the localized plus sign rather than
435 * <li>The minimum number of integer digits is achieved by adjusting the
436 * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This
437 * only happens if there is no maximum number of integer digits. If there is a
438 * maximum, then the minimum number of integer digits is fixed at one.
440 * <li>The maximum number of integer digits, if present, specifies the exponent
441 * grouping. The most common use of this is to generate <em>engineering
442 * notation</em>, in which the exponent is a multiple of three, e.g.,
443 * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3".
445 * <li>When using scientific notation, the formatter controls the
446 * digit counts using significant digits logic. The maximum number of
447 * significant digits limits the total number of integer and fraction
448 * digits that will be shown in the mantissa; it does not affect
449 * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3".
450 * See the section on significant digits for more details.
452 * <li>The number of significant digits shown is determined as
453 * follows: If areSignificantDigitsUsed() returns false, then the
454 * minimum number of significant digits shown is one, and the maximum
455 * number of significant digits shown is the sum of the <em>minimum
456 * integer</em> and <em>maximum fraction</em> digits, and is
457 * unaffected by the maximum integer digits. If this sum is zero,
458 * then all significant digits are shown. If
459 * areSignificantDigitsUsed() returns true, then the significant digit
460 * counts are specified by getMinimumSignificantDigits() and
461 * getMaximumSignificantDigits(). In this case, the number of
462 * integer digits is fixed at one, and there is no exponent grouping.
464 * <li>Exponential patterns may not contain grouping separators.
467 * <a name="sigdig"><strong>Significant Digits</strong></a>
469 * <code>DecimalFormat</code> has two ways of controlling how many
470 * digits are shows: (a) significant digits counts, or (b) integer and
471 * fraction digit counts. Integer and fraction digit counts are
472 * described above. When a formatter is using significant digits
473 * counts, the number of integer and fraction digits is not specified
474 * directly, and the formatter settings for these counts are ignored.
475 * Instead, the formatter uses however many integer and fraction
476 * digits are required to display the specified number of significant
479 * <table border=0 cellspacing=3 cellpadding=0>
480 * <tr bgcolor="#ccccff">
481 * <td align=left>Pattern
482 * <td align=left>Minimum significant digits
483 * <td align=left>Maximum significant digits
484 * <td align=left>Number
485 * <td align=left>Output of format()
487 * <td><code>\@\@\@</code>
491 * <td><code>12300</code>
492 * <tr valign=top bgcolor="#eeeeff">
493 * <td><code>\@\@\@</code>
497 * <td><code>0.123</code>
499 * <td><code>\@\@##</code>
503 * <td><code>3.142</code>
504 * <tr valign=top bgcolor="#eeeeff">
505 * <td><code>\@\@##</code>
509 * <td><code>1.23</code>
513 * <li>Significant digit counts may be expressed using patterns that
514 * specify a minimum and maximum number of significant digits. These
515 * are indicated by the <code>'@'</code> and <code>'#'</code>
516 * characters. The minimum number of significant digits is the number
517 * of <code>'@'</code> characters. The maximum number of significant
518 * digits is the number of <code>'@'</code> characters plus the number
519 * of <code>'#'</code> characters following on the right. For
520 * example, the pattern <code>"@@@"</code> indicates exactly 3
521 * significant digits. The pattern <code>"@##"</code> indicates from
522 * 1 to 3 significant digits. Trailing zero digits to the right of
523 * the decimal separator are suppressed after the minimum number of
524 * significant digits have been shown. For example, the pattern
525 * <code>"@##"</code> formats the number 0.1203 as
526 * <code>"0.12"</code>.
528 * <li>If a pattern uses significant digits, it may not contain a
529 * decimal separator, nor the <code>'0'</code> pattern character.
530 * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are
533 * <li>Any number of <code>'#'</code> characters may be prepended to
534 * the left of the leftmost <code>'@'</code> character. These have no
535 * effect on the minimum and maximum significant digits counts, but
536 * may be used to position grouping separators. For example,
537 * <code>"#,#@#"</code> indicates a minimum of one significant digits,
538 * a maximum of two significant digits, and a grouping size of three.
540 * <li>In order to enable significant digits formatting, use a pattern
541 * containing the <code>'@'</code> pattern character. Alternatively,
542 * call setSignificantDigitsUsed(TRUE).
544 * <li>In order to disable significant digits formatting, use a
545 * pattern that does not contain the <code>'@'</code> pattern
546 * character. Alternatively, call setSignificantDigitsUsed(FALSE).
548 * <li>The number of significant digits has no effect on parsing.
550 * <li>Significant digits may be used together with exponential notation. Such
551 * patterns are equivalent to a normal exponential pattern with a minimum and
552 * maximum integer digit count of one, a minimum fraction digit count of
553 * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit
554 * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the
555 * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>.
557 * <li>If signficant digits are in use, then the integer and fraction
558 * digit counts, as set via the API, are ignored. If significant
559 * digits are not in use, then the signficant digit counts, as set via
560 * the API, are ignored.
564 * <p><strong>Padding</strong>
566 * <p>DecimalFormat supports padding the result of
567 * format() to a specific width. Padding may be specified either
568 * through the API or through the pattern syntax. In a pattern the pad escape
569 * character, followed by a single pad character, causes padding to be parsed
570 * and formatted. The pad escape character is '*' in unlocalized patterns, and
571 * can be localized using DecimalFormatSymbols::setSymbol() with a
572 * DecimalFormatSymbols::kPadEscapeSymbol
573 * selector. For example, <code>"$*x#,##0.00"</code> formats 123 to
574 * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>.
577 * <li>When padding is in effect, the width of the positive subpattern,
578 * including prefix and suffix, determines the format width. For example, in
579 * the pattern <code>"* #0 o''clock"</code>, the format width is 10.
581 * <li>The width is counted in 16-bit code units (UChars).
583 * <li>Some parameters which usually do not matter have meaning when padding is
584 * used, because the pattern width is significant with padding. In the pattern
585 * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##,"
586 * do not affect the grouping size or maximum integer digits, but they do affect
589 * <li>Padding may be inserted at one of four locations: before the prefix,
590 * after the prefix, before the suffix, or after the suffix. If padding is
591 * specified in any other location, applyPattern()
592 * sets a failing UErrorCode. If there is no prefix,
593 * before the prefix and after the prefix are equivalent, likewise for the
596 * <li>When specified in a pattern, the 32-bit code point immediately
597 * following the pad escape is the pad character. This may be any character,
598 * including a special pattern character. That is, the pad escape
599 * <em>escapes</em> the following character. If there is no character after
600 * the pad escape, then the pattern is illegal.
604 * <p><strong>Rounding</strong>
606 * <p>DecimalFormat supports rounding to a specific increment. For
607 * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the
608 * nearest 0.65 is 1.3. The rounding increment may be specified through the API
609 * or in a pattern. To specify a rounding increment in a pattern, include the
610 * increment in the pattern itself. "#,#50" specifies a rounding increment of
611 * 50. "#,##0.05" specifies a rounding increment of 0.05.
613 * <p>In the absense of an explicit rounding increment numbers are
614 * rounded to their formatted width.
617 * <li>Rounding only affects the string produced by formatting. It does
618 * not affect parsing or change any numerical values.
620 * <li>A <em>rounding mode</em> determines how values are rounded; see
621 * DecimalFormat::ERoundingMode. The default rounding mode is
622 * DecimalFormat::kRoundHalfEven. The rounding mode can only be set
623 * through the API; it can not be set with a pattern.
625 * <li>Some locales use rounding in their currency formats to reflect the
626 * smallest currency denomination.
628 * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
629 * behave identically to digit '0'.
632 * <p><strong>Synchronization</strong>
634 * <p>DecimalFormat objects are not synchronized. Multiple
635 * threads should not access one formatter concurrently.
637 * <p><strong>Subclassing</strong>
639 * <p><em>User subclasses are not supported.</em> While clients may write
640 * subclasses, such code will not necessarily work and will not be
641 * guaranteed to work stably from release to release.
643 class U_I18N_API DecimalFormat
: public NumberFormat
{
650 kRoundCeiling
, /**< Round towards positive infinity */
651 kRoundFloor
, /**< Round towards negative infinity */
652 kRoundDown
, /**< Round towards zero */
653 kRoundUp
, /**< Round away from zero */
654 kRoundHalfEven
, /**< Round towards the nearest integer, or
655 towards the nearest even integer if equidistant */
656 kRoundHalfDown
, /**< Round towards the nearest integer, or
657 towards zero if equidistant */
658 kRoundHalfUp
, /**< Round towards the nearest integer, or
659 away from zero if equidistant */
661 * Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
679 * Create a DecimalFormat using the default pattern and symbols
680 * for the default locale. This is a convenient way to obtain a
681 * DecimalFormat when internationalization is not the main concern.
683 * To obtain standard formats for a given locale, use the factory methods
684 * on NumberFormat such as createInstance. These factories will
685 * return the most appropriate sub-class of NumberFormat for a given
687 * @param status Output param set to success/failure code. If the
688 * pattern is invalid this will be set to a failure code.
691 DecimalFormat(UErrorCode
& status
);
694 * Create a DecimalFormat from the given pattern and the symbols
695 * for the default locale. This is a convenient way to obtain a
696 * DecimalFormat when internationalization is not the main concern.
698 * To obtain standard formats for a given locale, use the factory methods
699 * on NumberFormat such as createInstance. These factories will
700 * return the most appropriate sub-class of NumberFormat for a given
702 * @param pattern A non-localized pattern string.
703 * @param status Output param set to success/failure code. If the
704 * pattern is invalid this will be set to a failure code.
707 DecimalFormat(const UnicodeString
& pattern
,
711 * Create a DecimalFormat from the given pattern and symbols.
712 * Use this constructor when you need to completely customize the
713 * behavior of the format.
715 * To obtain standard formats for a given
716 * locale, use the factory methods on NumberFormat such as
717 * createInstance or createCurrencyInstance. If you need only minor adjustments
718 * to a standard format, you can modify the format returned by
719 * a NumberFormat factory method.
721 * @param pattern a non-localized pattern string
722 * @param symbolsToAdopt the set of symbols to be used. The caller should not
723 * delete this object after making this call.
724 * @param status Output param set to success/failure code. If the
725 * pattern is invalid this will be set to a failure code.
728 DecimalFormat( const UnicodeString
& pattern
,
729 DecimalFormatSymbols
* symbolsToAdopt
,
732 #ifndef U_HIDE_INTERNAL_API
734 * This API is for ICU use only.
735 * Create a DecimalFormat from the given pattern, symbols, and style.
737 * @param pattern a non-localized pattern string
738 * @param symbolsToAdopt the set of symbols to be used. The caller should not
739 * delete this object after making this call.
740 * @param style style of decimal format
741 * @param status Output param set to success/failure code. If the
742 * pattern is invalid this will be set to a failure code.
745 DecimalFormat( const UnicodeString
& pattern
,
746 DecimalFormatSymbols
* symbolsToAdopt
,
747 UNumberFormatStyle style
,
749 #endif /* U_HIDE_INTERNAL_API */
752 * Create a DecimalFormat from the given pattern and symbols.
753 * Use this constructor when you need to completely customize the
754 * behavior of the format.
756 * To obtain standard formats for a given
757 * locale, use the factory methods on NumberFormat such as
758 * createInstance or createCurrencyInstance. If you need only minor adjustments
759 * to a standard format, you can modify the format returned by
760 * a NumberFormat factory method.
762 * @param pattern a non-localized pattern string
763 * @param symbolsToAdopt the set of symbols to be used. The caller should not
764 * delete this object after making this call.
765 * @param parseError Output param to receive errors occured during parsing
766 * @param status Output param set to success/failure code. If the
767 * pattern is invalid this will be set to a failure code.
770 DecimalFormat( const UnicodeString
& pattern
,
771 DecimalFormatSymbols
* symbolsToAdopt
,
772 UParseError
& parseError
,
775 * Create a DecimalFormat from the given pattern and symbols.
776 * Use this constructor when you need to completely customize the
777 * behavior of the format.
779 * To obtain standard formats for a given
780 * locale, use the factory methods on NumberFormat such as
781 * createInstance or createCurrencyInstance. If you need only minor adjustments
782 * to a standard format, you can modify the format returned by
783 * a NumberFormat factory method.
785 * @param pattern a non-localized pattern string
786 * @param symbols the set of symbols to be used
787 * @param status Output param set to success/failure code. If the
788 * pattern is invalid this will be set to a failure code.
791 DecimalFormat( const UnicodeString
& pattern
,
792 const DecimalFormatSymbols
& symbols
,
798 * @param source the DecimalFormat object to be copied from.
801 DecimalFormat(const DecimalFormat
& source
);
804 * Assignment operator.
806 * @param rhs the DecimalFormat object to be copied.
809 DecimalFormat
& operator=(const DecimalFormat
& rhs
);
815 virtual ~DecimalFormat();
818 * Clone this Format object polymorphically. The caller owns the
819 * result and should delete it when done.
821 * @return a polymorphic copy of this DecimalFormat.
824 virtual Format
* clone(void) const;
827 * Return true if the given Format objects are semantically equal.
828 * Objects of different subclasses are considered unequal.
830 * @param other the object to be compared with.
831 * @return true if the given Format objects are semantically equal.
834 virtual UBool
operator==(const Format
& other
) const;
837 using NumberFormat::format
;
840 * Format a double or long number using base-10 representation.
842 * @param number The value to be formatted.
843 * @param appendTo Output parameter to receive result.
844 * Result is appended to existing contents.
845 * @param pos On input: an alignment field, if desired.
846 * On output: the offsets of the alignment field.
847 * @return Reference to 'appendTo' parameter.
850 virtual UnicodeString
& format(double number
,
851 UnicodeString
& appendTo
,
852 FieldPosition
& pos
) const;
855 * Format a double or long number using base-10 representation.
857 * @param number The value to be formatted.
858 * @param appendTo Output parameter to receive result.
859 * Result is appended to existing contents.
860 * @param posIter On return, can be used to iterate over positions
861 * of fields generated by this format call.
863 * @param status Output param filled with success/failure status.
864 * @return Reference to 'appendTo' parameter.
867 virtual UnicodeString
& format(double number
,
868 UnicodeString
& appendTo
,
869 FieldPositionIterator
* posIter
,
870 UErrorCode
& status
) const;
873 * Format a long number using base-10 representation.
875 * @param number The value to be formatted.
876 * @param appendTo Output parameter to receive result.
877 * Result is appended to existing contents.
878 * @param pos On input: an alignment field, if desired.
879 * On output: the offsets of the alignment field.
880 * @return Reference to 'appendTo' parameter.
883 virtual UnicodeString
& format(int32_t number
,
884 UnicodeString
& appendTo
,
885 FieldPosition
& pos
) const;
888 * Format a long number using base-10 representation.
890 * @param number The value to be formatted.
891 * @param appendTo Output parameter to receive result.
892 * Result is appended to existing contents.
893 * @param posIter On return, can be used to iterate over positions
894 * of fields generated by this format call.
896 * @param status Output param filled with success/failure status.
897 * @return Reference to 'appendTo' parameter.
900 virtual UnicodeString
& format(int32_t number
,
901 UnicodeString
& appendTo
,
902 FieldPositionIterator
* posIter
,
903 UErrorCode
& status
) const;
906 * Format an int64 number using base-10 representation.
908 * @param number The value to be formatted.
909 * @param appendTo Output parameter to receive result.
910 * Result is appended to existing contents.
911 * @param pos On input: an alignment field, if desired.
912 * On output: the offsets of the alignment field.
913 * @return Reference to 'appendTo' parameter.
916 virtual UnicodeString
& format(int64_t number
,
917 UnicodeString
& appendTo
,
918 FieldPosition
& pos
) const;
921 * Format an int64 number using base-10 representation.
923 * @param number The value to be formatted.
924 * @param appendTo Output parameter to receive result.
925 * Result is appended to existing contents.
926 * @param posIter On return, can be used to iterate over positions
927 * of fields generated by this format call.
929 * @param status Output param filled with success/failure status.
930 * @return Reference to 'appendTo' parameter.
933 virtual UnicodeString
& format(int64_t number
,
934 UnicodeString
& appendTo
,
935 FieldPositionIterator
* posIter
,
936 UErrorCode
& status
) const;
939 * Format a decimal number.
940 * The syntax of the unformatted number is a "numeric string"
941 * as defined in the Decimal Arithmetic Specification, available at
942 * http://speleotrove.com/decimal
944 * @param number The unformatted number, as a string.
945 * @param appendTo Output parameter to receive result.
946 * Result is appended to existing contents.
947 * @param posIter On return, can be used to iterate over positions
948 * of fields generated by this format call.
950 * @param status Output param filled with success/failure status.
951 * @return Reference to 'appendTo' parameter.
954 virtual UnicodeString
& format(const StringPiece
&number
,
955 UnicodeString
& appendTo
,
956 FieldPositionIterator
* posIter
,
957 UErrorCode
& status
) const;
961 * Format a decimal number.
962 * The number is a DigitList wrapper onto a floating point decimal number.
963 * The default implementation in NumberFormat converts the decimal number
964 * to a double and formats that.
966 * @param number The number, a DigitList format Decimal Floating Point.
967 * @param appendTo Output parameter to receive result.
968 * Result is appended to existing contents.
969 * @param posIter On return, can be used to iterate over positions
970 * of fields generated by this format call.
971 * @param status Output param filled with success/failure status.
972 * @return Reference to 'appendTo' parameter.
975 virtual UnicodeString
& format(const DigitList
&number
,
976 UnicodeString
& appendTo
,
977 FieldPositionIterator
* posIter
,
978 UErrorCode
& status
) const;
981 * Format a decimal number.
982 * The number is a DigitList wrapper onto a floating point decimal number.
983 * The default implementation in NumberFormat converts the decimal number
984 * to a double and formats that.
986 * @param number The number, a DigitList format Decimal Floating Point.
987 * @param appendTo Output parameter to receive result.
988 * Result is appended to existing contents.
989 * @param pos On input: an alignment field, if desired.
990 * On output: the offsets of the alignment field.
991 * @param status Output param filled with success/failure status.
992 * @return Reference to 'appendTo' parameter.
995 virtual UnicodeString
& format(const DigitList
&number
,
996 UnicodeString
& appendTo
,
998 UErrorCode
& status
) const;
1002 * Format a Formattable using base-10 representation.
1004 * @param obj The value to be formatted.
1005 * @param appendTo Output parameter to receive result.
1006 * Result is appended to existing contents.
1007 * @param pos On input: an alignment field, if desired.
1008 * On output: the offsets of the alignment field.
1009 * @param status Error code indicating success or failure.
1010 * @return Reference to 'appendTo' parameter.
1013 virtual UnicodeString
& format(const Formattable
& obj
,
1014 UnicodeString
& appendTo
,
1016 UErrorCode
& status
) const;
1019 * Redeclared NumberFormat method.
1020 * Formats an object to produce a string.
1022 * @param obj The object to format.
1023 * @param appendTo Output parameter to receive result.
1024 * Result is appended to existing contents.
1025 * @param status Output parameter filled in with success or failure status.
1026 * @return Reference to 'appendTo' parameter.
1029 UnicodeString
& format(const Formattable
& obj
,
1030 UnicodeString
& appendTo
,
1031 UErrorCode
& status
) const;
1034 * Redeclared NumberFormat method.
1035 * Format a double number.
1037 * @param number The value to be formatted.
1038 * @param appendTo Output parameter to receive result.
1039 * Result is appended to existing contents.
1040 * @return Reference to 'appendTo' parameter.
1043 UnicodeString
& format(double number
,
1044 UnicodeString
& appendTo
) const;
1047 * Redeclared NumberFormat method.
1048 * Format a long number. These methods call the NumberFormat
1049 * pure virtual format() methods with the default FieldPosition.
1051 * @param number The value to be formatted.
1052 * @param appendTo Output parameter to receive result.
1053 * Result is appended to existing contents.
1054 * @return Reference to 'appendTo' parameter.
1057 UnicodeString
& format(int32_t number
,
1058 UnicodeString
& appendTo
) const;
1061 * Redeclared NumberFormat method.
1062 * Format an int64 number. These methods call the NumberFormat
1063 * pure virtual format() methods with the default FieldPosition.
1065 * @param number The value to be formatted.
1066 * @param appendTo Output parameter to receive result.
1067 * Result is appended to existing contents.
1068 * @return Reference to 'appendTo' parameter.
1071 UnicodeString
& format(int64_t number
,
1072 UnicodeString
& appendTo
) const;
1074 * Parse the given string using this object's choices. The method
1075 * does string comparisons to try to find an optimal match.
1076 * If no object can be parsed, index is unchanged, and NULL is
1077 * returned. The result is returned as the most parsimonious
1078 * type of Formattable that will accomodate all of the
1079 * necessary precision. For example, if the result is exactly 12,
1080 * it will be returned as a long. However, if it is 1.5, it will
1081 * be returned as a double.
1083 * @param text The text to be parsed.
1084 * @param result Formattable to be set to the parse result.
1085 * If parse fails, return contents are undefined.
1086 * @param parsePosition The position to start parsing at on input.
1087 * On output, moved to after the last successfully
1088 * parse character. On parse failure, does not change.
1092 virtual void parse(const UnicodeString
& text
,
1093 Formattable
& result
,
1094 ParsePosition
& parsePosition
) const;
1096 // Declare here again to get rid of function hiding problems.
1098 * Parse the given string using this object's choices.
1100 * @param text The text to be parsed.
1101 * @param result Formattable to be set to the parse result.
1102 * @param status Output parameter filled in with success or failure status.
1105 virtual void parse(const UnicodeString
& text
,
1106 Formattable
& result
,
1107 UErrorCode
& status
) const;
1109 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
1111 * Parses text from the given string as a currency amount. Unlike
1112 * the parse() method, this method will attempt to parse a generic
1113 * currency name, searching for a match of this object's locale's
1114 * currency display names, or for a 3-letter ISO currency code.
1115 * This method will fail if this format is not a currency format,
1116 * that is, if it does not contain the currency pattern symbol
1117 * (U+00A4) in its prefix or suffix.
1119 * @param text the string to parse
1120 * @param pos input-output position; on input, the position within text
1121 * to match; must have 0 <= pos.getIndex() < text.length();
1122 * on output, the position after the last matched character.
1123 * If the parse fails, the position in unchanged upon output.
1124 * @return if parse succeeds, a pointer to a newly-created CurrencyAmount
1125 * object (owned by the caller) containing information about
1126 * the parsed currency; if parse fails, this is NULL.
1129 virtual CurrencyAmount
* parseCurrency(const UnicodeString
& text
,
1130 ParsePosition
& pos
) const;
1133 * Returns the decimal format symbols, which is generally not changed
1134 * by the programmer or user.
1135 * @return desired DecimalFormatSymbols
1136 * @see DecimalFormatSymbols
1139 virtual const DecimalFormatSymbols
* getDecimalFormatSymbols(void) const;
1142 * Sets the decimal format symbols, which is generally not changed
1143 * by the programmer or user.
1144 * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
1147 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols
* symbolsToAdopt
);
1150 * Sets the decimal format symbols, which is generally not changed
1151 * by the programmer or user.
1152 * @param symbols DecimalFormatSymbols.
1155 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols
& symbols
);
1159 * Returns the currency plural format information,
1160 * which is generally not changed by the programmer or user.
1161 * @return desired CurrencyPluralInfo
1164 virtual const CurrencyPluralInfo
* getCurrencyPluralInfo(void) const;
1167 * Sets the currency plural format information,
1168 * which is generally not changed by the programmer or user.
1169 * @param toAdopt CurrencyPluralInfo to be adopted.
1172 virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo
* toAdopt
);
1175 * Sets the currency plural format information,
1176 * which is generally not changed by the programmer or user.
1177 * @param info Currency Plural Info.
1180 virtual void setCurrencyPluralInfo(const CurrencyPluralInfo
& info
);
1184 * Get the positive prefix.
1186 * @param result Output param which will receive the positive prefix.
1187 * @return A reference to 'result'.
1188 * Examples: +123, $123, sFr123
1191 UnicodeString
& getPositivePrefix(UnicodeString
& result
) const;
1194 * Set the positive prefix.
1196 * @param newValue the new value of the the positive prefix to be set.
1197 * Examples: +123, $123, sFr123
1200 virtual void setPositivePrefix(const UnicodeString
& newValue
);
1203 * Get the negative prefix.
1205 * @param result Output param which will receive the negative prefix.
1206 * @return A reference to 'result'.
1207 * Examples: -123, ($123) (with negative suffix), sFr-123
1210 UnicodeString
& getNegativePrefix(UnicodeString
& result
) const;
1213 * Set the negative prefix.
1215 * @param newValue the new value of the the negative prefix to be set.
1216 * Examples: -123, ($123) (with negative suffix), sFr-123
1219 virtual void setNegativePrefix(const UnicodeString
& newValue
);
1222 * Get the positive suffix.
1224 * @param result Output param which will receive the positive suffix.
1225 * @return A reference to 'result'.
1229 UnicodeString
& getPositiveSuffix(UnicodeString
& result
) const;
1232 * Set the positive suffix.
1234 * @param newValue the new value of the positive suffix to be set.
1238 virtual void setPositiveSuffix(const UnicodeString
& newValue
);
1241 * Get the negative suffix.
1243 * @param result Output param which will receive the negative suffix.
1244 * @return A reference to 'result'.
1245 * Examples: -123%, ($123) (with positive suffixes)
1248 UnicodeString
& getNegativeSuffix(UnicodeString
& result
) const;
1251 * Set the negative suffix.
1253 * @param newValue the new value of the negative suffix to be set.
1257 virtual void setNegativeSuffix(const UnicodeString
& newValue
);
1260 * Get the multiplier for use in percent, permill, etc.
1261 * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1262 * (For Arabic, use arabic percent symbol).
1263 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1265 * @return the multiplier for use in percent, permill, etc.
1266 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1269 int32_t getMultiplier(void) const;
1272 * Set the multiplier for use in percent, permill, etc.
1273 * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1274 * (For Arabic, use arabic percent symbol).
1275 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1277 * @param newValue the new value of the multiplier for use in percent, permill, etc.
1278 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1281 virtual void setMultiplier(int32_t newValue
);
1284 * Get the rounding increment.
1285 * @return A positive rounding increment, or 0.0 if a rounding
1286 * increment is not in effect.
1287 * @see #setRoundingIncrement
1288 * @see #getRoundingMode
1289 * @see #setRoundingMode
1292 virtual double getRoundingIncrement(void) const;
1295 * Set the rounding increment. In the absence of a rounding increment,
1296 * numbers will be rounded to the number of digits displayed.
1297 * @param newValue A positive rounding increment.
1298 * Negative increments are equivalent to 0.0.
1299 * @see #getRoundingIncrement
1300 * @see #getRoundingMode
1301 * @see #setRoundingMode
1304 virtual void setRoundingIncrement(double newValue
);
1307 * Get the rounding mode.
1308 * @return A rounding mode
1309 * @see #setRoundingIncrement
1310 * @see #getRoundingIncrement
1311 * @see #setRoundingMode
1314 virtual ERoundingMode
getRoundingMode(void) const;
1317 * Set the rounding mode.
1318 * @param roundingMode A rounding mode
1319 * @see #setRoundingIncrement
1320 * @see #getRoundingIncrement
1321 * @see #getRoundingMode
1324 virtual void setRoundingMode(ERoundingMode roundingMode
);
1327 * Get the width to which the output of format() is padded.
1328 * The width is counted in 16-bit code units.
1329 * @return the format width, or zero if no padding is in effect
1330 * @see #setFormatWidth
1331 * @see #getPadCharacterString
1332 * @see #setPadCharacter
1333 * @see #getPadPosition
1334 * @see #setPadPosition
1337 virtual int32_t getFormatWidth(void) const;
1340 * Set the width to which the output of format() is padded.
1341 * The width is counted in 16-bit code units.
1342 * This method also controls whether padding is enabled.
1343 * @param width the width to which to pad the result of
1344 * format(), or zero to disable padding. A negative
1345 * width is equivalent to 0.
1346 * @see #getFormatWidth
1347 * @see #getPadCharacterString
1348 * @see #setPadCharacter
1349 * @see #getPadPosition
1350 * @see #setPadPosition
1353 virtual void setFormatWidth(int32_t width
);
1356 * Get the pad character used to pad to the format width. The
1358 * @return a string containing the pad character. This will always
1359 * have a length of one 32-bit code point.
1360 * @see #setFormatWidth
1361 * @see #getFormatWidth
1362 * @see #setPadCharacter
1363 * @see #getPadPosition
1364 * @see #setPadPosition
1367 virtual UnicodeString
getPadCharacterString() const;
1370 * Set the character used to pad to the format width. If padding
1371 * is not enabled, then this will take effect if padding is later
1373 * @param padChar a string containing the pad charcter. If the string
1374 * has length 0, then the pad characer is set to ' '. Otherwise
1375 * padChar.char32At(0) will be used as the pad character.
1376 * @see #setFormatWidth
1377 * @see #getFormatWidth
1378 * @see #getPadCharacterString
1379 * @see #getPadPosition
1380 * @see #setPadPosition
1383 virtual void setPadCharacter(const UnicodeString
&padChar
);
1386 * Get the position at which padding will take place. This is the location
1387 * at which padding will be inserted if the result of format()
1388 * is shorter than the format width.
1389 * @return the pad position, one of kPadBeforePrefix,
1390 * kPadAfterPrefix, kPadBeforeSuffix, or
1392 * @see #setFormatWidth
1393 * @see #getFormatWidth
1394 * @see #setPadCharacter
1395 * @see #getPadCharacterString
1396 * @see #setPadPosition
1397 * @see #EPadPosition
1400 virtual EPadPosition
getPadPosition(void) const;
1403 * Set the position at which padding will take place. This is the location
1404 * at which padding will be inserted if the result of format()
1405 * is shorter than the format width. This has no effect unless padding is
1407 * @param padPos the pad position, one of kPadBeforePrefix,
1408 * kPadAfterPrefix, kPadBeforeSuffix, or
1410 * @see #setFormatWidth
1411 * @see #getFormatWidth
1412 * @see #setPadCharacter
1413 * @see #getPadCharacterString
1414 * @see #getPadPosition
1415 * @see #EPadPosition
1418 virtual void setPadPosition(EPadPosition padPos
);
1421 * Return whether or not scientific notation is used.
1422 * @return TRUE if this object formats and parses scientific notation
1423 * @see #setScientificNotation
1424 * @see #getMinimumExponentDigits
1425 * @see #setMinimumExponentDigits
1426 * @see #isExponentSignAlwaysShown
1427 * @see #setExponentSignAlwaysShown
1430 virtual UBool
isScientificNotation(void);
1433 * Set whether or not scientific notation is used. When scientific notation
1434 * is used, the effective maximum number of integer digits is <= 8. If the
1435 * maximum number of integer digits is set to more than 8, the effective
1436 * maximum will be 1. This allows this call to generate a 'default' scientific
1437 * number format without additional changes.
1438 * @param useScientific TRUE if this object formats and parses scientific
1440 * @see #isScientificNotation
1441 * @see #getMinimumExponentDigits
1442 * @see #setMinimumExponentDigits
1443 * @see #isExponentSignAlwaysShown
1444 * @see #setExponentSignAlwaysShown
1447 virtual void setScientificNotation(UBool useScientific
);
1450 * Return the minimum exponent digits that will be shown.
1451 * @return the minimum exponent digits that will be shown
1452 * @see #setScientificNotation
1453 * @see #isScientificNotation
1454 * @see #setMinimumExponentDigits
1455 * @see #isExponentSignAlwaysShown
1456 * @see #setExponentSignAlwaysShown
1459 virtual int8_t getMinimumExponentDigits(void) const;
1462 * Set the minimum exponent digits that will be shown. This has no
1463 * effect unless scientific notation is in use.
1464 * @param minExpDig a value >= 1 indicating the fewest exponent digits
1465 * that will be shown. Values less than 1 will be treated as 1.
1466 * @see #setScientificNotation
1467 * @see #isScientificNotation
1468 * @see #getMinimumExponentDigits
1469 * @see #isExponentSignAlwaysShown
1470 * @see #setExponentSignAlwaysShown
1473 virtual void setMinimumExponentDigits(int8_t minExpDig
);
1476 * Return whether the exponent sign is always shown.
1477 * @return TRUE if the exponent is always prefixed with either the
1478 * localized minus sign or the localized plus sign, false if only negative
1479 * exponents are prefixed with the localized minus sign.
1480 * @see #setScientificNotation
1481 * @see #isScientificNotation
1482 * @see #setMinimumExponentDigits
1483 * @see #getMinimumExponentDigits
1484 * @see #setExponentSignAlwaysShown
1487 virtual UBool
isExponentSignAlwaysShown(void);
1490 * Set whether the exponent sign is always shown. This has no effect
1491 * unless scientific notation is in use.
1492 * @param expSignAlways TRUE if the exponent is always prefixed with either
1493 * the localized minus sign or the localized plus sign, false if only
1494 * negative exponents are prefixed with the localized minus sign.
1495 * @see #setScientificNotation
1496 * @see #isScientificNotation
1497 * @see #setMinimumExponentDigits
1498 * @see #getMinimumExponentDigits
1499 * @see #isExponentSignAlwaysShown
1502 virtual void setExponentSignAlwaysShown(UBool expSignAlways
);
1505 * Return the grouping size. Grouping size is the number of digits between
1506 * grouping separators in the integer portion of a number. For example,
1507 * in the number "123,456.78", the grouping size is 3.
1509 * @return the grouping size.
1510 * @see setGroupingSize
1511 * @see NumberFormat::isGroupingUsed
1512 * @see DecimalFormatSymbols::getGroupingSeparator
1515 int32_t getGroupingSize(void) const;
1518 * Set the grouping size. Grouping size is the number of digits between
1519 * grouping separators in the integer portion of a number. For example,
1520 * in the number "123,456.78", the grouping size is 3.
1522 * @param newValue the new value of the grouping size.
1523 * @see getGroupingSize
1524 * @see NumberFormat::setGroupingUsed
1525 * @see DecimalFormatSymbols::setGroupingSeparator
1528 virtual void setGroupingSize(int32_t newValue
);
1531 * Return the secondary grouping size. In some locales one
1532 * grouping interval is used for the least significant integer
1533 * digits (the primary grouping size), and another is used for all
1534 * others (the secondary grouping size). A formatter supporting a
1535 * secondary grouping size will return a positive integer unequal
1536 * to the primary grouping size returned by
1537 * getGroupingSize(). For example, if the primary
1538 * grouping size is 4, and the secondary grouping size is 2, then
1539 * the number 123456789 formats as "1,23,45,6789", and the pattern
1540 * appears as "#,##,###0".
1541 * @return the secondary grouping size, or a value less than
1542 * one if there is none
1543 * @see setSecondaryGroupingSize
1544 * @see NumberFormat::isGroupingUsed
1545 * @see DecimalFormatSymbols::getGroupingSeparator
1548 int32_t getSecondaryGroupingSize(void) const;
1551 * Set the secondary grouping size. If set to a value less than 1,
1552 * then secondary grouping is turned off, and the primary grouping
1553 * size is used for all intervals, not just the least significant.
1555 * @param newValue the new value of the secondary grouping size.
1556 * @see getSecondaryGroupingSize
1557 * @see NumberFormat#setGroupingUsed
1558 * @see DecimalFormatSymbols::setGroupingSeparator
1561 virtual void setSecondaryGroupingSize(int32_t newValue
);
1564 * Allows you to get the behavior of the decimal separator with integers.
1565 * (The decimal separator will always appear with decimals.)
1567 * @return TRUE if the decimal separator always appear with decimals.
1568 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1571 UBool
isDecimalSeparatorAlwaysShown(void) const;
1574 * Allows you to set the behavior of the decimal separator with integers.
1575 * (The decimal separator will always appear with decimals.)
1577 * @param newValue set TRUE if the decimal separator will always appear with decimals.
1578 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1581 virtual void setDecimalSeparatorAlwaysShown(UBool newValue
);
1584 * Synthesizes a pattern string that represents the current state
1585 * of this Format object.
1587 * @param result Output param which will receive the pattern.
1588 * Previous contents are deleted.
1589 * @return A reference to 'result'.
1593 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
1596 * Synthesizes a localized pattern string that represents the current
1597 * state of this Format object.
1599 * @param result Output param which will receive the localized pattern.
1600 * Previous contents are deleted.
1601 * @return A reference to 'result'.
1605 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
) const;
1608 * Apply the given pattern to this Format object. A pattern is a
1609 * short-hand specification for the various formatting properties.
1610 * These properties can also be changed individually through the
1611 * various setter methods.
1613 * There is no limit to integer digits are set
1614 * by this routine, since that is the typical end-user desire;
1615 * use setMaximumInteger if you want to set a real value.
1616 * For negative numbers, use a second pattern, separated by a semicolon
1618 * . Example "#,#00.0#" -> 1,234.56
1620 * This means a minimum of 2 integer digits, 1 fraction digit, and
1621 * a maximum of 2 fraction digits.
1623 * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1625 * In negative patterns, the minimum and maximum counts are ignored;
1626 * these are presumed to be set in the positive pattern.
1628 * @param pattern The pattern to be applied.
1629 * @param parseError Struct to recieve information on position
1630 * of error if an error is encountered
1631 * @param status Output param set to success/failure code on
1632 * exit. If the pattern is invalid, this will be
1633 * set to a failure result.
1636 virtual void applyPattern(const UnicodeString
& pattern
,
1637 UParseError
& parseError
,
1638 UErrorCode
& status
);
1641 * @param pattern The pattern to be applied.
1642 * @param status Output param set to success/failure code on
1643 * exit. If the pattern is invalid, this will be
1644 * set to a failure result.
1647 virtual void applyPattern(const UnicodeString
& pattern
,
1648 UErrorCode
& status
);
1651 * Apply the given pattern to this Format object. The pattern
1652 * is assumed to be in a localized notation. A pattern is a
1653 * short-hand specification for the various formatting properties.
1654 * These properties can also be changed individually through the
1655 * various setter methods.
1657 * There is no limit to integer digits are set
1658 * by this routine, since that is the typical end-user desire;
1659 * use setMaximumInteger if you want to set a real value.
1660 * For negative numbers, use a second pattern, separated by a semicolon
1662 * . Example "#,#00.0#" -> 1,234.56
1664 * This means a minimum of 2 integer digits, 1 fraction digit, and
1665 * a maximum of 2 fraction digits.
1667 * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1669 * In negative patterns, the minimum and maximum counts are ignored;
1670 * these are presumed to be set in the positive pattern.
1672 * @param pattern The localized pattern to be applied.
1673 * @param parseError Struct to recieve information on position
1674 * of error if an error is encountered
1675 * @param status Output param set to success/failure code on
1676 * exit. If the pattern is invalid, this will be
1677 * set to a failure result.
1680 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1681 UParseError
& parseError
,
1682 UErrorCode
& status
);
1685 * Apply the given pattern to this Format object.
1687 * @param pattern The localized pattern to be applied.
1688 * @param status Output param set to success/failure code on
1689 * exit. If the pattern is invalid, this will be
1690 * set to a failure result.
1693 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1694 UErrorCode
& status
);
1698 * Sets the maximum number of digits allowed in the integer portion of a
1699 * number. This override limits the integer digit count to 309.
1701 * @param newValue the new value of the maximum number of digits
1702 * allowed in the integer portion of a number.
1703 * @see NumberFormat#setMaximumIntegerDigits
1706 virtual void setMaximumIntegerDigits(int32_t newValue
);
1709 * Sets the minimum number of digits allowed in the integer portion of a
1710 * number. This override limits the integer digit count to 309.
1712 * @param newValue the new value of the minimum number of digits
1713 * allowed in the integer portion of a number.
1714 * @see NumberFormat#setMinimumIntegerDigits
1717 virtual void setMinimumIntegerDigits(int32_t newValue
);
1720 * Sets the maximum number of digits allowed in the fraction portion of a
1721 * number. This override limits the fraction digit count to 340.
1723 * @param newValue the new value of the maximum number of digits
1724 * allowed in the fraction portion of a number.
1725 * @see NumberFormat#setMaximumFractionDigits
1728 virtual void setMaximumFractionDigits(int32_t newValue
);
1731 * Sets the minimum number of digits allowed in the fraction portion of a
1732 * number. This override limits the fraction digit count to 340.
1734 * @param newValue the new value of the minimum number of digits
1735 * allowed in the fraction portion of a number.
1736 * @see NumberFormat#setMinimumFractionDigits
1739 virtual void setMinimumFractionDigits(int32_t newValue
);
1742 * Returns the minimum number of significant digits that will be
1743 * displayed. This value has no effect unless areSignificantDigitsUsed()
1745 * @return the fewest significant digits that will be shown
1748 int32_t getMinimumSignificantDigits() const;
1751 * Returns the maximum number of significant digits that will be
1752 * displayed. This value has no effect unless areSignificantDigitsUsed()
1754 * @return the most significant digits that will be shown
1757 int32_t getMaximumSignificantDigits() const;
1760 * Sets the minimum number of significant digits that will be
1761 * displayed. If <code>min</code> is less than one then it is set
1762 * to one. If the maximum significant digits count is less than
1763 * <code>min</code>, then it is set to <code>min</code>. This
1764 * value has no effect unless areSignificantDigits() returns true.
1765 * @param min the fewest significant digits to be shown
1768 void setMinimumSignificantDigits(int32_t min
);
1771 * Sets the maximum number of significant digits that will be
1772 * displayed. If <code>max</code> is less than one then it is set
1773 * to one. If the minimum significant digits count is greater
1774 * than <code>max</code>, then it is set to <code>max</code>.
1775 * This value has no effect unless areSignificantDigits() returns
1777 * @param max the most significant digits to be shown
1780 void setMaximumSignificantDigits(int32_t max
);
1783 * Returns true if significant digits are in use, or false if
1784 * integer and fraction digit counts are in use.
1785 * @return true if significant digits are in use
1788 UBool
areSignificantDigitsUsed() const;
1791 * Sets whether significant digits are in use, or integer and
1792 * fraction digit counts are in use.
1793 * @param useSignificantDigits true to use significant digits, or
1794 * false to use integer and fraction digit counts
1797 void setSignificantDigitsUsed(UBool useSignificantDigits
);
1801 * Sets the currency used to display currency
1802 * amounts. This takes effect immediately, if this format is a
1803 * currency format. If this format is not a currency format, then
1804 * the currency is used if and when this object becomes a
1805 * currency format through the application of a new pattern.
1806 * @param theCurrency a 3-letter ISO code indicating new currency
1807 * to use. It need not be null-terminated. May be the empty
1808 * string or NULL to indicate no currency.
1809 * @param ec input-output error code
1812 virtual void setCurrency(const UChar
* theCurrency
, UErrorCode
& ec
);
1815 * Sets the currency used to display currency amounts. See
1816 * setCurrency(const UChar*, UErrorCode&).
1817 * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&).
1819 virtual void setCurrency(const UChar
* theCurrency
);
1822 * The resource tags we use to retrieve decimal format data from
1823 * locale resource bundles.
1824 * @deprecated ICU 3.4. This string has no public purpose. Please don't use it.
1826 static const char fgNumberPatterns
[];
1831 * Return the class ID for this class. This is useful only for
1832 * comparing to a return value from getDynamicClassID(). For example:
1834 * . Base* polymorphic_pointer = createPolymorphicObject();
1835 * . if (polymorphic_pointer->getDynamicClassID() ==
1836 * . Derived::getStaticClassID()) ...
1838 * @return The class ID for all objects of this class.
1841 static UClassID U_EXPORT2
getStaticClassID(void);
1844 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
1845 * This method is to implement a simple version of RTTI, since not all
1846 * C++ compilers support genuine RTTI. Polymorphic operator==() and
1847 * clone() methods call this method.
1849 * @return The class ID for this object. All objects of a
1850 * given class have the same class ID. Objects of
1851 * other classes have different class IDs.
1854 virtual UClassID
getDynamicClassID(void) const;
1858 DecimalFormat(); // default constructor not implemented
1860 int32_t precision() const;
1863 * Initialize all fields of a new DecimalFormatter.
1864 * Common code for use by constructors.
1869 * Do real work of constructing a new DecimalFormat.
1871 void construct(UErrorCode
& status
,
1872 UParseError
& parseErr
,
1873 const UnicodeString
* pattern
= 0,
1874 DecimalFormatSymbols
* symbolsToAdopt
= 0
1878 * Does the real work of generating a pattern.
1880 * @param result Output param which will receive the pattern.
1881 * Previous contents are deleted.
1882 * @param localized TRUE return localized pattern.
1883 * @return A reference to 'result'.
1885 UnicodeString
& toPattern(UnicodeString
& result
, UBool localized
) const;
1888 * Does the real work of applying a pattern.
1889 * @param pattern The pattern to be applied.
1890 * @param localized If true, the pattern is localized; else false.
1891 * @param parseError Struct to recieve information on position
1892 * of error if an error is encountered
1893 * @param status Output param set to success/failure code on
1894 * exit. If the pattern is invalid, this will be
1895 * set to a failure result.
1897 void applyPattern(const UnicodeString
& pattern
,
1899 UParseError
& parseError
,
1900 UErrorCode
& status
);
1903 * similar to applyPattern, but without re-gen affix for currency
1905 void applyPatternInternally(const UnicodeString
& pluralCount
,
1906 const UnicodeString
& pattern
,
1908 UParseError
& parseError
,
1909 UErrorCode
& status
);
1912 * only apply pattern without expand affixes
1914 void applyPatternWithoutExpandAffix(const UnicodeString
& pattern
,
1916 UParseError
& parseError
,
1917 UErrorCode
& status
);
1921 * expand affixes (after apply patter) and re-compute fFormatWidth
1923 void expandAffixAdjustWidth(const UnicodeString
* pluralCount
);
1927 * Do the work of formatting a number, either a double or a long.
1929 * @param appendTo Output parameter to receive result.
1930 * Result is appended to existing contents.
1931 * @param handler Records information about field positions.
1932 * @param digits the digits to be formatted.
1933 * @param isInteger if TRUE format the digits as Integer.
1934 * @return Reference to 'appendTo' parameter.
1936 UnicodeString
& subformat(UnicodeString
& appendTo
,
1937 FieldPositionHandler
& handler
,
1939 UBool isInteger
) const;
1942 void parse(const UnicodeString
& text
,
1943 Formattable
& result
,
1945 UChar
* currency
) const;
1949 fgStatusLength
// Leave last in list.
1952 UBool
subparse(const UnicodeString
& text
,
1953 const UnicodeString
* negPrefix
,
1954 const UnicodeString
* negSuffix
,
1955 const UnicodeString
* posPrefix
,
1956 const UnicodeString
* posSuffix
,
1957 UBool currencyParsing
,
1959 ParsePosition
& parsePosition
,
1960 DigitList
& digits
, UBool
* status
,
1961 UChar
* currency
) const;
1963 // Mixed style parsing for currency.
1964 // It parses against the current currency pattern
1965 // using complex affix comparison
1966 // parses against the currency plural patterns using complex affix comparison,
1967 // and parses against the current pattern using simple affix comparison.
1968 UBool
parseForCurrency(const UnicodeString
& text
,
1969 ParsePosition
& parsePosition
,
1972 UChar
* currency
) const;
1974 int32_t skipPadding(const UnicodeString
& text
, int32_t position
) const;
1976 int32_t compareAffix(const UnicodeString
& input
,
1980 const UnicodeString
* affixPat
,
1981 UBool currencyParsing
,
1983 UChar
* currency
) const;
1985 static int32_t compareSimpleAffix(const UnicodeString
& affix
,
1986 const UnicodeString
& input
,
1990 static int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
);
1992 static int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
);
1994 int32_t compareComplexAffix(const UnicodeString
& affixPat
,
1995 const UnicodeString
& input
,
1998 UChar
* currency
) const;
2000 static int32_t match(const UnicodeString
& text
, int32_t pos
, UChar32 ch
);
2002 static int32_t match(const UnicodeString
& text
, int32_t pos
, const UnicodeString
& str
);
2004 static UBool
matchSymbol(const UnicodeString
&text
, int32_t position
, int32_t length
, const UnicodeString
&symbol
,
2005 UnicodeSet
*sset
, UChar32 schar
);
2007 static UBool
matchDecimal(UChar32 symbolChar
,
2008 UBool sawDecimal
, UChar32 sawDecimalChar
,
2009 const UnicodeSet
*sset
, UChar32 schar
);
2011 static UBool
matchGrouping(UChar32 groupingChar
,
2012 UBool sawGrouping
, UChar32 sawGroupingChar
,
2013 const UnicodeSet
*sset
,
2014 UChar32 decimalChar
, const UnicodeSet
*decimalSet
,
2018 * Get a decimal format symbol.
2019 * Returns a const reference to the symbol string.
2022 inline const UnicodeString
&getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol
) const;
2024 int32_t appendAffix(UnicodeString
& buf
,
2026 FieldPositionHandler
& handler
,
2028 UBool isPrefix
) const;
2031 * Append an affix to the given UnicodeString, using quotes if
2032 * there are special characters. Single quotes themselves must be
2033 * escaped in either case.
2035 void appendAffixPattern(UnicodeString
& appendTo
, const UnicodeString
& affix
,
2036 UBool localized
) const;
2038 void appendAffixPattern(UnicodeString
& appendTo
,
2039 const UnicodeString
* affixPattern
,
2040 const UnicodeString
& expAffix
, UBool localized
) const;
2042 void expandAffix(const UnicodeString
& pattern
,
2043 UnicodeString
& affix
,
2045 FieldPositionHandler
& handler
,
2047 const UnicodeString
* pluralCount
) const;
2049 void expandAffixes(const UnicodeString
* pluralCount
);
2051 void addPadding(UnicodeString
& appendTo
,
2052 FieldPositionHandler
& handler
,
2053 int32_t prefixLen
, int32_t suffixLen
) const;
2055 UBool
isGroupingPosition(int32_t pos
) const;
2057 void setCurrencyForSymbols();
2059 // similar to setCurrency without re-compute the affixes for currency.
2060 // If currency changes, the affix pattern for currency is not changed,
2061 // but the affix will be changed. So, affixes need to be
2062 // re-computed in setCurrency(), but not in setCurrencyInternally().
2063 virtual void setCurrencyInternally(const UChar
* theCurrency
, UErrorCode
& ec
);
2065 // set up currency affix patterns for mix parsing.
2066 // The patterns saved here are the affix patterns of default currency
2067 // pattern and the unique affix patterns of the plural currency patterns.
2068 // Those patterns are used by parseForCurrency().
2069 void setupCurrencyAffixPatterns(UErrorCode
& status
);
2071 // set up the currency affixes used in currency plural formatting.
2072 // It sets up both fAffixesForCurrency for currency pattern if the current
2073 // pattern contains 3 currency signs,
2074 // and it sets up fPluralAffixesForCurrency for currency plural patterns.
2075 void setupCurrencyAffixes(const UnicodeString
& pattern
,
2076 UBool setupForCurrentPattern
,
2077 UBool setupForPluralPattern
,
2078 UErrorCode
& status
);
2080 // hashtable operations
2081 Hashtable
* initHashForAffixPattern(UErrorCode
& status
);
2082 Hashtable
* initHashForAffix(UErrorCode
& status
);
2084 void deleteHashForAffixPattern();
2085 void deleteHashForAffix(Hashtable
*& table
);
2087 void copyHashForAffixPattern(const Hashtable
* source
,
2088 Hashtable
* target
, UErrorCode
& status
);
2089 void copyHashForAffix(const Hashtable
* source
,
2090 Hashtable
* target
, UErrorCode
& status
);
2092 UnicodeString
& _format(int64_t number
,
2093 UnicodeString
& appendTo
,
2094 FieldPositionHandler
& handler
) const;
2095 UnicodeString
& _format(double number
,
2096 UnicodeString
& appendTo
,
2097 FieldPositionHandler
& handler
) const;
2098 UnicodeString
& _format(const DigitList
&number
,
2099 UnicodeString
& appendTo
,
2100 FieldPositionHandler
& handler
,
2101 UErrorCode
&status
) const;
2103 // currency sign count
2105 fgCurrencySignCountZero
,
2106 fgCurrencySignCountInSymbolFormat
,
2107 fgCurrencySignCountInISOFormat
,
2108 fgCurrencySignCountInPluralFormat
2109 } CurrencySignCount
;
2115 UnicodeString fPositivePrefix
;
2116 UnicodeString fPositiveSuffix
;
2117 UnicodeString fNegativePrefix
;
2118 UnicodeString fNegativeSuffix
;
2119 UnicodeString
* fPosPrefixPattern
;
2120 UnicodeString
* fPosSuffixPattern
;
2121 UnicodeString
* fNegPrefixPattern
;
2122 UnicodeString
* fNegSuffixPattern
;
2125 * Formatter for ChoiceFormat-based currency names. If this field
2126 * is not null, then delegate to it to format currency symbols.
2129 ChoiceFormat
* fCurrencyChoice
;
2131 DigitList
* fMultiplier
; // NULL for multiplier of one
2132 int32_t fGroupingSize
;
2133 int32_t fGroupingSize2
;
2134 UBool fDecimalSeparatorAlwaysShown
;
2135 DecimalFormatSymbols
* fSymbols
;
2137 UBool fUseSignificantDigits
;
2138 int32_t fMinSignificantDigits
;
2139 int32_t fMaxSignificantDigits
;
2141 UBool fUseExponentialNotation
;
2142 int8_t fMinExponentDigits
;
2143 UBool fExponentSignAlwaysShown
;
2145 DigitList
* fRoundingIncrement
; // NULL if no rounding increment specified.
2146 ERoundingMode fRoundingMode
;
2149 int32_t fFormatWidth
;
2150 EPadPosition fPadPosition
;
2153 * Following are used for currency format
2155 // pattern used in this formatter
2156 UnicodeString fFormatPattern
;
2157 // style is only valid when decimal formatter is constructed by
2158 // DecimalFormat(pattern, decimalFormatSymbol, style)
2161 * Represents whether this is a currency format, and which
2162 * currency format style.
2163 * 0: not currency format type;
2164 * 1: currency style -- symbol name, such as "$" for US dollar.
2165 * 2: currency style -- ISO name, such as USD for US dollar.
2166 * 3: currency style -- plural long name, such as "US Dollar" for
2167 * "1.00 US Dollar", or "US Dollars" for
2168 * "3.00 US Dollars".
2170 int fCurrencySignCount
;
2173 /* For currency parsing purose,
2174 * Need to remember all prefix patterns and suffix patterns of
2175 * every currency format pattern,
2176 * including the pattern of default currecny style
2177 * and plural currency style. And the patterns are set through applyPattern.
2179 // TODO: innerclass?
2180 /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2181 struct AffixPatternsForCurrency : public UMemory {
2182 // negative prefix pattern
2183 UnicodeString negPrefixPatternForCurrency;
2184 // negative suffix pattern
2185 UnicodeString negSuffixPatternForCurrency;
2186 // positive prefix pattern
2187 UnicodeString posPrefixPatternForCurrency;
2188 // positive suffix pattern
2189 UnicodeString posSuffixPatternForCurrency;
2192 AffixPatternsForCurrency(const UnicodeString& negPrefix,
2193 const UnicodeString& negSuffix,
2194 const UnicodeString& posPrefix,
2195 const UnicodeString& posSuffix,
2197 negPrefixPatternForCurrency = negPrefix;
2198 negSuffixPatternForCurrency = negSuffix;
2199 posPrefixPatternForCurrency = posPrefix;
2200 posSuffixPatternForCurrency = posSuffix;
2206 /* affix for currency formatting when the currency sign in the pattern
2207 * equals to 3, such as the pattern contains 3 currency sign or
2208 * the formatter style is currency plural format style.
2210 /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2211 struct AffixesForCurrency : public UMemory {
2213 UnicodeString negPrefixForCurrency;
2215 UnicodeString negSuffixForCurrency;
2217 UnicodeString posPrefixForCurrency;
2219 UnicodeString posSuffixForCurrency;
2221 int32_t formatWidth;
2223 AffixesForCurrency(const UnicodeString& negPrefix,
2224 const UnicodeString& negSuffix,
2225 const UnicodeString& posPrefix,
2226 const UnicodeString& posSuffix) {
2227 negPrefixForCurrency = negPrefix;
2228 negSuffixForCurrency = negSuffix;
2229 posPrefixForCurrency = posPrefix;
2230 posSuffixForCurrency = posSuffix;
2235 // Affix pattern set for currency.
2236 // It is a set of AffixPatternsForCurrency,
2237 // each element of the set saves the negative prefix pattern,
2238 // negative suffix pattern, positive prefix pattern,
2239 // and positive suffix pattern of a pattern.
2240 // It is used for currency mixed style parsing.
2241 // It is actually is a set.
2242 // The set contains the default currency pattern from the locale,
2243 // and the currency plural patterns.
2244 // Since it is a set, it does not contain duplicated items.
2245 // For example, if 2 currency plural patterns are the same, only one pattern
2246 // is included in the set. When parsing, we do not check whether the plural
2247 // count match or not.
2248 Hashtable
* fAffixPatternsForCurrency
;
2250 // Following 2 are affixes for currency.
2251 // It is a hash map from plural count to AffixesForCurrency.
2252 // AffixesForCurrency saves the negative prefix,
2253 // negative suffix, positive prefix, and positive suffix of a pattern.
2254 // It is used during currency formatting only when the currency sign count
2255 // is 3. In which case, the affixes are getting from here, not
2256 // from the fNegativePrefix etc.
2257 Hashtable
* fAffixesForCurrency
; // for current pattern
2258 Hashtable
* fPluralAffixesForCurrency
; // for plural pattern
2260 // Information needed for DecimalFormat to format/parse currency plural.
2261 CurrencyPluralInfo
* fCurrencyPluralInfo
;
2266 * Returns the currency in effect for this formatter. Subclasses
2267 * should override this method as needed. Unlike getCurrency(),
2268 * this method should never return "".
2269 * @result output parameter for null-terminated result, which must
2270 * have a capacity of at least 4
2273 virtual void getEffectiveCurrency(UChar
* result
, UErrorCode
& ec
) const;
2275 /** number of integer digits
2278 static const int32_t kDoubleIntegerDigits
;
2279 /** number of fraction digits
2282 static const int32_t kDoubleFractionDigits
;
2285 * When someone turns on scientific mode, we assume that more than this
2286 * number of digits is due to flipping from some other mode that didn't
2287 * restrict the maximum, and so we force 1 integer digit. We don't bother
2288 * to track and see if someone is using exponential notation with more than
2289 * this number, it wouldn't make sense anyway, and this is just to make sure
2290 * that someone turning on scientific mode with default settings doesn't
2291 * end up with lots of zeroes.
2294 static const int32_t kMaxScientificIntegerDigits
;
2297 inline UnicodeString
&
2298 DecimalFormat::format(const Formattable
& obj
,
2299 UnicodeString
& appendTo
,
2300 UErrorCode
& status
) const {
2301 // Don't use Format:: - use immediate base class only,
2302 // in case immediate base modifies behavior later.
2303 return NumberFormat::format(obj
, appendTo
, status
);
2306 inline UnicodeString
&
2307 DecimalFormat::format(double number
,
2308 UnicodeString
& appendTo
) const {
2309 FieldPosition
pos(0);
2310 return format(number
, appendTo
, pos
);
2313 inline UnicodeString
&
2314 DecimalFormat::format(int32_t number
,
2315 UnicodeString
& appendTo
) const {
2316 FieldPosition
pos(0);
2317 return format((int64_t)number
, appendTo
, pos
);
2320 #ifndef U_HIDE_INTERNAL_API
2321 inline const UnicodeString
&
2322 DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol
) const {
2323 return fSymbols
->getConstSymbol(symbol
);
2329 #endif /* #if !UCONFIG_NO_FORMATTING */