1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 03/20/97 clhuang Updated per C++ implementation.
16 * 04/03/97 aliu Rewrote parsing and formatting completely, and
17 * cleaned up and debugged. Actually works now.
18 * 04/17/97 aliu Changed DigitCount to int per code review.
19 * 07/10/97 helena Made ParsePosition a class and get rid of the function
21 * 09/09/97 aliu Ported over support for exponential formats.
22 * 07/20/98 stephen Changed documentation
23 * 01/30/13 emmons Added Scaling methods
24 ********************************************************************************
30 #include "unicode/utypes.h"
33 * \brief C++ API: Compatibility APIs for decimal formatting.
36 #if !UCONFIG_NO_FORMATTING
38 #include "unicode/dcfmtsym.h"
39 #include "unicode/numfmt.h"
40 #include "unicode/locid.h"
41 #include "unicode/fpositer.h"
42 #include "unicode/stringpiece.h"
43 #include "unicode/curramt.h"
44 #include "unicode/enumset.h"
46 #ifndef U_HIDE_INTERNAL_API
48 * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE
51 #if UCONFIG_FORMAT_FASTPATHS_49
52 #define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16
54 #endif /* U_HIDE_INTERNAL_API */
56 #if U_SHOW_CPLUSPLUS_API
60 class CurrencyPluralInfo
;
63 class FieldPositionHandler
;
64 class DecimalFormatStaticSets
;
66 class DecimalFormatImpl
;
68 class VisibleDigitsWithExponent
;
70 // explicit template instantiation. see digitlst.h
71 // (When building DLLs for Windows this is required.)
72 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
73 template class U_I18N_API EnumSet
<UNumberFormatAttribute
,
74 UNUM_MAX_NONBOOLEAN_ATTRIBUTE
+1,
75 UNUM_LIMIT_BOOLEAN_ATTRIBUTE
>;
79 * <p><strong>IMPORTANT:</strong> New users are strongly encouraged to see if
80 * numberformatter.h fits their use case. Although not deprecated, this header
81 * is provided for backwards compatibility only.
84 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal
85 * numbers. It has a variety of features designed to make it possible to parse
86 * and format numbers in any locale, including support for Western, Arabic, or
87 * Indic digits. It also supports different flavors of numbers, including
88 * integers ("123"), fixed-point numbers ("123.4"), scientific notation
89 * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123",
90 * "123 US dollars"). All of these flavors can be easily localized.
92 * <p>To obtain a NumberFormat for a specific locale (including the default
93 * locale) call one of NumberFormat's factory methods such as
94 * createInstance(). Do not call the DecimalFormat constructors directly, unless
95 * you know what you are doing, since the NumberFormat factory methods may
96 * return subclasses other than DecimalFormat.
98 * <p><strong>Example Usage</strong>
101 * // Normally we would have a GUI with a menu for this
103 * const Locale* locales = NumberFormat::getAvailableLocales(locCount);
105 * double myNumber = -1234.56;
106 * UErrorCode success = U_ZERO_ERROR;
107 * NumberFormat* form;
109 * // Print out a number with the localized number, currency and percent
110 * // format for each locale.
111 * UnicodeString countryName;
112 * UnicodeString displayName;
114 * UnicodeString pattern;
115 * Formattable fmtable;
116 * for (int32_t j = 0; j < 3; ++j) {
117 * cout << endl << "FORMAT " << j << endl;
118 * for (int32_t i = 0; i < locCount; ++i) {
119 * if (locales[i].getCountry(countryName).size() == 0) {
120 * // skip language-only
125 * form = NumberFormat::createInstance(locales[i], success ); break;
127 * form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
129 * form = NumberFormat::createPercentInstance(locales[i], success ); break;
133 * pattern = ((DecimalFormat*)form)->toPattern(pattern);
134 * cout << locales[i].getDisplayName(displayName) << ": " << pattern;
135 * cout << " -> " << form->format(myNumber,str) << endl;
136 * form->parse(form->format(myNumber,str), fmtable, success);
143 * Another example use createInstance(style)
146 * <strong>// Print out a number using the localized number, currency,
147 * // percent, scientific, integer, iso currency, and plural currency
148 * // format for each locale</strong>
149 * Locale* locale = new Locale("en", "US");
150 * double myNumber = 1234.56;
151 * UErrorCode success = U_ZERO_ERROR;
153 * Formattable fmtable;
154 * for (int j=NumberFormat::kNumberStyle;
155 * j<=NumberFormat::kPluralCurrencyStyle;
157 * NumberFormat* format = NumberFormat::createInstance(locale, j, success);
159 * cout << "format result " << form->format(myNumber, str) << endl;
160 * format->parse(form->format(myNumber, str), fmtable, success);
164 * <p><strong>Patterns</strong>
166 * <p>A DecimalFormat consists of a <em>pattern</em> and a set of
167 * <em>symbols</em>. The pattern may be set directly using
168 * applyPattern(), or indirectly using other API methods which
169 * manipulate aspects of the pattern, such as the minimum number of integer
170 * digits. The symbols are stored in a DecimalFormatSymbols
171 * object. When using the NumberFormat factory methods, the
172 * pattern and symbols are read from ICU's locale data.
174 * <p><strong>Special Pattern Characters</strong>
176 * <p>Many characters in a pattern are taken literally; they are matched during
177 * parsing and output unchanged during formatting. Special characters, on the
178 * other hand, stand for other characters, strings, or classes of characters.
179 * For example, the '#' character is replaced by a localized digit. Often the
180 * replacement character is the same as the pattern character; in the U.S. locale,
181 * the ',' grouping character is replaced by ','. However, the replacement is
182 * still happening, and if the symbols are modified, the grouping character
183 * changes. Some special characters affect the behavior of the formatter by
184 * their presence; for example, if the percent character is seen, then the
185 * value is multiplied by 100 before being displayed.
187 * <p>To insert a special character in a pattern as a literal, that is, without
188 * any special meaning, the character must be quoted. There are some exceptions to
189 * this which are noted below.
191 * <p>The characters listed here are used in non-localized patterns. Localized
192 * patterns use the corresponding characters taken from this formatter's
193 * DecimalFormatSymbols object instead, and these characters lose
194 * their special status. Two exceptions are the currency sign and quote, which
197 * <table border=0 cellspacing=3 cellpadding=0>
198 * <tr bgcolor="#ccccff">
199 * <td align=left><strong>Symbol</strong>
200 * <td align=left><strong>Location</strong>
201 * <td align=left><strong>Localized?</strong>
202 * <td align=left><strong>Meaning</strong>
208 * <tr valign=top bgcolor="#eeeeff">
209 * <td><code>1-9</code>
212 * <td>'1' through '9' indicate rounding.
214 * <td><code>\htmlonly@\endhtmlonly</code> <!--doxygen doesn't like @-->
217 * <td>Significant digit
218 * <tr valign=top bgcolor="#eeeeff">
222 * <td>Digit, zero shows as absent
227 * <td>Decimal separator or monetary decimal separator
228 * <tr valign=top bgcolor="#eeeeff">
237 * <td>Grouping separator
238 * <tr valign=top bgcolor="#eeeeff">
242 * <td>Separates mantissa and exponent in scientific notation.
243 * <em>Need not be quoted in prefix or suffix.</em>
248 * <td>Prefix positive exponents with localized plus sign.
249 * <em>Need not be quoted in prefix or suffix.</em>
250 * <tr valign=top bgcolor="#eeeeff">
252 * <td>Subpattern boundary
254 * <td>Separates positive and negative subpatterns
256 * <td><code>\%</code>
257 * <td>Prefix or suffix
259 * <td>Multiply by 100 and show as percentage
260 * <tr valign=top bgcolor="#eeeeff">
261 * <td><code>\\u2030</code>
262 * <td>Prefix or suffix
264 * <td>Multiply by 1000 and show as per mille
266 * <td><code>\htmlonly¤\endhtmlonly</code> (<code>\\u00A4</code>)
267 * <td>Prefix or suffix
269 * <td>Currency sign, replaced by currency symbol. If
270 * doubled, replaced by international currency symbol.
271 * If tripled, replaced by currency plural names, for example,
272 * "US dollar" or "US dollars" for America.
273 * If present in a pattern, the monetary decimal separator
274 * is used instead of the decimal separator.
275 * <tr valign=top bgcolor="#eeeeff">
277 * <td>Prefix or suffix
279 * <td>Used to quote special characters in a prefix or suffix,
280 * for example, <code>"'#'#"</code> formats 123 to
281 * <code>"#123"</code>. To create a single quote
282 * itself, use two in a row: <code>"# o''clock"</code>.
285 * <td>Prefix or suffix boundary
287 * <td>Pad escape, precedes pad character
290 * <p>A DecimalFormat pattern contains a postive and negative
291 * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a
292 * prefix, a numeric part, and a suffix. If there is no explicit negative
293 * subpattern, the negative subpattern is the localized minus sign prefixed to the
294 * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there
295 * is an explicit negative subpattern, it serves only to specify the negative
296 * prefix and suffix; the number of digits, minimal digits, and other
297 * characteristics are ignored in the negative subpattern. That means that
298 * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
300 * <p>The prefixes, suffixes, and various symbols used for infinity, digits,
301 * thousands separators, decimal separators, etc. may be set to arbitrary
302 * values, and they will appear properly during formatting. However, care must
303 * be taken that the symbols and strings do not conflict, or parsing will be
304 * unreliable. For example, either the positive and negative prefixes or the
305 * suffixes must be distinct for parse() to be able
306 * to distinguish positive from negative values. Another example is that the
307 * decimal separator and thousands separator should be distinct characters, or
308 * parsing will be impossible.
310 * <p>The <em>grouping separator</em> is a character that separates clusters of
311 * integer digits to make large numbers more legible. It commonly used for
312 * thousands, but in some locales it separates ten-thousands. The <em>grouping
313 * size</em> is the number of digits between the grouping separators, such as 3
314 * for "100,000,000" or 4 for "1 0000 0000". There are actually two different
315 * grouping sizes: One used for the least significant integer digits, the
316 * <em>primary grouping size</em>, and one used for all others, the
317 * <em>secondary grouping size</em>. In most locales these are the same, but
318 * sometimes they are different. For example, if the primary grouping interval
319 * is 3, and the secondary is 2, then this corresponds to the pattern
320 * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a
321 * pattern contains multiple grouping separators, the interval between the last
322 * one and the end of the integer defines the primary grouping size, and the
323 * interval between the last two defines the secondary grouping size. All others
324 * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
326 * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
327 * DecimalFormat to set a failing UErrorCode.
329 * <p><strong>Pattern BNF</strong>
332 * pattern := subpattern (';' subpattern)?
333 * subpattern := prefix? number exponent? suffix?
334 * number := (integer ('.' fraction)?) | sigDigits
335 * prefix := '\\u0000'..'\\uFFFD' - specialCharacters
336 * suffix := '\\u0000'..'\\uFFFD' - specialCharacters
337 * integer := '#'* '0'* '0'
338 * fraction := '0'* '#'*
339 * sigDigits := '#'* '@' '@'* '#'*
340 * exponent := 'E' '+'? '0'* '0'
341 * padSpec := '*' padChar
342 * padChar := '\\u0000'..'\\uFFFD' - quote
345 * X* 0 or more instances of X
346 * X? 0 or 1 instances of X
348 * C..D any character from C up to D, inclusive
349 * S-T characters in S, except those in T
351 * The first subpattern is for positive numbers. The second (optional)
352 * subpattern is for negative numbers.
354 * <p>Not indicated in the BNF syntax above:
356 * <ul><li>The grouping separator ',' can occur inside the integer and
357 * sigDigits elements, between any two pattern characters of that
358 * element, as long as the integer or sigDigits element is not
359 * followed by the exponent element.
361 * <li>Two grouping intervals are recognized: That between the
362 * decimal point and the first grouping symbol, and that
363 * between the first and second grouping symbols. These
364 * intervals are identical in most locales, but in some
365 * locales they differ. For example, the pattern
366 * "#,##,###" formats the number 123456789 as
367 * "12,34,56,789".</li>
369 * <li>The pad specifier <code>padSpec</code> may appear before the prefix,
370 * after the prefix, before the suffix, after the suffix, or not at all.
372 * <li>In place of '0', the digits '1' through '9' may be used to
373 * indicate a rounding increment.
376 * <p><strong>Parsing</strong>
378 * <p>DecimalFormat parses all Unicode characters that represent
379 * decimal digits, as defined by u_charDigitValue(). In addition,
380 * DecimalFormat also recognizes as digits the ten consecutive
381 * characters starting with the localized zero digit defined in the
382 * DecimalFormatSymbols object. During formatting, the
383 * DecimalFormatSymbols-based digits are output.
385 * <p>During parsing, grouping separators are ignored.
387 * <p>For currency parsing, the formatter is able to parse every currency
388 * style formats no matter which style the formatter is constructed with.
389 * For example, a formatter instance gotten from
390 * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse
391 * formats such as "USD1.00" and "3.00 US dollars".
393 * <p>If parse(UnicodeString&,Formattable&,ParsePosition&)
394 * fails to parse a string, it leaves the parse position unchanged.
395 * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&)
396 * indicates parse failure by setting a failing
399 * <p><strong>Formatting</strong>
401 * <p>Formatting is guided by several parameters, all of which can be
402 * specified either using a pattern or using the API. The following
403 * description applies to formats that do not use <a href="#sci">scientific
404 * notation</a> or <a href="#sigdig">significant digits</a>.
406 * <ul><li>If the number of actual integer digits exceeds the
407 * <em>maximum integer digits</em>, then only the least significant
408 * digits are shown. For example, 1997 is formatted as "97" if the
409 * maximum integer digits is set to 2.
411 * <li>If the number of actual integer digits is less than the
412 * <em>minimum integer digits</em>, then leading zeros are added. For
413 * example, 1997 is formatted as "01997" if the minimum integer digits
416 * <li>If the number of actual fraction digits exceeds the <em>maximum
417 * fraction digits</em>, then rounding is performed to the
418 * maximum fraction digits. For example, 0.125 is formatted as "0.12"
419 * if the maximum fraction digits is 2. This behavior can be changed
420 * by specifying a rounding increment and/or a rounding mode.
422 * <li>If the number of actual fraction digits is less than the
423 * <em>minimum fraction digits</em>, then trailing zeros are added.
424 * For example, 0.125 is formatted as "0.1250" if the mimimum fraction
425 * digits is set to 4.
427 * <li>Trailing fractional zeros are not displayed if they occur
428 * <em>j</em> positions after the decimal, where <em>j</em> is less
429 * than the maximum fraction digits. For example, 0.10004 is
430 * formatted as "0.1" if the maximum fraction digits is four or less.
433 * <p><strong>Special Values</strong>
435 * <p><code>NaN</code> is represented as a single character, typically
436 * <code>\\uFFFD</code>. This character is determined by the
437 * DecimalFormatSymbols object. This is the only value for which
438 * the prefixes and suffixes are not used.
440 * <p>Infinity is represented as a single character, typically
441 * <code>\\u221E</code>, with the positive or negative prefixes and suffixes
442 * applied. The infinity character is determined by the
443 * DecimalFormatSymbols object.
445 * <a name="sci"><strong>Scientific Notation</strong></a>
447 * <p>Numbers in scientific notation are expressed as the product of a mantissa
448 * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The
449 * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0),
450 * but it need not be. DecimalFormat supports arbitrary mantissas.
451 * DecimalFormat can be instructed to use scientific
452 * notation through the API or through the pattern. In a pattern, the exponent
453 * character immediately followed by one or more digit characters indicates
454 * scientific notation. Example: "0.###E0" formats the number 1234 as
458 * <li>The number of digit characters after the exponent character gives the
459 * minimum exponent digit count. There is no maximum. Negative exponents are
460 * formatted using the localized minus sign, <em>not</em> the prefix and suffix
461 * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix
462 * positive exponents with a localized plus sign, specify '+' between the
463 * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0",
464 * "1E-1", etc. (In localized patterns, use the localized plus sign rather than
467 * <li>The minimum number of integer digits is achieved by adjusting the
468 * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This
469 * only happens if there is no maximum number of integer digits. If there is a
470 * maximum, then the minimum number of integer digits is fixed at one.
472 * <li>The maximum number of integer digits, if present, specifies the exponent
473 * grouping. The most common use of this is to generate <em>engineering
474 * notation</em>, in which the exponent is a multiple of three, e.g.,
475 * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3".
477 * <li>When using scientific notation, the formatter controls the
478 * digit counts using significant digits logic. The maximum number of
479 * significant digits limits the total number of integer and fraction
480 * digits that will be shown in the mantissa; it does not affect
481 * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3".
482 * See the section on significant digits for more details.
484 * <li>The number of significant digits shown is determined as
485 * follows: If areSignificantDigitsUsed() returns false, then the
486 * minimum number of significant digits shown is one, and the maximum
487 * number of significant digits shown is the sum of the <em>minimum
488 * integer</em> and <em>maximum fraction</em> digits, and is
489 * unaffected by the maximum integer digits. If this sum is zero,
490 * then all significant digits are shown. If
491 * areSignificantDigitsUsed() returns true, then the significant digit
492 * counts are specified by getMinimumSignificantDigits() and
493 * getMaximumSignificantDigits(). In this case, the number of
494 * integer digits is fixed at one, and there is no exponent grouping.
496 * <li>Exponential patterns may not contain grouping separators.
499 * <a name="sigdig"><strong>Significant Digits</strong></a>
501 * <code>DecimalFormat</code> has two ways of controlling how many
502 * digits are shows: (a) significant digits counts, or (b) integer and
503 * fraction digit counts. Integer and fraction digit counts are
504 * described above. When a formatter is using significant digits
505 * counts, the number of integer and fraction digits is not specified
506 * directly, and the formatter settings for these counts are ignored.
507 * Instead, the formatter uses however many integer and fraction
508 * digits are required to display the specified number of significant
511 * <table border=0 cellspacing=3 cellpadding=0>
512 * <tr bgcolor="#ccccff">
513 * <td align=left>Pattern
514 * <td align=left>Minimum significant digits
515 * <td align=left>Maximum significant digits
516 * <td align=left>Number
517 * <td align=left>Output of format()
519 * <td><code>\@\@\@</code>
523 * <td><code>12300</code>
524 * <tr valign=top bgcolor="#eeeeff">
525 * <td><code>\@\@\@</code>
529 * <td><code>0.123</code>
531 * <td><code>\@\@##</code>
535 * <td><code>3.142</code>
536 * <tr valign=top bgcolor="#eeeeff">
537 * <td><code>\@\@##</code>
541 * <td><code>1.23</code>
545 * <li>Significant digit counts may be expressed using patterns that
546 * specify a minimum and maximum number of significant digits. These
547 * are indicated by the <code>'@'</code> and <code>'#'</code>
548 * characters. The minimum number of significant digits is the number
549 * of <code>'@'</code> characters. The maximum number of significant
550 * digits is the number of <code>'@'</code> characters plus the number
551 * of <code>'#'</code> characters following on the right. For
552 * example, the pattern <code>"@@@"</code> indicates exactly 3
553 * significant digits. The pattern <code>"@##"</code> indicates from
554 * 1 to 3 significant digits. Trailing zero digits to the right of
555 * the decimal separator are suppressed after the minimum number of
556 * significant digits have been shown. For example, the pattern
557 * <code>"@##"</code> formats the number 0.1203 as
558 * <code>"0.12"</code>.
560 * <li>If a pattern uses significant digits, it may not contain a
561 * decimal separator, nor the <code>'0'</code> pattern character.
562 * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are
565 * <li>Any number of <code>'#'</code> characters may be prepended to
566 * the left of the leftmost <code>'@'</code> character. These have no
567 * effect on the minimum and maximum significant digits counts, but
568 * may be used to position grouping separators. For example,
569 * <code>"#,#@#"</code> indicates a minimum of one significant digits,
570 * a maximum of two significant digits, and a grouping size of three.
572 * <li>In order to enable significant digits formatting, use a pattern
573 * containing the <code>'@'</code> pattern character. Alternatively,
574 * call setSignificantDigitsUsed(TRUE).
576 * <li>In order to disable significant digits formatting, use a
577 * pattern that does not contain the <code>'@'</code> pattern
578 * character. Alternatively, call setSignificantDigitsUsed(FALSE).
580 * <li>The number of significant digits has no effect on parsing.
582 * <li>Significant digits may be used together with exponential notation. Such
583 * patterns are equivalent to a normal exponential pattern with a minimum and
584 * maximum integer digit count of one, a minimum fraction digit count of
585 * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit
586 * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the
587 * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>.
589 * <li>If signficant digits are in use, then the integer and fraction
590 * digit counts, as set via the API, are ignored. If significant
591 * digits are not in use, then the signficant digit counts, as set via
592 * the API, are ignored.
596 * <p><strong>Padding</strong>
598 * <p>DecimalFormat supports padding the result of
599 * format() to a specific width. Padding may be specified either
600 * through the API or through the pattern syntax. In a pattern the pad escape
601 * character, followed by a single pad character, causes padding to be parsed
602 * and formatted. The pad escape character is '*' in unlocalized patterns, and
603 * can be localized using DecimalFormatSymbols::setSymbol() with a
604 * DecimalFormatSymbols::kPadEscapeSymbol
605 * selector. For example, <code>"$*x#,##0.00"</code> formats 123 to
606 * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>.
609 * <li>When padding is in effect, the width of the positive subpattern,
610 * including prefix and suffix, determines the format width. For example, in
611 * the pattern <code>"* #0 o''clock"</code>, the format width is 10.
613 * <li>The width is counted in 16-bit code units (char16_ts).
615 * <li>Some parameters which usually do not matter have meaning when padding is
616 * used, because the pattern width is significant with padding. In the pattern
617 * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##,"
618 * do not affect the grouping size or maximum integer digits, but they do affect
621 * <li>Padding may be inserted at one of four locations: before the prefix,
622 * after the prefix, before the suffix, or after the suffix. If padding is
623 * specified in any other location, applyPattern()
624 * sets a failing UErrorCode. If there is no prefix,
625 * before the prefix and after the prefix are equivalent, likewise for the
628 * <li>When specified in a pattern, the 32-bit code point immediately
629 * following the pad escape is the pad character. This may be any character,
630 * including a special pattern character. That is, the pad escape
631 * <em>escapes</em> the following character. If there is no character after
632 * the pad escape, then the pattern is illegal.
636 * <p><strong>Rounding</strong>
638 * <p>DecimalFormat supports rounding to a specific increment. For
639 * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the
640 * nearest 0.65 is 1.3. The rounding increment may be specified through the API
641 * or in a pattern. To specify a rounding increment in a pattern, include the
642 * increment in the pattern itself. "#,#50" specifies a rounding increment of
643 * 50. "#,##0.05" specifies a rounding increment of 0.05.
645 * <p>In the absense of an explicit rounding increment numbers are
646 * rounded to their formatted width.
649 * <li>Rounding only affects the string produced by formatting. It does
650 * not affect parsing or change any numerical values.
652 * <li>A <em>rounding mode</em> determines how values are rounded; see
653 * DecimalFormat::ERoundingMode. The default rounding mode is
654 * DecimalFormat::kRoundHalfEven. The rounding mode can only be set
655 * through the API; it can not be set with a pattern.
657 * <li>Some locales use rounding in their currency formats to reflect the
658 * smallest currency denomination.
660 * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
661 * behave identically to digit '0'.
664 * <p><strong>Synchronization</strong>
666 * <p>DecimalFormat objects are not synchronized. Multiple
667 * threads should not access one formatter concurrently.
669 * <p><strong>Subclassing</strong>
671 * <p><em>User subclasses are not supported.</em> While clients may write
672 * subclasses, such code will not necessarily work and will not be
673 * guaranteed to work stably from release to release.
675 class U_I18N_API DecimalFormat
: public NumberFormat
{
689 * Create a DecimalFormat using the default pattern and symbols
690 * for the default locale. This is a convenient way to obtain a
691 * DecimalFormat when internationalization is not the main concern.
693 * To obtain standard formats for a given locale, use the factory methods
694 * on NumberFormat such as createInstance. These factories will
695 * return the most appropriate sub-class of NumberFormat for a given
698 * <strong>NOTE:</strong> New users are strongly encouraged to use
699 * {@link NumberFormatter} instead of DecimalFormat.
700 * @param status Output param set to success/failure code. If the
701 * pattern is invalid this will be set to a failure code.
704 DecimalFormat(UErrorCode
& status
);
707 * Create a DecimalFormat from the given pattern and the symbols
708 * for the default locale. This is a convenient way to obtain a
709 * DecimalFormat when internationalization is not the main concern.
711 * To obtain standard formats for a given locale, use the factory methods
712 * on NumberFormat such as createInstance. These factories will
713 * return the most appropriate sub-class of NumberFormat for a given
716 * <strong>NOTE:</strong> New users are strongly encouraged to use
717 * {@link NumberFormatter} instead of DecimalFormat.
718 * @param pattern A non-localized pattern string.
719 * @param status Output param set to success/failure code. If the
720 * pattern is invalid this will be set to a failure code.
723 DecimalFormat(const UnicodeString
& pattern
,
727 * Create a DecimalFormat from the given pattern and symbols.
728 * Use this constructor when you need to completely customize the
729 * behavior of the format.
731 * To obtain standard formats for a given
732 * locale, use the factory methods on NumberFormat such as
733 * createInstance or createCurrencyInstance. If you need only minor adjustments
734 * to a standard format, you can modify the format returned by
735 * a NumberFormat factory method.
737 * <strong>NOTE:</strong> New users are strongly encouraged to use
738 * {@link NumberFormatter} instead of DecimalFormat.
740 * @param pattern a non-localized pattern string
741 * @param symbolsToAdopt the set of symbols to be used. The caller should not
742 * delete this object after making this call.
743 * @param status Output param set to success/failure code. If the
744 * pattern is invalid this will be set to a failure code.
747 DecimalFormat( const UnicodeString
& pattern
,
748 DecimalFormatSymbols
* symbolsToAdopt
,
751 #ifndef U_HIDE_INTERNAL_API
753 * This API is for ICU use only.
754 * Create a DecimalFormat from the given pattern, symbols, and style.
756 * @param pattern a non-localized pattern string
757 * @param symbolsToAdopt the set of symbols to be used. The caller should not
758 * delete this object after making this call.
759 * @param style style of decimal format
760 * @param status Output param set to success/failure code. If the
761 * pattern is invalid this will be set to a failure code.
764 DecimalFormat( const UnicodeString
& pattern
,
765 DecimalFormatSymbols
* symbolsToAdopt
,
766 UNumberFormatStyle style
,
769 #if UCONFIG_HAVE_PARSEALLINPUT
773 void setParseAllInput(UNumberFormatAttributeValue value
);
776 #endif /* U_HIDE_INTERNAL_API */
780 * Set an integer attribute on this DecimalFormat.
781 * May return U_UNSUPPORTED_ERROR if this instance does not support
782 * the specified attribute.
783 * @param attr the attribute to set
784 * @param newvalue new value
785 * @param status the error type
786 * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
789 virtual DecimalFormat
& setAttribute( UNumberFormatAttribute attr
,
795 * May return U_UNSUPPORTED_ERROR if this instance does not support
796 * the specified attribute.
797 * @param attr the attribute to set
798 * @param status the error type
799 * @return the attribute value. Undefined if there is an error.
802 virtual int32_t getAttribute( UNumberFormatAttribute attr
,
803 UErrorCode
&status
) const;
807 * Set whether or not grouping will be used in this format.
808 * @param newValue True, grouping will be used in this format.
809 * @see getGroupingUsed
812 virtual void setGroupingUsed(UBool newValue
);
815 * Sets whether or not numbers should be parsed as integers only.
816 * @param value set True, this format will parse numbers as integers
818 * @see isParseIntegerOnly
821 virtual void setParseIntegerOnly(UBool value
);
824 * Set a particular UDisplayContext value in the formatter, such as
825 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
826 * @param value The UDisplayContext value to set.
827 * @param status Input/output status. If at entry this indicates a failure
828 * status, the function will do nothing; otherwise this will be
829 * updated with any new status from the function.
832 virtual void setContext(UDisplayContext value
, UErrorCode
& status
);
835 * Create a DecimalFormat from the given pattern and symbols.
836 * Use this constructor when you need to completely customize the
837 * behavior of the format.
839 * To obtain standard formats for a given
840 * locale, use the factory methods on NumberFormat such as
841 * createInstance or createCurrencyInstance. If you need only minor adjustments
842 * to a standard format, you can modify the format returned by
843 * a NumberFormat factory method.
845 * <strong>NOTE:</strong> New users are strongly encouraged to use
846 * {@link NumberFormatter} instead of DecimalFormat.
848 * @param pattern a non-localized pattern string
849 * @param symbolsToAdopt the set of symbols to be used. The caller should not
850 * delete this object after making this call.
851 * @param parseError Output param to receive errors occured during parsing
852 * @param status Output param set to success/failure code. If the
853 * pattern is invalid this will be set to a failure code.
856 DecimalFormat( const UnicodeString
& pattern
,
857 DecimalFormatSymbols
* symbolsToAdopt
,
858 UParseError
& parseError
,
861 * Create a DecimalFormat from the given pattern and symbols.
862 * Use this constructor when you need to completely customize the
863 * behavior of the format.
865 * To obtain standard formats for a given
866 * locale, use the factory methods on NumberFormat such as
867 * createInstance or createCurrencyInstance. If you need only minor adjustments
868 * to a standard format, you can modify the format returned by
869 * a NumberFormat factory method.
871 * <strong>NOTE:</strong> New users are strongly encouraged to use
872 * {@link NumberFormatter} instead of DecimalFormat.
874 * @param pattern a non-localized pattern string
875 * @param symbols the set of symbols to be used
876 * @param status Output param set to success/failure code. If the
877 * pattern is invalid this will be set to a failure code.
880 DecimalFormat( const UnicodeString
& pattern
,
881 const DecimalFormatSymbols
& symbols
,
887 * @param source the DecimalFormat object to be copied from.
890 DecimalFormat(const DecimalFormat
& source
);
893 * Assignment operator.
895 * @param rhs the DecimalFormat object to be copied.
898 DecimalFormat
& operator=(const DecimalFormat
& rhs
);
904 virtual ~DecimalFormat();
907 * Clone this Format object polymorphically. The caller owns the
908 * result and should delete it when done.
910 * @return a polymorphic copy of this DecimalFormat.
913 virtual Format
* clone(void) const;
916 * Return true if the given Format objects are semantically equal.
917 * Objects of different subclasses are considered unequal.
919 * @param other the object to be compared with.
920 * @return true if the given Format objects are semantically equal.
923 virtual UBool
operator==(const Format
& other
) const;
926 using NumberFormat::format
;
929 * Format a double or long number using base-10 representation.
931 * @param number The value to be formatted.
932 * @param appendTo Output parameter to receive result.
933 * Result is appended to existing contents.
934 * @param pos On input: an alignment field, if desired.
935 * On output: the offsets of the alignment field.
936 * @return Reference to 'appendTo' parameter.
939 virtual UnicodeString
& format(double number
,
940 UnicodeString
& appendTo
,
941 FieldPosition
& pos
) const;
945 * Format a double or long number using base-10 representation.
947 * @param number The value to be formatted.
948 * @param appendTo Output parameter to receive result.
949 * Result is appended to existing contents.
950 * @param pos On input: an alignment field, if desired.
951 * On output: the offsets of the alignment field.
953 * @return Reference to 'appendTo' parameter.
956 virtual UnicodeString
& format(double number
,
957 UnicodeString
& appendTo
,
959 UErrorCode
&status
) const;
962 * Format a double or long number using base-10 representation.
964 * @param number The value to be formatted.
965 * @param appendTo Output parameter to receive result.
966 * Result is appended to existing contents.
967 * @param posIter On return, can be used to iterate over positions
968 * of fields generated by this format call.
970 * @param status Output param filled with success/failure status.
971 * @return Reference to 'appendTo' parameter.
974 virtual UnicodeString
& format(double number
,
975 UnicodeString
& appendTo
,
976 FieldPositionIterator
* posIter
,
977 UErrorCode
& status
) const;
980 * Format a long number using base-10 representation.
982 * @param number The value to be formatted.
983 * @param appendTo Output parameter to receive result.
984 * Result is appended to existing contents.
985 * @param pos On input: an alignment field, if desired.
986 * On output: the offsets of the alignment field.
987 * @return Reference to 'appendTo' parameter.
990 virtual UnicodeString
& format(int32_t number
,
991 UnicodeString
& appendTo
,
992 FieldPosition
& pos
) const;
995 * Format a long number using base-10 representation.
997 * @param number The value to be formatted.
998 * @param appendTo Output parameter to receive result.
999 * Result is appended to existing contents.
1000 * @param pos On input: an alignment field, if desired.
1001 * On output: the offsets of the alignment field.
1002 * @return Reference to 'appendTo' parameter.
1005 virtual UnicodeString
& format(int32_t number
,
1006 UnicodeString
& appendTo
,
1008 UErrorCode
&status
) const;
1011 * Format a long number using base-10 representation.
1013 * @param number The value to be formatted.
1014 * @param appendTo Output parameter to receive result.
1015 * Result is appended to existing contents.
1016 * @param posIter On return, can be used to iterate over positions
1017 * of fields generated by this format call.
1019 * @param status Output param filled with success/failure status.
1020 * @return Reference to 'appendTo' parameter.
1023 virtual UnicodeString
& format(int32_t number
,
1024 UnicodeString
& appendTo
,
1025 FieldPositionIterator
* posIter
,
1026 UErrorCode
& status
) const;
1029 * Format an int64 number using base-10 representation.
1031 * @param number The value to be formatted.
1032 * @param appendTo Output parameter to receive result.
1033 * Result is appended to existing contents.
1034 * @param pos On input: an alignment field, if desired.
1035 * On output: the offsets of the alignment field.
1036 * @return Reference to 'appendTo' parameter.
1039 virtual UnicodeString
& format(int64_t number
,
1040 UnicodeString
& appendTo
,
1041 FieldPosition
& pos
) const;
1044 * Format an int64 number using base-10 representation.
1046 * @param number The value to be formatted.
1047 * @param appendTo Output parameter to receive result.
1048 * Result is appended to existing contents.
1049 * @param pos On input: an alignment field, if desired.
1050 * On output: the offsets of the alignment field.
1051 * @return Reference to 'appendTo' parameter.
1054 virtual UnicodeString
& format(int64_t number
,
1055 UnicodeString
& appendTo
,
1057 UErrorCode
&status
) const;
1060 * Format an int64 number using base-10 representation.
1062 * @param number The value to be formatted.
1063 * @param appendTo Output parameter to receive result.
1064 * Result is appended to existing contents.
1065 * @param posIter On return, can be used to iterate over positions
1066 * of fields generated by this format call.
1068 * @param status Output param filled with success/failure status.
1069 * @return Reference to 'appendTo' parameter.
1072 virtual UnicodeString
& format(int64_t number
,
1073 UnicodeString
& appendTo
,
1074 FieldPositionIterator
* posIter
,
1075 UErrorCode
& status
) const;
1078 * Format a decimal number.
1079 * The syntax of the unformatted number is a "numeric string"
1080 * as defined in the Decimal Arithmetic Specification, available at
1081 * http://speleotrove.com/decimal
1083 * @param number The unformatted number, as a string.
1084 * @param appendTo Output parameter to receive result.
1085 * Result is appended to existing contents.
1086 * @param posIter On return, can be used to iterate over positions
1087 * of fields generated by this format call.
1089 * @param status Output param filled with success/failure status.
1090 * @return Reference to 'appendTo' parameter.
1093 virtual UnicodeString
& format(StringPiece number
,
1094 UnicodeString
& appendTo
,
1095 FieldPositionIterator
* posIter
,
1096 UErrorCode
& status
) const;
1100 * Format a decimal number.
1101 * The number is a DigitList wrapper onto a floating point decimal number.
1102 * The default implementation in NumberFormat converts the decimal number
1103 * to a double and formats that.
1105 * @param number The number, a DigitList format Decimal Floating Point.
1106 * @param appendTo Output parameter to receive result.
1107 * Result is appended to existing contents.
1108 * @param posIter On return, can be used to iterate over positions
1109 * of fields generated by this format call.
1110 * @param status Output param filled with success/failure status.
1111 * @return Reference to 'appendTo' parameter.
1114 virtual UnicodeString
& format(const DigitList
&number
,
1115 UnicodeString
& appendTo
,
1116 FieldPositionIterator
* posIter
,
1117 UErrorCode
& status
) const;
1120 * Format a decimal number.
1121 * @param number The number
1122 * @param appendTo Output parameter to receive result.
1123 * Result is appended to existing contents.
1124 * @param pos On input: an alignment field, if desired.
1125 * On output: the offsets of the alignment field.
1126 * @param status Output param filled with success/failure status.
1127 * @return Reference to 'appendTo' parameter.
1130 virtual UnicodeString
& format(
1131 const VisibleDigitsWithExponent
&number
,
1132 UnicodeString
& appendTo
,
1134 UErrorCode
& status
) const;
1137 * Format a decimal number.
1138 * @param number The number
1139 * @param appendTo Output parameter to receive result.
1140 * Result is appended to existing contents.
1141 * @param posIter On return, can be used to iterate over positions
1142 * of fields generated by this format call.
1143 * @param status Output param filled with success/failure status.
1144 * @return Reference to 'appendTo' parameter.
1147 virtual UnicodeString
& format(
1148 const VisibleDigitsWithExponent
&number
,
1149 UnicodeString
& appendTo
,
1150 FieldPositionIterator
* posIter
,
1151 UErrorCode
& status
) const;
1154 * Format a decimal number.
1155 * The number is a DigitList wrapper onto a floating point decimal number.
1156 * The default implementation in NumberFormat converts the decimal number
1157 * to a double and formats that.
1159 * @param number The number, a DigitList format Decimal Floating Point.
1160 * @param appendTo Output parameter to receive result.
1161 * Result is appended to existing contents.
1162 * @param pos On input: an alignment field, if desired.
1163 * On output: the offsets of the alignment field.
1164 * @param status Output param filled with success/failure status.
1165 * @return Reference to 'appendTo' parameter.
1168 virtual UnicodeString
& format(const DigitList
&number
,
1169 UnicodeString
& appendTo
,
1171 UErrorCode
& status
) const;
1173 using NumberFormat::parse
;
1176 * Parse the given string using this object's choices. The method
1177 * does string comparisons to try to find an optimal match.
1178 * If no object can be parsed, index is unchanged, and NULL is
1179 * returned. The result is returned as the most parsimonious
1180 * type of Formattable that will accomodate all of the
1181 * necessary precision. For example, if the result is exactly 12,
1182 * it will be returned as a long. However, if it is 1.5, it will
1183 * be returned as a double.
1185 * @param text The text to be parsed.
1186 * @param result Formattable to be set to the parse result.
1187 * If parse fails, return contents are undefined.
1188 * @param parsePosition The position to start parsing at on input.
1189 * On output, moved to after the last successfully
1190 * parse character. On parse failure, does not change.
1194 virtual void parse(const UnicodeString
& text
,
1195 Formattable
& result
,
1196 ParsePosition
& parsePosition
) const;
1199 * Parses text from the given string as a currency amount. Unlike
1200 * the parse() method, this method will attempt to parse a generic
1201 * currency name, searching for a match of this object's locale's
1202 * currency display names, or for a 3-letter ISO currency code.
1203 * This method will fail if this format is not a currency format,
1204 * that is, if it does not contain the currency pattern symbol
1205 * (U+00A4) in its prefix or suffix.
1207 * @param text the string to parse
1208 * @param pos input-output position; on input, the position within text
1209 * to match; must have 0 <= pos.getIndex() < text.length();
1210 * on output, the position after the last matched character.
1211 * If the parse fails, the position in unchanged upon output.
1212 * @return if parse succeeds, a pointer to a newly-created CurrencyAmount
1213 * object (owned by the caller) containing information about
1214 * the parsed currency; if parse fails, this is NULL.
1217 virtual CurrencyAmount
* parseCurrency(const UnicodeString
& text
,
1218 ParsePosition
& pos
) const;
1221 * Returns the decimal format symbols, which is generally not changed
1222 * by the programmer or user.
1223 * @return desired DecimalFormatSymbols
1224 * @see DecimalFormatSymbols
1227 virtual const DecimalFormatSymbols
* getDecimalFormatSymbols(void) const;
1230 * Sets the decimal format symbols, which is generally not changed
1231 * by the programmer or user.
1232 * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
1235 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols
* symbolsToAdopt
);
1238 * Sets the decimal format symbols, which is generally not changed
1239 * by the programmer or user.
1240 * @param symbols DecimalFormatSymbols.
1243 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols
& symbols
);
1247 * Returns the currency plural format information,
1248 * which is generally not changed by the programmer or user.
1249 * @return desired CurrencyPluralInfo
1252 virtual const CurrencyPluralInfo
* getCurrencyPluralInfo(void) const;
1255 * Sets the currency plural format information,
1256 * which is generally not changed by the programmer or user.
1257 * @param toAdopt CurrencyPluralInfo to be adopted.
1260 virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo
* toAdopt
);
1263 * Sets the currency plural format information,
1264 * which is generally not changed by the programmer or user.
1265 * @param info Currency Plural Info.
1268 virtual void setCurrencyPluralInfo(const CurrencyPluralInfo
& info
);
1272 * Get the positive prefix.
1274 * @param result Output param which will receive the positive prefix.
1275 * @return A reference to 'result'.
1276 * Examples: +123, $123, sFr123
1279 UnicodeString
& getPositivePrefix(UnicodeString
& result
) const;
1282 * Set the positive prefix.
1284 * @param newValue the new value of the the positive prefix to be set.
1285 * Examples: +123, $123, sFr123
1288 virtual void setPositivePrefix(const UnicodeString
& newValue
);
1291 * Get the negative prefix.
1293 * @param result Output param which will receive the negative prefix.
1294 * @return A reference to 'result'.
1295 * Examples: -123, ($123) (with negative suffix), sFr-123
1298 UnicodeString
& getNegativePrefix(UnicodeString
& result
) const;
1301 * Set the negative prefix.
1303 * @param newValue the new value of the the negative prefix to be set.
1304 * Examples: -123, ($123) (with negative suffix), sFr-123
1307 virtual void setNegativePrefix(const UnicodeString
& newValue
);
1310 * Get the positive suffix.
1312 * @param result Output param which will receive the positive suffix.
1313 * @return A reference to 'result'.
1317 UnicodeString
& getPositiveSuffix(UnicodeString
& result
) const;
1320 * Set the positive suffix.
1322 * @param newValue the new value of the positive suffix to be set.
1326 virtual void setPositiveSuffix(const UnicodeString
& newValue
);
1329 * Get the negative suffix.
1331 * @param result Output param which will receive the negative suffix.
1332 * @return A reference to 'result'.
1333 * Examples: -123%, ($123) (with positive suffixes)
1336 UnicodeString
& getNegativeSuffix(UnicodeString
& result
) const;
1339 * Set the negative suffix.
1341 * @param newValue the new value of the negative suffix to be set.
1345 virtual void setNegativeSuffix(const UnicodeString
& newValue
);
1348 * Get the multiplier for use in percent, permill, etc.
1349 * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1350 * (For Arabic, use arabic percent symbol).
1351 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1353 * @return the multiplier for use in percent, permill, etc.
1354 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1357 int32_t getMultiplier(void) const;
1360 * Set the multiplier for use in percent, permill, etc.
1361 * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
1362 * (For Arabic, use arabic percent symbol).
1363 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
1365 * @param newValue the new value of the multiplier for use in percent, permill, etc.
1366 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
1369 virtual void setMultiplier(int32_t newValue
);
1372 * Get the rounding increment.
1373 * @return A positive rounding increment, or 0.0 if a custom rounding
1374 * increment is not in effect.
1375 * @see #setRoundingIncrement
1376 * @see #getRoundingMode
1377 * @see #setRoundingMode
1380 virtual double getRoundingIncrement(void) const;
1383 * Set the rounding increment. In the absence of a rounding increment,
1384 * numbers will be rounded to the number of digits displayed.
1385 * @param newValue A positive rounding increment, or 0.0 to
1386 * use the default rounding increment.
1387 * Negative increments are equivalent to 0.0.
1388 * @see #getRoundingIncrement
1389 * @see #getRoundingMode
1390 * @see #setRoundingMode
1393 virtual void setRoundingIncrement(double newValue
);
1396 * Get the rounding mode.
1397 * @return A rounding mode
1398 * @see #setRoundingIncrement
1399 * @see #getRoundingIncrement
1400 * @see #setRoundingMode
1403 virtual ERoundingMode
getRoundingMode(void) const;
1406 * Set the rounding mode.
1407 * @param roundingMode A rounding mode
1408 * @see #setRoundingIncrement
1409 * @see #getRoundingIncrement
1410 * @see #getRoundingMode
1413 virtual void setRoundingMode(ERoundingMode roundingMode
);
1416 * Get the width to which the output of format() is padded.
1417 * The width is counted in 16-bit code units.
1418 * @return the format width, or zero if no padding is in effect
1419 * @see #setFormatWidth
1420 * @see #getPadCharacterString
1421 * @see #setPadCharacter
1422 * @see #getPadPosition
1423 * @see #setPadPosition
1426 virtual int32_t getFormatWidth(void) const;
1429 * Set the width to which the output of format() is padded.
1430 * The width is counted in 16-bit code units.
1431 * This method also controls whether padding is enabled.
1432 * @param width the width to which to pad the result of
1433 * format(), or zero to disable padding. A negative
1434 * width is equivalent to 0.
1435 * @see #getFormatWidth
1436 * @see #getPadCharacterString
1437 * @see #setPadCharacter
1438 * @see #getPadPosition
1439 * @see #setPadPosition
1442 virtual void setFormatWidth(int32_t width
);
1445 * Get the pad character used to pad to the format width. The
1447 * @return a string containing the pad character. This will always
1448 * have a length of one 32-bit code point.
1449 * @see #setFormatWidth
1450 * @see #getFormatWidth
1451 * @see #setPadCharacter
1452 * @see #getPadPosition
1453 * @see #setPadPosition
1456 virtual UnicodeString
getPadCharacterString() const;
1459 * Set the character used to pad to the format width. If padding
1460 * is not enabled, then this will take effect if padding is later
1462 * @param padChar a string containing the pad charcter. If the string
1463 * has length 0, then the pad characer is set to ' '. Otherwise
1464 * padChar.char32At(0) will be used as the pad character.
1465 * @see #setFormatWidth
1466 * @see #getFormatWidth
1467 * @see #getPadCharacterString
1468 * @see #getPadPosition
1469 * @see #setPadPosition
1472 virtual void setPadCharacter(const UnicodeString
&padChar
);
1475 * Get the position at which padding will take place. This is the location
1476 * at which padding will be inserted if the result of format()
1477 * is shorter than the format width.
1478 * @return the pad position, one of kPadBeforePrefix,
1479 * kPadAfterPrefix, kPadBeforeSuffix, or
1481 * @see #setFormatWidth
1482 * @see #getFormatWidth
1483 * @see #setPadCharacter
1484 * @see #getPadCharacterString
1485 * @see #setPadPosition
1486 * @see #EPadPosition
1489 virtual EPadPosition
getPadPosition(void) const;
1492 * Set the position at which padding will take place. This is the location
1493 * at which padding will be inserted if the result of format()
1494 * is shorter than the format width. This has no effect unless padding is
1496 * @param padPos the pad position, one of kPadBeforePrefix,
1497 * kPadAfterPrefix, kPadBeforeSuffix, or
1499 * @see #setFormatWidth
1500 * @see #getFormatWidth
1501 * @see #setPadCharacter
1502 * @see #getPadCharacterString
1503 * @see #getPadPosition
1504 * @see #EPadPosition
1507 virtual void setPadPosition(EPadPosition padPos
);
1510 * Return whether or not scientific notation is used.
1511 * @return TRUE if this object formats and parses scientific notation
1512 * @see #setScientificNotation
1513 * @see #getMinimumExponentDigits
1514 * @see #setMinimumExponentDigits
1515 * @see #isExponentSignAlwaysShown
1516 * @see #setExponentSignAlwaysShown
1519 virtual UBool
isScientificNotation(void) const;
1522 * Set whether or not scientific notation is used. When scientific notation
1523 * is used, the effective maximum number of integer digits is <= 8. If the
1524 * maximum number of integer digits is set to more than 8, the effective
1525 * maximum will be 1. This allows this call to generate a 'default' scientific
1526 * number format without additional changes.
1527 * @param useScientific TRUE if this object formats and parses scientific
1529 * @see #isScientificNotation
1530 * @see #getMinimumExponentDigits
1531 * @see #setMinimumExponentDigits
1532 * @see #isExponentSignAlwaysShown
1533 * @see #setExponentSignAlwaysShown
1536 virtual void setScientificNotation(UBool useScientific
);
1539 * Return the minimum exponent digits that will be shown.
1540 * @return the minimum exponent digits that will be shown
1541 * @see #setScientificNotation
1542 * @see #isScientificNotation
1543 * @see #setMinimumExponentDigits
1544 * @see #isExponentSignAlwaysShown
1545 * @see #setExponentSignAlwaysShown
1548 virtual int8_t getMinimumExponentDigits(void) const;
1551 * Set the minimum exponent digits that will be shown. This has no
1552 * effect unless scientific notation is in use.
1553 * @param minExpDig a value >= 1 indicating the fewest exponent digits
1554 * that will be shown. Values less than 1 will be treated as 1.
1555 * @see #setScientificNotation
1556 * @see #isScientificNotation
1557 * @see #getMinimumExponentDigits
1558 * @see #isExponentSignAlwaysShown
1559 * @see #setExponentSignAlwaysShown
1562 virtual void setMinimumExponentDigits(int8_t minExpDig
);
1565 * Return whether the exponent sign is always shown.
1566 * @return TRUE if the exponent is always prefixed with either the
1567 * localized minus sign or the localized plus sign, false if only negative
1568 * exponents are prefixed with the localized minus sign.
1569 * @see #setScientificNotation
1570 * @see #isScientificNotation
1571 * @see #setMinimumExponentDigits
1572 * @see #getMinimumExponentDigits
1573 * @see #setExponentSignAlwaysShown
1576 virtual UBool
isExponentSignAlwaysShown(void) const;
1579 * Set whether the exponent sign is always shown. This has no effect
1580 * unless scientific notation is in use.
1581 * @param expSignAlways TRUE if the exponent is always prefixed with either
1582 * the localized minus sign or the localized plus sign, false if only
1583 * negative exponents are prefixed with the localized minus sign.
1584 * @see #setScientificNotation
1585 * @see #isScientificNotation
1586 * @see #setMinimumExponentDigits
1587 * @see #getMinimumExponentDigits
1588 * @see #isExponentSignAlwaysShown
1591 virtual void setExponentSignAlwaysShown(UBool expSignAlways
);
1594 * Return the grouping size. Grouping size is the number of digits between
1595 * grouping separators in the integer portion of a number. For example,
1596 * in the number "123,456.78", the grouping size is 3.
1598 * @return the grouping size.
1599 * @see setGroupingSize
1600 * @see NumberFormat::isGroupingUsed
1601 * @see DecimalFormatSymbols::getGroupingSeparator
1604 int32_t getGroupingSize(void) const;
1607 * Set the grouping size. Grouping size is the number of digits between
1608 * grouping separators in the integer portion of a number. For example,
1609 * in the number "123,456.78", the grouping size is 3.
1611 * @param newValue the new value of the grouping size.
1612 * @see getGroupingSize
1613 * @see NumberFormat::setGroupingUsed
1614 * @see DecimalFormatSymbols::setGroupingSeparator
1617 virtual void setGroupingSize(int32_t newValue
);
1620 * Return the secondary grouping size. In some locales one
1621 * grouping interval is used for the least significant integer
1622 * digits (the primary grouping size), and another is used for all
1623 * others (the secondary grouping size). A formatter supporting a
1624 * secondary grouping size will return a positive integer unequal
1625 * to the primary grouping size returned by
1626 * getGroupingSize(). For example, if the primary
1627 * grouping size is 4, and the secondary grouping size is 2, then
1628 * the number 123456789 formats as "1,23,45,6789", and the pattern
1629 * appears as "#,##,###0".
1630 * @return the secondary grouping size, or a value less than
1631 * one if there is none
1632 * @see setSecondaryGroupingSize
1633 * @see NumberFormat::isGroupingUsed
1634 * @see DecimalFormatSymbols::getGroupingSeparator
1637 int32_t getSecondaryGroupingSize(void) const;
1640 * Set the secondary grouping size. If set to a value less than 1,
1641 * then secondary grouping is turned off, and the primary grouping
1642 * size is used for all intervals, not just the least significant.
1644 * @param newValue the new value of the secondary grouping size.
1645 * @see getSecondaryGroupingSize
1646 * @see NumberFormat#setGroupingUsed
1647 * @see DecimalFormatSymbols::setGroupingSeparator
1650 virtual void setSecondaryGroupingSize(int32_t newValue
);
1652 #ifndef U_HIDE_INTERNAL_API
1655 * Returns the minimum number of grouping digits.
1656 * Grouping separators are output if there are at least this many
1657 * digits to the left of the first (rightmost) grouping separator,
1658 * that is, there are at least (minimum grouping + grouping size) integer digits.
1659 * (Subject to isGroupingUsed().)
1661 * For example, if this value is 2, and the grouping size is 3, then
1662 * 9999 -> "9999" and 10000 -> "10,000"
1664 * This is a technology preview. This API may change behavior or may be removed.
1666 * The default value for this attribute is 0.
1667 * A value of 1, 0, or lower, means that the use of grouping separators
1668 * only depends on the grouping size (and on isGroupingUsed()).
1669 * Currently, the corresponding CLDR data is not used; this is likely to change.
1671 * @see setMinimumGroupingDigits
1672 * @see getGroupingSize
1673 * @internal technology preview
1675 int32_t getMinimumGroupingDigits() const;
1677 #endif /* U_HIDE_INTERNAL_API */
1679 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following draft method since it is virtual. */
1681 * Sets the minimum grouping digits. Setting to a value less than or
1682 * equal to 1 turns off minimum grouping digits.
1684 * @param newValue the new value of minimum grouping digits.
1685 * @see getMinimumGroupingDigits
1686 * @internal technology preview
1688 virtual void setMinimumGroupingDigits(int32_t newValue
);
1692 * Allows you to get the behavior of the decimal separator with integers.
1693 * (The decimal separator will always appear with decimals.)
1695 * @return TRUE if the decimal separator always appear with decimals.
1696 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1699 UBool
isDecimalSeparatorAlwaysShown(void) const;
1702 * Allows you to set the behavior of the decimal separator with integers.
1703 * (The decimal separator will always appear with decimals.)
1705 * @param newValue set TRUE if the decimal separator will always appear with decimals.
1706 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
1709 virtual void setDecimalSeparatorAlwaysShown(UBool newValue
);
1712 * Allows you to get the parse behavior of the pattern decimal mark.
1714 * @return TRUE if input must contain a match to decimal mark in pattern
1717 UBool
isDecimalPatternMatchRequired(void) const;
1720 * Allows you to set the behavior of the pattern decimal mark.
1722 * if TRUE, the input must have a decimal mark if one was specified in the pattern. When
1723 * FALSE the decimal mark may be omitted from the input.
1725 * @param newValue set TRUE if input must contain a match to decimal mark in pattern
1728 virtual void setDecimalPatternMatchRequired(UBool newValue
);
1732 * Synthesizes a pattern string that represents the current state
1733 * of this Format object.
1735 * @param result Output param which will receive the pattern.
1736 * Previous contents are deleted.
1737 * @return A reference to 'result'.
1741 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
1744 * Synthesizes a localized pattern string that represents the current
1745 * state of this Format object.
1747 * @param result Output param which will receive the localized pattern.
1748 * Previous contents are deleted.
1749 * @return A reference to 'result'.
1753 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
) const;
1756 * Apply the given pattern to this Format object. A pattern is a
1757 * short-hand specification for the various formatting properties.
1758 * These properties can also be changed individually through the
1759 * various setter methods.
1761 * There is no limit to integer digits are set
1762 * by this routine, since that is the typical end-user desire;
1763 * use setMaximumInteger if you want to set a real value.
1764 * For negative numbers, use a second pattern, separated by a semicolon
1766 * . Example "#,#00.0#" -> 1,234.56
1768 * This means a minimum of 2 integer digits, 1 fraction digit, and
1769 * a maximum of 2 fraction digits.
1771 * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1773 * In negative patterns, the minimum and maximum counts are ignored;
1774 * these are presumed to be set in the positive pattern.
1776 * @param pattern The pattern to be applied.
1777 * @param parseError Struct to recieve information on position
1778 * of error if an error is encountered
1779 * @param status Output param set to success/failure code on
1780 * exit. If the pattern is invalid, this will be
1781 * set to a failure result.
1784 virtual void applyPattern(const UnicodeString
& pattern
,
1785 UParseError
& parseError
,
1786 UErrorCode
& status
);
1789 * @param pattern The pattern to be applied.
1790 * @param status Output param set to success/failure code on
1791 * exit. If the pattern is invalid, this will be
1792 * set to a failure result.
1795 virtual void applyPattern(const UnicodeString
& pattern
,
1796 UErrorCode
& status
);
1799 * Apply the given pattern to this Format object. The pattern
1800 * is assumed to be in a localized notation. A pattern is a
1801 * short-hand specification for the various formatting properties.
1802 * These properties can also be changed individually through the
1803 * various setter methods.
1805 * There is no limit to integer digits are set
1806 * by this routine, since that is the typical end-user desire;
1807 * use setMaximumInteger if you want to set a real value.
1808 * For negative numbers, use a second pattern, separated by a semicolon
1810 * . Example "#,#00.0#" -> 1,234.56
1812 * This means a minimum of 2 integer digits, 1 fraction digit, and
1813 * a maximum of 2 fraction digits.
1815 * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
1817 * In negative patterns, the minimum and maximum counts are ignored;
1818 * these are presumed to be set in the positive pattern.
1820 * @param pattern The localized pattern to be applied.
1821 * @param parseError Struct to recieve information on position
1822 * of error if an error is encountered
1823 * @param status Output param set to success/failure code on
1824 * exit. If the pattern is invalid, this will be
1825 * set to a failure result.
1828 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1829 UParseError
& parseError
,
1830 UErrorCode
& status
);
1833 * Apply the given pattern to this Format object.
1835 * @param pattern The localized pattern to be applied.
1836 * @param status Output param set to success/failure code on
1837 * exit. If the pattern is invalid, this will be
1838 * set to a failure result.
1841 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
1842 UErrorCode
& status
);
1846 * Sets the maximum number of digits allowed in the integer portion of a
1847 * number. This override limits the integer digit count to 309.
1849 * @param newValue the new value of the maximum number of digits
1850 * allowed in the integer portion of a number.
1851 * @see NumberFormat#setMaximumIntegerDigits
1854 virtual void setMaximumIntegerDigits(int32_t newValue
);
1857 * Sets the minimum number of digits allowed in the integer portion of a
1858 * number. This override limits the integer digit count to 309.
1860 * @param newValue the new value of the minimum number of digits
1861 * allowed in the integer portion of a number.
1862 * @see NumberFormat#setMinimumIntegerDigits
1865 virtual void setMinimumIntegerDigits(int32_t newValue
);
1868 * Sets the maximum number of digits allowed in the fraction portion of a
1869 * number. This override limits the fraction digit count to 340.
1871 * @param newValue the new value of the maximum number of digits
1872 * allowed in the fraction portion of a number.
1873 * @see NumberFormat#setMaximumFractionDigits
1876 virtual void setMaximumFractionDigits(int32_t newValue
);
1879 * Sets the minimum number of digits allowed in the fraction portion of a
1880 * number. This override limits the fraction digit count to 340.
1882 * @param newValue the new value of the minimum number of digits
1883 * allowed in the fraction portion of a number.
1884 * @see NumberFormat#setMinimumFractionDigits
1887 virtual void setMinimumFractionDigits(int32_t newValue
);
1890 * Returns the minimum number of significant digits that will be
1891 * displayed. This value has no effect unless areSignificantDigitsUsed()
1893 * @return the fewest significant digits that will be shown
1896 int32_t getMinimumSignificantDigits() const;
1899 * Returns the maximum number of significant digits that will be
1900 * displayed. This value has no effect unless areSignificantDigitsUsed()
1902 * @return the most significant digits that will be shown
1905 int32_t getMaximumSignificantDigits() const;
1908 * Sets the minimum number of significant digits that will be
1909 * displayed. If <code>min</code> is less than one then it is set
1910 * to one. If the maximum significant digits count is less than
1911 * <code>min</code>, then it is set to <code>min</code>.
1912 * This function also enables the use of significant digits
1913 * by this formatter - areSignificantDigitsUsed() will return TRUE.
1914 * @see #areSignificantDigitsUsed
1915 * @param min the fewest significant digits to be shown
1918 void setMinimumSignificantDigits(int32_t min
);
1921 * Sets the maximum number of significant digits that will be
1922 * displayed. If <code>max</code> is less than one then it is set
1923 * to one. If the minimum significant digits count is greater
1924 * than <code>max</code>, then it is set to <code>max</code>.
1925 * This function also enables the use of significant digits
1926 * by this formatter - areSignificantDigitsUsed() will return TRUE.
1927 * @see #areSignificantDigitsUsed
1928 * @param max the most significant digits to be shown
1931 void setMaximumSignificantDigits(int32_t max
);
1934 * Returns true if significant digits are in use, or false if
1935 * integer and fraction digit counts are in use.
1936 * @return true if significant digits are in use
1939 UBool
areSignificantDigitsUsed() const;
1942 * Sets whether significant digits are in use, or integer and
1943 * fraction digit counts are in use.
1944 * @param useSignificantDigits true to use significant digits, or
1945 * false to use integer and fraction digit counts
1948 void setSignificantDigitsUsed(UBool useSignificantDigits
);
1952 * Sets the currency used to display currency
1953 * amounts. This takes effect immediately, if this format is a
1954 * currency format. If this format is not a currency format, then
1955 * the currency is used if and when this object becomes a
1956 * currency format through the application of a new pattern.
1957 * @param theCurrency a 3-letter ISO code indicating new currency
1958 * to use. It need not be null-terminated. May be the empty
1959 * string or NULL to indicate no currency.
1960 * @param ec input-output error code
1963 virtual void setCurrency(const char16_t* theCurrency
, UErrorCode
& ec
);
1966 * Sets the currency used to display currency amounts. See
1967 * setCurrency(const char16_t*, UErrorCode&).
1968 * @deprecated ICU 3.0. Use setCurrency(const char16_t*, UErrorCode&).
1970 virtual void setCurrency(const char16_t* theCurrency
);
1973 * Sets the <tt>Currency Context</tt> object used to display currency.
1974 * This takes effect immediately, if this format is a
1976 * @param currencyContext new currency context object to use.
1979 void setCurrencyUsage(UCurrencyUsage newUsage
, UErrorCode
* ec
);
1982 * Returns the <tt>Currency Context</tt> object used to display currency
1985 UCurrencyUsage
getCurrencyUsage() const;
1988 #ifndef U_HIDE_DEPRECATED_API
1990 * The resource tags we use to retrieve decimal format data from
1991 * locale resource bundles.
1992 * @deprecated ICU 3.4. This string has no public purpose. Please don't use it.
1994 static const char fgNumberPatterns
[];
1995 #endif // U_HIDE_DEPRECATED_API
1997 #ifndef U_HIDE_INTERNAL_API
1999 * Get a FixedDecimal corresponding to a double as it would be
2000 * formatted by this DecimalFormat.
2001 * Internal, not intended for public use.
2004 FixedDecimal
getFixedDecimal(double number
, UErrorCode
&status
) const;
2007 * Get a FixedDecimal corresponding to a formattable as it would be
2008 * formatted by this DecimalFormat.
2009 * Internal, not intended for public use.
2012 FixedDecimal
getFixedDecimal(const Formattable
&number
, UErrorCode
&status
) const;
2015 * Get a FixedDecimal corresponding to a DigitList as it would be
2016 * formatted by this DecimalFormat. Note: the DigitList may be modified.
2017 * Internal, not intended for public use.
2020 FixedDecimal
getFixedDecimal(DigitList
&number
, UErrorCode
&status
) const;
2023 * Get a VisibleDigitsWithExponent corresponding to a double
2024 * as it would be formatted by this DecimalFormat.
2025 * Internal, not intended for public use.
2028 VisibleDigitsWithExponent
&initVisibleDigitsWithExponent(
2030 VisibleDigitsWithExponent
&digits
,
2031 UErrorCode
&status
) const;
2034 * Get a VisibleDigitsWithExponent corresponding to a formattable
2035 * as it would be formatted by this DecimalFormat.
2036 * Internal, not intended for public use.
2039 VisibleDigitsWithExponent
&initVisibleDigitsWithExponent(
2040 const Formattable
&number
,
2041 VisibleDigitsWithExponent
&digits
,
2042 UErrorCode
&status
) const;
2045 * Get a VisibleDigitsWithExponent corresponding to a DigitList
2046 * as it would be formatted by this DecimalFormat.
2047 * Note: the DigitList may be modified.
2048 * Internal, not intended for public use.
2051 VisibleDigitsWithExponent
&initVisibleDigitsWithExponent(
2053 VisibleDigitsWithExponent
&digits
,
2054 UErrorCode
&status
) const;
2056 #endif /* U_HIDE_INTERNAL_API */
2061 * Return the class ID for this class. This is useful only for
2062 * comparing to a return value from getDynamicClassID(). For example:
2064 * . Base* polymorphic_pointer = createPolymorphicObject();
2065 * . if (polymorphic_pointer->getDynamicClassID() ==
2066 * . Derived::getStaticClassID()) ...
2068 * @return The class ID for all objects of this class.
2071 static UClassID U_EXPORT2
getStaticClassID(void);
2074 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
2075 * This method is to implement a simple version of RTTI, since not all
2076 * C++ compilers support genuine RTTI. Polymorphic operator==() and
2077 * clone() methods call this method.
2079 * @return The class ID for this object. All objects of a
2080 * given class have the same class ID. Objects of
2081 * other classes have different class IDs.
2084 virtual UClassID
getDynamicClassID(void) const;
2088 DecimalFormat(); // default constructor not implemented
2091 * Initialize all fields of a new DecimalFormatter to a safe default value.
2092 * Common code for use by constructors.
2097 * Do real work of constructing a new DecimalFormat.
2099 void construct(UErrorCode
& status
,
2100 UParseError
& parseErr
,
2101 const UnicodeString
* pattern
= 0,
2102 DecimalFormatSymbols
* symbolsToAdopt
= 0
2105 void handleCurrencySignInPattern(UErrorCode
& status
);
2107 void parse(const UnicodeString
& text
,
2108 Formattable
& result
,
2110 char16_t* currency
) const;
2114 fgStatusLength
// Leave last in list.
2117 UBool
subparse(const UnicodeString
& text
,
2118 const UnicodeString
* negPrefix
,
2119 const UnicodeString
* negSuffix
,
2120 const UnicodeString
* posPrefix
,
2121 const UnicodeString
* posSuffix
,
2122 UBool complexCurrencyParsing
,
2124 ParsePosition
& parsePosition
,
2125 DigitList
& digits
, UBool
* status
,
2126 char16_t* currency
) const;
2128 // Mixed style parsing for currency.
2129 // It parses against the current currency pattern
2130 // using complex affix comparison
2131 // parses against the currency plural patterns using complex affix comparison,
2132 // and parses against the current pattern using simple affix comparison.
2133 UBool
parseForCurrency(const UnicodeString
& text
,
2134 ParsePosition
& parsePosition
,
2137 char16_t* currency
) const;
2139 int32_t skipPadding(const UnicodeString
& text
, int32_t position
) const;
2141 int32_t compareAffix(const UnicodeString
& input
,
2145 const UnicodeString
* affixPat
,
2146 UBool complexCurrencyParsing
,
2148 char16_t* currency
) const;
2150 static UnicodeString
& trimMarksFromAffix(const UnicodeString
& affix
, UnicodeString
& trimmedAffix
);
2152 UBool
equalWithSignCompatibility(UChar32 lhs
, UChar32 rhs
) const;
2154 int32_t compareSimpleAffix(const UnicodeString
& affix
,
2155 const UnicodeString
& input
,
2157 UBool lenient
) const;
2159 static int32_t skipPatternWhiteSpace(const UnicodeString
& text
, int32_t pos
);
2161 static int32_t skipUWhiteSpace(const UnicodeString
& text
, int32_t pos
);
2163 static int32_t skipUWhiteSpaceAndMarks(const UnicodeString
& text
, int32_t pos
);
2165 static int32_t skipBidiMarks(const UnicodeString
& text
, int32_t pos
);
2167 int32_t compareComplexAffix(const UnicodeString
& affixPat
,
2168 const UnicodeString
& input
,
2171 char16_t* currency
) const;
2173 static int32_t match(const UnicodeString
& text
, int32_t pos
, UChar32 ch
);
2175 static int32_t match(const UnicodeString
& text
, int32_t pos
, const UnicodeString
& str
);
2177 static UBool
matchSymbol(const UnicodeString
&text
, int32_t position
, int32_t length
, const UnicodeString
&symbol
,
2178 UnicodeSet
*sset
, UChar32 schar
);
2180 static UBool
matchDecimal(UChar32 symbolChar
,
2181 UBool sawDecimal
, UChar32 sawDecimalChar
,
2182 const UnicodeSet
*sset
, UChar32 schar
);
2184 static UBool
matchGrouping(UChar32 groupingChar
,
2185 UBool sawGrouping
, UChar32 sawGroupingChar
,
2186 const UnicodeSet
*sset
,
2187 UChar32 decimalChar
, const UnicodeSet
*decimalSet
,
2190 // set up currency affix patterns for mix parsing.
2191 // The patterns saved here are the affix patterns of default currency
2192 // pattern and the unique affix patterns of the plural currency patterns.
2193 // Those patterns are used by parseForCurrency().
2194 void setupCurrencyAffixPatterns(UErrorCode
& status
);
2196 // get the currency rounding with respect to currency usage
2197 double getCurrencyRounding(const char16_t* currency
,
2198 UErrorCode
* ec
) const;
2200 // get the currency fraction with respect to currency usage
2201 int getCurrencyFractionDigits(const char16_t* currency
,
2202 UErrorCode
* ec
) const;
2204 // hashtable operations
2205 Hashtable
* initHashForAffixPattern(UErrorCode
& status
);
2207 void deleteHashForAffixPattern();
2209 void copyHashForAffixPattern(const Hashtable
* source
,
2210 Hashtable
* target
, UErrorCode
& status
);
2212 DecimalFormatImpl
*fImpl
;
2219 EnumSet
<UNumberFormatAttribute
,
2220 UNUM_MAX_NONBOOLEAN_ATTRIBUTE
+1,
2221 UNUM_LIMIT_BOOLEAN_ATTRIBUTE
>
2225 // style is only valid when decimal formatter is constructed by
2226 // DecimalFormat(pattern, decimalFormatSymbol, style)
2230 // Affix pattern set for currency.
2231 // It is a set of AffixPatternsForCurrency,
2232 // each element of the set saves the negative prefix pattern,
2233 // negative suffix pattern, positive prefix pattern,
2234 // and positive suffix pattern of a pattern.
2235 // It is used for currency mixed style parsing.
2236 // It is actually is a set.
2237 // The set contains the default currency pattern from the locale,
2238 // and the currency plural patterns.
2239 // Since it is a set, it does not contain duplicated items.
2240 // For example, if 2 currency plural patterns are the same, only one pattern
2241 // is included in the set. When parsing, we do not check whether the plural
2242 // count match or not.
2243 Hashtable
* fAffixPatternsForCurrency
;
2245 // Information needed for DecimalFormat to format/parse currency plural.
2246 CurrencyPluralInfo
* fCurrencyPluralInfo
;
2248 #if UCONFIG_HAVE_PARSEALLINPUT
2249 UNumberFormatAttributeValue fParseAllInput
;
2252 // Decimal Format Static Sets singleton.
2253 const DecimalFormatStaticSets
*fStaticSets
;
2257 #ifndef U_HIDE_INTERNAL_API
2259 * Rounds a value according to the rules of this object.
2262 DigitList
& _round(const DigitList
& number
, DigitList
& adjustedNum
, UBool
& isNegative
, UErrorCode
& status
) const;
2263 #endif /* U_HIDE_INTERNAL_API */
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(char16_t* 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
;
2299 #endif // U_SHOW_CPLUSPLUS_API
2301 #endif /* #if !UCONFIG_NO_FORMATTING */