|
||||
Warning, file /include/unicode/decimfmt.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************** 0005 * Copyright (C) 1997-2016, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ******************************************************************************** 0008 * 0009 * File DECIMFMT.H 0010 * 0011 * Modification History: 0012 * 0013 * Date Name Description 0014 * 02/19/97 aliu Converted from java. 0015 * 03/20/97 clhuang Updated per C++ implementation. 0016 * 04/03/97 aliu Rewrote parsing and formatting completely, and 0017 * cleaned up and debugged. Actually works now. 0018 * 04/17/97 aliu Changed DigitCount to int per code review. 0019 * 07/10/97 helena Made ParsePosition a class and get rid of the function 0020 * hiding problems. 0021 * 09/09/97 aliu Ported over support for exponential formats. 0022 * 07/20/98 stephen Changed documentation 0023 * 01/30/13 emmons Added Scaling methods 0024 ******************************************************************************** 0025 */ 0026 0027 #ifndef DECIMFMT_H 0028 #define DECIMFMT_H 0029 0030 #include "unicode/utypes.h" 0031 0032 #if U_SHOW_CPLUSPLUS_API 0033 0034 /** 0035 * \file 0036 * \brief C++ API: Compatibility APIs for decimal formatting. 0037 */ 0038 0039 #if !UCONFIG_NO_FORMATTING 0040 0041 #include "unicode/dcfmtsym.h" 0042 #include "unicode/numfmt.h" 0043 #include "unicode/locid.h" 0044 #include "unicode/fpositer.h" 0045 #include "unicode/stringpiece.h" 0046 #include "unicode/curramt.h" 0047 #include "unicode/enumset.h" 0048 0049 U_NAMESPACE_BEGIN 0050 0051 class CurrencyPluralInfo; 0052 class CompactDecimalFormat; 0053 0054 namespace number { 0055 class LocalizedNumberFormatter; 0056 namespace impl { 0057 class DecimalQuantity; 0058 struct DecimalFormatFields; 0059 class UFormattedNumberData; 0060 } 0061 } 0062 0063 namespace numparse { 0064 namespace impl { 0065 class NumberParserImpl; 0066 } 0067 } 0068 0069 /** 0070 * **IMPORTANT:** New users are strongly encouraged to see if 0071 * numberformatter.h fits their use case. Although not deprecated, this header 0072 * is provided for backwards compatibility only. 0073 * 0074 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal 0075 * numbers. It has a variety of features designed to make it possible to parse 0076 * and format numbers in any locale, including support for Western, Arabic, or 0077 * Indic digits. It also supports different flavors of numbers, including 0078 * integers ("123"), fixed-point numbers ("123.4"), scientific notation 0079 * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123", 0080 * "123 US dollars"). All of these flavors can be easily localized. 0081 * 0082 * To obtain a NumberFormat for a specific locale (including the default 0083 * locale) call one of NumberFormat's factory methods such as 0084 * createInstance(). Do not call the DecimalFormat constructors directly, unless 0085 * you know what you are doing, since the NumberFormat factory methods may 0086 * return subclasses other than DecimalFormat. 0087 * 0088 * **Example Usage** 0089 * 0090 * \code 0091 * // Normally we would have a GUI with a menu for this 0092 * int32_t locCount; 0093 * const Locale* locales = NumberFormat::getAvailableLocales(locCount); 0094 * 0095 * double myNumber = -1234.56; 0096 * UErrorCode success = U_ZERO_ERROR; 0097 * NumberFormat* form; 0098 * 0099 * // Print out a number with the localized number, currency and percent 0100 * // format for each locale. 0101 * UnicodeString countryName; 0102 * UnicodeString displayName; 0103 * UnicodeString str; 0104 * UnicodeString pattern; 0105 * Formattable fmtable; 0106 * for (int32_t j = 0; j < 3; ++j) { 0107 * cout << endl << "FORMAT " << j << endl; 0108 * for (int32_t i = 0; i < locCount; ++i) { 0109 * if (locales[i].getCountry(countryName).size() == 0) { 0110 * // skip language-only 0111 * continue; 0112 * } 0113 * switch (j) { 0114 * case 0: 0115 * form = NumberFormat::createInstance(locales[i], success ); break; 0116 * case 1: 0117 * form = NumberFormat::createCurrencyInstance(locales[i], success ); break; 0118 * default: 0119 * form = NumberFormat::createPercentInstance(locales[i], success ); break; 0120 * } 0121 * if (form) { 0122 * str.remove(); 0123 * pattern = ((DecimalFormat*)form)->toPattern(pattern); 0124 * cout << locales[i].getDisplayName(displayName) << ": " << pattern; 0125 * cout << " -> " << form->format(myNumber,str) << endl; 0126 * form->parse(form->format(myNumber,str), fmtable, success); 0127 * delete form; 0128 * } 0129 * } 0130 * } 0131 * \endcode 0132 * 0133 * **Another example use createInstance(style)** 0134 * 0135 * \code 0136 * // Print out a number using the localized number, currency, 0137 * // percent, scientific, integer, iso currency, and plural currency 0138 * // format for each locale</strong> 0139 * Locale* locale = new Locale("en", "US"); 0140 * double myNumber = 1234.56; 0141 * UErrorCode success = U_ZERO_ERROR; 0142 * UnicodeString str; 0143 * Formattable fmtable; 0144 * for (int j=NumberFormat::kNumberStyle; 0145 * j<=NumberFormat::kPluralCurrencyStyle; 0146 * ++j) { 0147 * NumberFormat* form = NumberFormat::createInstance(locale, j, success); 0148 * str.remove(); 0149 * cout << "format result " << form->format(myNumber, str) << endl; 0150 * format->parse(form->format(myNumber, str), fmtable, success); 0151 * delete form; 0152 * } 0153 * \endcode 0154 * 0155 * 0156 * <p><strong>Patterns</strong> 0157 * 0158 * <p>A DecimalFormat consists of a <em>pattern</em> and a set of 0159 * <em>symbols</em>. The pattern may be set directly using 0160 * applyPattern(), or indirectly using other API methods which 0161 * manipulate aspects of the pattern, such as the minimum number of integer 0162 * digits. The symbols are stored in a DecimalFormatSymbols 0163 * object. When using the NumberFormat factory methods, the 0164 * pattern and symbols are read from ICU's locale data. 0165 * 0166 * <p><strong>Special Pattern Characters</strong> 0167 * 0168 * <p>Many characters in a pattern are taken literally; they are matched during 0169 * parsing and output unchanged during formatting. Special characters, on the 0170 * other hand, stand for other characters, strings, or classes of characters. 0171 * For example, the '#' character is replaced by a localized digit. Often the 0172 * replacement character is the same as the pattern character; in the U.S. locale, 0173 * the ',' grouping character is replaced by ','. However, the replacement is 0174 * still happening, and if the symbols are modified, the grouping character 0175 * changes. Some special characters affect the behavior of the formatter by 0176 * their presence; for example, if the percent character is seen, then the 0177 * value is multiplied by 100 before being displayed. 0178 * 0179 * <p>To insert a special character in a pattern as a literal, that is, without 0180 * any special meaning, the character must be quoted. There are some exceptions to 0181 * this which are noted below. 0182 * 0183 * <p>The characters listed here are used in non-localized patterns. Localized 0184 * patterns use the corresponding characters taken from this formatter's 0185 * DecimalFormatSymbols object instead, and these characters lose 0186 * their special status. Two exceptions are the currency sign and quote, which 0187 * are not localized. 0188 * 0189 * <table border=0 cellspacing=3 cellpadding=0> 0190 * <tr bgcolor="#ccccff"> 0191 * <td align=left><strong>Symbol</strong> 0192 * <td align=left><strong>Location</strong> 0193 * <td align=left><strong>Localized?</strong> 0194 * <td align=left><strong>Meaning</strong> 0195 * <tr valign=top> 0196 * <td><code>0</code> 0197 * <td>Number 0198 * <td>Yes 0199 * <td>Digit 0200 * <tr valign=top bgcolor="#eeeeff"> 0201 * <td><code>1-9</code> 0202 * <td>Number 0203 * <td>Yes 0204 * <td>'1' through '9' indicate rounding. 0205 * <tr valign=top> 0206 * <td><code>\htmlonly@\endhtmlonly</code> <!--doxygen doesn't like @--> 0207 * <td>Number 0208 * <td>No 0209 * <td>Significant digit 0210 * <tr valign=top bgcolor="#eeeeff"> 0211 * <td><code>#</code> 0212 * <td>Number 0213 * <td>Yes 0214 * <td>Digit, zero shows as absent 0215 * <tr valign=top> 0216 * <td><code>.</code> 0217 * <td>Number 0218 * <td>Yes 0219 * <td>Decimal separator or monetary decimal separator 0220 * <tr valign=top bgcolor="#eeeeff"> 0221 * <td><code>-</code> 0222 * <td>Number 0223 * <td>Yes 0224 * <td>Minus sign 0225 * <tr valign=top> 0226 * <td><code>,</code> 0227 * <td>Number 0228 * <td>Yes 0229 * <td>Grouping separator 0230 * <tr valign=top bgcolor="#eeeeff"> 0231 * <td><code>E</code> 0232 * <td>Number 0233 * <td>Yes 0234 * <td>Separates mantissa and exponent in scientific notation. 0235 * <em>Need not be quoted in prefix or suffix.</em> 0236 * <tr valign=top> 0237 * <td><code>+</code> 0238 * <td>Exponent 0239 * <td>Yes 0240 * <td>Prefix positive exponents with localized plus sign. 0241 * <em>Need not be quoted in prefix or suffix.</em> 0242 * <tr valign=top bgcolor="#eeeeff"> 0243 * <td><code>;</code> 0244 * <td>Subpattern boundary 0245 * <td>Yes 0246 * <td>Separates positive and negative subpatterns 0247 * <tr valign=top> 0248 * <td><code>\%</code> 0249 * <td>Prefix or suffix 0250 * <td>Yes 0251 * <td>Multiply by 100 and show as percentage 0252 * <tr valign=top bgcolor="#eeeeff"> 0253 * <td><code>\\u2030</code> 0254 * <td>Prefix or suffix 0255 * <td>Yes 0256 * <td>Multiply by 1000 and show as per mille 0257 * <tr valign=top> 0258 * <td><code>\htmlonly¤\endhtmlonly</code> (<code>\\u00A4</code>) 0259 * <td>Prefix or suffix 0260 * <td>No 0261 * <td>Currency sign, replaced by currency symbol. If 0262 * doubled, replaced by international currency symbol. 0263 * If tripled, replaced by currency plural names, for example, 0264 * "US dollar" or "US dollars" for America. 0265 * If present in a pattern, the monetary decimal separator 0266 * is used instead of the decimal separator. 0267 * <tr valign=top bgcolor="#eeeeff"> 0268 * <td><code>'</code> 0269 * <td>Prefix or suffix 0270 * <td>No 0271 * <td>Used to quote special characters in a prefix or suffix, 0272 * for example, <code>"'#'#"</code> formats 123 to 0273 * <code>"#123"</code>. To create a single quote 0274 * itself, use two in a row: <code>"# o''clock"</code>. 0275 * <tr valign=top> 0276 * <td><code>*</code> 0277 * <td>Prefix or suffix boundary 0278 * <td>Yes 0279 * <td>Pad escape, precedes pad character 0280 * </table> 0281 * 0282 * <p>A DecimalFormat pattern contains a positive and negative 0283 * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a 0284 * prefix, a numeric part, and a suffix. If there is no explicit negative 0285 * subpattern, the negative subpattern is the localized minus sign prefixed to the 0286 * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there 0287 * is an explicit negative subpattern, it serves only to specify the negative 0288 * prefix and suffix; the number of digits, minimal digits, and other 0289 * characteristics are ignored in the negative subpattern. That means that 0290 * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)". 0291 * 0292 * <p>The prefixes, suffixes, and various symbols used for infinity, digits, 0293 * thousands separators, decimal separators, etc. may be set to arbitrary 0294 * values, and they will appear properly during formatting. However, care must 0295 * be taken that the symbols and strings do not conflict, or parsing will be 0296 * unreliable. For example, either the positive and negative prefixes or the 0297 * suffixes must be distinct for parse() to be able 0298 * to distinguish positive from negative values. Another example is that the 0299 * decimal separator and thousands separator should be distinct characters, or 0300 * parsing will be impossible. 0301 * 0302 * <p>The <em>grouping separator</em> is a character that separates clusters of 0303 * integer digits to make large numbers more legible. It commonly used for 0304 * thousands, but in some locales it separates ten-thousands. The <em>grouping 0305 * size</em> is the number of digits between the grouping separators, such as 3 0306 * for "100,000,000" or 4 for "1 0000 0000". There are actually two different 0307 * grouping sizes: One used for the least significant integer digits, the 0308 * <em>primary grouping size</em>, and one used for all others, the 0309 * <em>secondary grouping size</em>. In most locales these are the same, but 0310 * sometimes they are different. For example, if the primary grouping interval 0311 * is 3, and the secondary is 2, then this corresponds to the pattern 0312 * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a 0313 * pattern contains multiple grouping separators, the interval between the last 0314 * one and the end of the integer defines the primary grouping size, and the 0315 * interval between the last two defines the secondary grouping size. All others 0316 * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####". 0317 * 0318 * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause 0319 * DecimalFormat to set a failing UErrorCode. 0320 * 0321 * <p><strong>Pattern BNF</strong> 0322 * 0323 * <pre> 0324 * pattern := subpattern (';' subpattern)? 0325 * subpattern := prefix? number exponent? suffix? 0326 * number := (integer ('.' fraction)?) | sigDigits 0327 * prefix := '\\u0000'..'\\uFFFD' - specialCharacters 0328 * suffix := '\\u0000'..'\\uFFFD' - specialCharacters 0329 * integer := '#'* '0'* '0' 0330 * fraction := '0'* '#'* 0331 * sigDigits := '#'* '@' '@'* '#'* 0332 * exponent := 'E' '+'? '0'* '0' 0333 * padSpec := '*' padChar 0334 * padChar := '\\u0000'..'\\uFFFD' - quote 0335 * 0336 * Notation: 0337 * X* 0 or more instances of X 0338 * X? 0 or 1 instances of X 0339 * X|Y either X or Y 0340 * C..D any character from C up to D, inclusive 0341 * S-T characters in S, except those in T 0342 * </pre> 0343 * The first subpattern is for positive numbers. The second (optional) 0344 * subpattern is for negative numbers. 0345 * 0346 * <p>Not indicated in the BNF syntax above: 0347 * 0348 * <ul><li>The grouping separator ',' can occur inside the integer and 0349 * sigDigits elements, between any two pattern characters of that 0350 * element, as long as the integer or sigDigits element is not 0351 * followed by the exponent element. 0352 * 0353 * <li>Two grouping intervals are recognized: That between the 0354 * decimal point and the first grouping symbol, and that 0355 * between the first and second grouping symbols. These 0356 * intervals are identical in most locales, but in some 0357 * locales they differ. For example, the pattern 0358 * "#,##,###" formats the number 123456789 as 0359 * "12,34,56,789".</li> 0360 * 0361 * <li>The pad specifier <code>padSpec</code> may appear before the prefix, 0362 * after the prefix, before the suffix, after the suffix, or not at all. 0363 * 0364 * <li>In place of '0', the digits '1' through '9' may be used to 0365 * indicate a rounding increment. 0366 * </ul> 0367 * 0368 * <p><strong>Parsing</strong> 0369 * 0370 * <p>DecimalFormat parses all Unicode characters that represent 0371 * decimal digits, as defined by u_charDigitValue(). In addition, 0372 * DecimalFormat also recognizes as digits the ten consecutive 0373 * characters starting with the localized zero digit defined in the 0374 * DecimalFormatSymbols object. During formatting, the 0375 * DecimalFormatSymbols-based digits are output. 0376 * 0377 * <p>During parsing, grouping separators are ignored if in lenient mode; 0378 * otherwise, if present, they must be in appropriate positions. 0379 * 0380 * <p>For currency parsing, the formatter is able to parse every currency 0381 * style formats no matter which style the formatter is constructed with. 0382 * For example, a formatter instance gotten from 0383 * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse 0384 * formats such as "USD1.00" and "3.00 US dollars". 0385 * 0386 * <p>If parse(UnicodeString&,Formattable&,ParsePosition&) 0387 * fails to parse a string, it leaves the parse position unchanged. 0388 * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&) 0389 * indicates parse failure by setting a failing 0390 * UErrorCode. 0391 * 0392 * <p><strong>Formatting</strong> 0393 * 0394 * <p>Formatting is guided by several parameters, all of which can be 0395 * specified either using a pattern or using the API. The following 0396 * description applies to formats that do not use <a href="#sci">scientific 0397 * notation</a> or <a href="#sigdig">significant digits</a>. 0398 * 0399 * <ul><li>If the number of actual integer digits exceeds the 0400 * <em>maximum integer digits</em>, then only the least significant 0401 * digits are shown. For example, 1997 is formatted as "97" if the 0402 * maximum integer digits is set to 2. 0403 * 0404 * <li>If the number of actual integer digits is less than the 0405 * <em>minimum integer digits</em>, then leading zeros are added. For 0406 * example, 1997 is formatted as "01997" if the minimum integer digits 0407 * is set to 5. 0408 * 0409 * <li>If the number of actual fraction digits exceeds the <em>maximum 0410 * fraction digits</em>, then rounding is performed to the 0411 * maximum fraction digits. For example, 0.125 is formatted as "0.12" 0412 * if the maximum fraction digits is 2. This behavior can be changed 0413 * by specifying a rounding increment and/or a rounding mode. 0414 * 0415 * <li>If the number of actual fraction digits is less than the 0416 * <em>minimum fraction digits</em>, then trailing zeros are added. 0417 * For example, 0.125 is formatted as "0.1250" if the minimum fraction 0418 * digits is set to 4. 0419 * 0420 * <li>Trailing fractional zeros are not displayed if they occur 0421 * <em>j</em> positions after the decimal, where <em>j</em> is less 0422 * than the maximum fraction digits. For example, 0.10004 is 0423 * formatted as "0.1" if the maximum fraction digits is four or less. 0424 * </ul> 0425 * 0426 * <p><strong>Special Values</strong> 0427 * 0428 * <p><code>NaN</code> is represented as a single character, typically 0429 * <code>\\uFFFD</code>. This character is determined by the 0430 * DecimalFormatSymbols object. This is the only value for which 0431 * the prefixes and suffixes are not used. 0432 * 0433 * <p>Infinity is represented as a single character, typically 0434 * <code>\\u221E</code>, with the positive or negative prefixes and suffixes 0435 * applied. The infinity character is determined by the 0436 * DecimalFormatSymbols object. 0437 * 0438 * <a name="sci"><strong>Scientific Notation</strong></a> 0439 * 0440 * <p>Numbers in scientific notation are expressed as the product of a mantissa 0441 * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The 0442 * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0), 0443 * but it need not be. DecimalFormat supports arbitrary mantissas. 0444 * DecimalFormat can be instructed to use scientific 0445 * notation through the API or through the pattern. In a pattern, the exponent 0446 * character immediately followed by one or more digit characters indicates 0447 * scientific notation. Example: "0.###E0" formats the number 1234 as 0448 * "1.234E3". 0449 * 0450 * <ul> 0451 * <li>The number of digit characters after the exponent character gives the 0452 * minimum exponent digit count. There is no maximum. Negative exponents are 0453 * formatted using the localized minus sign, <em>not</em> the prefix and suffix 0454 * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix 0455 * positive exponents with a localized plus sign, specify '+' between the 0456 * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0", 0457 * "1E-1", etc. (In localized patterns, use the localized plus sign rather than 0458 * '+'.) 0459 * 0460 * <li>The minimum number of integer digits is achieved by adjusting the 0461 * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This 0462 * only happens if there is no maximum number of integer digits. If there is a 0463 * maximum, then the minimum number of integer digits is fixed at one. 0464 * 0465 * <li>The maximum number of integer digits, if present, specifies the exponent 0466 * grouping. The most common use of this is to generate <em>engineering 0467 * notation</em>, in which the exponent is a multiple of three, e.g., 0468 * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3". 0469 * 0470 * <li>When using scientific notation, the formatter controls the 0471 * digit counts using significant digits logic. The maximum number of 0472 * significant digits limits the total number of integer and fraction 0473 * digits that will be shown in the mantissa; it does not affect 0474 * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3". 0475 * See the section on significant digits for more details. 0476 * 0477 * <li>The number of significant digits shown is determined as 0478 * follows: If areSignificantDigitsUsed() returns false, then the 0479 * minimum number of significant digits shown is one, and the maximum 0480 * number of significant digits shown is the sum of the <em>minimum 0481 * integer</em> and <em>maximum fraction</em> digits, and is 0482 * unaffected by the maximum integer digits. If this sum is zero, 0483 * then all significant digits are shown. If 0484 * areSignificantDigitsUsed() returns true, then the significant digit 0485 * counts are specified by getMinimumSignificantDigits() and 0486 * getMaximumSignificantDigits(). In this case, the number of 0487 * integer digits is fixed at one, and there is no exponent grouping. 0488 * 0489 * <li>Exponential patterns may not contain grouping separators. 0490 * </ul> 0491 * 0492 * <a name="sigdig"><strong>Significant Digits</strong></a> 0493 * 0494 * <code>DecimalFormat</code> has two ways of controlling how many 0495 * digits are shows: (a) significant digits counts, or (b) integer and 0496 * fraction digit counts. Integer and fraction digit counts are 0497 * described above. When a formatter is using significant digits 0498 * counts, the number of integer and fraction digits is not specified 0499 * directly, and the formatter settings for these counts are ignored. 0500 * Instead, the formatter uses however many integer and fraction 0501 * digits are required to display the specified number of significant 0502 * digits. Examples: 0503 * 0504 * <table border=0 cellspacing=3 cellpadding=0> 0505 * <tr bgcolor="#ccccff"> 0506 * <td align=left>Pattern 0507 * <td align=left>Minimum significant digits 0508 * <td align=left>Maximum significant digits 0509 * <td align=left>Number 0510 * <td align=left>Output of format() 0511 * <tr valign=top> 0512 * <td><code>\@\@\@</code> 0513 * <td>3 0514 * <td>3 0515 * <td>12345 0516 * <td><code>12300</code> 0517 * <tr valign=top bgcolor="#eeeeff"> 0518 * <td><code>\@\@\@</code> 0519 * <td>3 0520 * <td>3 0521 * <td>0.12345 0522 * <td><code>0.123</code> 0523 * <tr valign=top> 0524 * <td><code>\@\@##</code> 0525 * <td>2 0526 * <td>4 0527 * <td>3.14159 0528 * <td><code>3.142</code> 0529 * <tr valign=top bgcolor="#eeeeff"> 0530 * <td><code>\@\@##</code> 0531 * <td>2 0532 * <td>4 0533 * <td>1.23004 0534 * <td><code>1.23</code> 0535 * </table> 0536 * 0537 * <ul> 0538 * <li>Significant digit counts may be expressed using patterns that 0539 * specify a minimum and maximum number of significant digits. These 0540 * are indicated by the <code>'@'</code> and <code>'#'</code> 0541 * characters. The minimum number of significant digits is the number 0542 * of <code>'@'</code> characters. The maximum number of significant 0543 * digits is the number of <code>'@'</code> characters plus the number 0544 * of <code>'#'</code> characters following on the right. For 0545 * example, the pattern <code>"@@@"</code> indicates exactly 3 0546 * significant digits. The pattern <code>"@##"</code> indicates from 0547 * 1 to 3 significant digits. Trailing zero digits to the right of 0548 * the decimal separator are suppressed after the minimum number of 0549 * significant digits have been shown. For example, the pattern 0550 * <code>"@##"</code> formats the number 0.1203 as 0551 * <code>"0.12"</code>. 0552 * 0553 * <li>If a pattern uses significant digits, it may not contain a 0554 * decimal separator, nor the <code>'0'</code> pattern character. 0555 * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are 0556 * disallowed. 0557 * 0558 * <li>Any number of <code>'#'</code> characters may be prepended to 0559 * the left of the leftmost <code>'@'</code> character. These have no 0560 * effect on the minimum and maximum significant digits counts, but 0561 * may be used to position grouping separators. For example, 0562 * <code>"#,#@#"</code> indicates a minimum of one significant digits, 0563 * a maximum of two significant digits, and a grouping size of three. 0564 * 0565 * <li>In order to enable significant digits formatting, use a pattern 0566 * containing the <code>'@'</code> pattern character. Alternatively, 0567 * call setSignificantDigitsUsed(true). 0568 * 0569 * <li>In order to disable significant digits formatting, use a 0570 * pattern that does not contain the <code>'@'</code> pattern 0571 * character. Alternatively, call setSignificantDigitsUsed(false). 0572 * 0573 * <li>The number of significant digits has no effect on parsing. 0574 * 0575 * <li>Significant digits may be used together with exponential notation. Such 0576 * patterns are equivalent to a normal exponential pattern with a minimum and 0577 * maximum integer digit count of one, a minimum fraction digit count of 0578 * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit 0579 * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the 0580 * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>. 0581 * 0582 * <li>If significant digits are in use, then the integer and fraction 0583 * digit counts, as set via the API, are ignored. If significant 0584 * digits are not in use, then the significant digit counts, as set via 0585 * the API, are ignored. 0586 * 0587 * </ul> 0588 * 0589 * <p><strong>Padding</strong> 0590 * 0591 * <p>DecimalFormat supports padding the result of 0592 * format() to a specific width. Padding may be specified either 0593 * through the API or through the pattern syntax. In a pattern the pad escape 0594 * character, followed by a single pad character, causes padding to be parsed 0595 * and formatted. The pad escape character is '*' in unlocalized patterns, and 0596 * can be localized using DecimalFormatSymbols::setSymbol() with a 0597 * DecimalFormatSymbols::kPadEscapeSymbol 0598 * selector. For example, <code>"$*x#,##0.00"</code> formats 123 to 0599 * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>. 0600 * 0601 * <ul> 0602 * <li>When padding is in effect, the width of the positive subpattern, 0603 * including prefix and suffix, determines the format width. For example, in 0604 * the pattern <code>"* #0 o''clock"</code>, the format width is 10. 0605 * 0606 * <li>The width is counted in 16-bit code units (char16_ts). 0607 * 0608 * <li>Some parameters which usually do not matter have meaning when padding is 0609 * used, because the pattern width is significant with padding. In the pattern 0610 * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##," 0611 * do not affect the grouping size or maximum integer digits, but they do affect 0612 * the format width. 0613 * 0614 * <li>Padding may be inserted at one of four locations: before the prefix, 0615 * after the prefix, before the suffix, or after the suffix. If padding is 0616 * specified in any other location, applyPattern() 0617 * sets a failing UErrorCode. If there is no prefix, 0618 * before the prefix and after the prefix are equivalent, likewise for the 0619 * suffix. 0620 * 0621 * <li>When specified in a pattern, the 32-bit code point immediately 0622 * following the pad escape is the pad character. This may be any character, 0623 * including a special pattern character. That is, the pad escape 0624 * <em>escapes</em> the following character. If there is no character after 0625 * the pad escape, then the pattern is illegal. 0626 * 0627 * </ul> 0628 * 0629 * <p><strong>Rounding</strong> 0630 * 0631 * <p>DecimalFormat supports rounding to a specific increment. For 0632 * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the 0633 * nearest 0.65 is 1.3. The rounding increment may be specified through the API 0634 * or in a pattern. To specify a rounding increment in a pattern, include the 0635 * increment in the pattern itself. "#,#50" specifies a rounding increment of 0636 * 50. "#,##0.05" specifies a rounding increment of 0.05. 0637 * 0638 * <p>In the absence of an explicit rounding increment numbers are 0639 * rounded to their formatted width. 0640 * 0641 * <ul> 0642 * <li>Rounding only affects the string produced by formatting. It does 0643 * not affect parsing or change any numerical values. 0644 * 0645 * <li>A <em>rounding mode</em> determines how values are rounded; see 0646 * DecimalFormat::ERoundingMode. The default rounding mode is 0647 * DecimalFormat::kRoundHalfEven. The rounding mode can only be set 0648 * through the API; it can not be set with a pattern. 0649 * 0650 * <li>Some locales use rounding in their currency formats to reflect the 0651 * smallest currency denomination. 0652 * 0653 * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise 0654 * behave identically to digit '0'. 0655 * </ul> 0656 * 0657 * <p><strong>Synchronization</strong> 0658 * 0659 * <p>DecimalFormat objects are not synchronized. Multiple 0660 * threads should not access one formatter concurrently. 0661 * 0662 * <p><strong>Subclassing</strong> 0663 * 0664 * <p><em>User subclasses are not supported.</em> While clients may write 0665 * subclasses, such code will not necessarily work and will not be 0666 * guaranteed to work stably from release to release. 0667 */ 0668 class U_I18N_API DecimalFormat : public NumberFormat { 0669 public: 0670 /** 0671 * Pad position. 0672 * @stable ICU 2.4 0673 */ 0674 enum EPadPosition { 0675 kPadBeforePrefix, kPadAfterPrefix, kPadBeforeSuffix, kPadAfterSuffix 0676 }; 0677 0678 /** 0679 * Create a DecimalFormat using the default pattern and symbols 0680 * for the default locale. This is a convenient way to obtain a 0681 * DecimalFormat when internationalization is not the main concern. 0682 * <P> 0683 * To obtain standard formats for a given locale, use the factory methods 0684 * on NumberFormat such as createInstance. These factories will 0685 * return the most appropriate sub-class of NumberFormat for a given 0686 * locale. 0687 * <p> 0688 * <strong>NOTE:</strong> New users are strongly encouraged to use 0689 * #icu::number::NumberFormatter instead of DecimalFormat. 0690 * @param status Output param set to success/failure code. If the 0691 * pattern is invalid this will be set to a failure code. 0692 * @stable ICU 2.0 0693 */ 0694 DecimalFormat(UErrorCode& status); 0695 0696 /** 0697 * Create a DecimalFormat from the given pattern and the symbols 0698 * for the default locale. This is a convenient way to obtain a 0699 * DecimalFormat when internationalization is not the main concern. 0700 * <P> 0701 * To obtain standard formats for a given locale, use the factory methods 0702 * on NumberFormat such as createInstance. These factories will 0703 * return the most appropriate sub-class of NumberFormat for a given 0704 * locale. 0705 * <p> 0706 * <strong>NOTE:</strong> New users are strongly encouraged to use 0707 * #icu::number::NumberFormatter instead of DecimalFormat. 0708 * @param pattern A non-localized pattern string. 0709 * @param status Output param set to success/failure code. If the 0710 * pattern is invalid this will be set to a failure code. 0711 * @stable ICU 2.0 0712 */ 0713 DecimalFormat(const UnicodeString& pattern, UErrorCode& status); 0714 0715 /** 0716 * Create a DecimalFormat from the given pattern and symbols. 0717 * Use this constructor when you need to completely customize the 0718 * behavior of the format. 0719 * <P> 0720 * To obtain standard formats for a given 0721 * locale, use the factory methods on NumberFormat such as 0722 * createInstance or createCurrencyInstance. If you need only minor adjustments 0723 * to a standard format, you can modify the format returned by 0724 * a NumberFormat factory method. 0725 * <p> 0726 * <strong>NOTE:</strong> New users are strongly encouraged to use 0727 * #icu::number::NumberFormatter instead of DecimalFormat. 0728 * 0729 * @param pattern a non-localized pattern string 0730 * @param symbolsToAdopt the set of symbols to be used. The caller should not 0731 * delete this object after making this call. 0732 * @param status Output param set to success/failure code. If the 0733 * pattern is invalid this will be set to a failure code. 0734 * @stable ICU 2.0 0735 */ 0736 DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status); 0737 0738 #ifndef U_HIDE_INTERNAL_API 0739 0740 /** 0741 * This API is for ICU use only. 0742 * Create a DecimalFormat from the given pattern, symbols, and style. 0743 * 0744 * @param pattern a non-localized pattern string 0745 * @param symbolsToAdopt the set of symbols to be used. The caller should not 0746 * delete this object after making this call. 0747 * @param style style of decimal format 0748 * @param status Output param set to success/failure code. If the 0749 * pattern is invalid this will be set to a failure code. 0750 * @internal 0751 */ 0752 DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, 0753 UNumberFormatStyle style, UErrorCode& status); 0754 0755 #if UCONFIG_HAVE_PARSEALLINPUT 0756 0757 /** 0758 * @internal 0759 */ 0760 void setParseAllInput(UNumberFormatAttributeValue value); 0761 0762 #endif 0763 0764 #endif /* U_HIDE_INTERNAL_API */ 0765 0766 private: 0767 0768 /** 0769 * Internal constructor for DecimalFormat; sets up internal fields. All public constructors should 0770 * call this constructor. 0771 */ 0772 DecimalFormat(const DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status); 0773 0774 public: 0775 0776 /** 0777 * Set an integer attribute on this DecimalFormat. 0778 * May return U_UNSUPPORTED_ERROR if this instance does not support 0779 * the specified attribute. 0780 * @param attr the attribute to set 0781 * @param newValue new value 0782 * @param status the error type 0783 * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) ) 0784 * @stable ICU 51 0785 */ 0786 virtual DecimalFormat& setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErrorCode& status); 0787 0788 /** 0789 * Get an integer 0790 * May return U_UNSUPPORTED_ERROR if this instance does not support 0791 * the specified attribute. 0792 * @param attr the attribute to set 0793 * @param status the error type 0794 * @return the attribute value. Undefined if there is an error. 0795 * @stable ICU 51 0796 */ 0797 virtual int32_t getAttribute(UNumberFormatAttribute attr, UErrorCode& status) const; 0798 0799 0800 /** 0801 * Set whether or not grouping will be used in this format. 0802 * @param newValue True, grouping will be used in this format. 0803 * @see getGroupingUsed 0804 * @stable ICU 53 0805 */ 0806 void setGroupingUsed(UBool newValue) override; 0807 0808 /** 0809 * Sets whether or not numbers should be parsed as integers only. 0810 * @param value set True, this format will parse numbers as integers 0811 * only. 0812 * @see isParseIntegerOnly 0813 * @stable ICU 53 0814 */ 0815 void setParseIntegerOnly(UBool value) override; 0816 0817 /** 0818 * Sets whether lenient parsing should be enabled (it is off by default). 0819 * 0820 * @param enable \c true if lenient parsing should be used, 0821 * \c false otherwise. 0822 * @stable ICU 4.8 0823 */ 0824 void setLenient(UBool enable) override; 0825 0826 /** 0827 * Create a DecimalFormat from the given pattern and symbols. 0828 * Use this constructor when you need to completely customize the 0829 * behavior of the format. 0830 * <P> 0831 * To obtain standard formats for a given 0832 * locale, use the factory methods on NumberFormat such as 0833 * createInstance or createCurrencyInstance. If you need only minor adjustments 0834 * to a standard format, you can modify the format returned by 0835 * a NumberFormat factory method. 0836 * <p> 0837 * <strong>NOTE:</strong> New users are strongly encouraged to use 0838 * #icu::number::NumberFormatter instead of DecimalFormat. 0839 * 0840 * @param pattern a non-localized pattern string 0841 * @param symbolsToAdopt the set of symbols to be used. The caller should not 0842 * delete this object after making this call. 0843 * @param parseError Output param to receive errors occurred during parsing 0844 * @param status Output param set to success/failure code. If the 0845 * pattern is invalid this will be set to a failure code. 0846 * @stable ICU 2.0 0847 */ 0848 DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, 0849 UParseError& parseError, UErrorCode& status); 0850 0851 /** 0852 * Create a DecimalFormat from the given pattern and symbols. 0853 * Use this constructor when you need to completely customize the 0854 * behavior of the format. 0855 * <P> 0856 * To obtain standard formats for a given 0857 * locale, use the factory methods on NumberFormat such as 0858 * createInstance or createCurrencyInstance. If you need only minor adjustments 0859 * to a standard format, you can modify the format returned by 0860 * a NumberFormat factory method. 0861 * <p> 0862 * <strong>NOTE:</strong> New users are strongly encouraged to use 0863 * #icu::number::NumberFormatter instead of DecimalFormat. 0864 * 0865 * @param pattern a non-localized pattern string 0866 * @param symbols the set of symbols to be used 0867 * @param status Output param set to success/failure code. If the 0868 * pattern is invalid this will be set to a failure code. 0869 * @stable ICU 2.0 0870 */ 0871 DecimalFormat(const UnicodeString& pattern, const DecimalFormatSymbols& symbols, UErrorCode& status); 0872 0873 /** 0874 * Copy constructor. 0875 * 0876 * @param source the DecimalFormat object to be copied from. 0877 * @stable ICU 2.0 0878 */ 0879 DecimalFormat(const DecimalFormat& source); 0880 0881 /** 0882 * Assignment operator. 0883 * 0884 * @param rhs the DecimalFormat object to be copied. 0885 * @stable ICU 2.0 0886 */ 0887 DecimalFormat& operator=(const DecimalFormat& rhs); 0888 0889 /** 0890 * Destructor. 0891 * @stable ICU 2.0 0892 */ 0893 ~DecimalFormat() override; 0894 0895 /** 0896 * Clone this Format object polymorphically. The caller owns the 0897 * result and should delete it when done. 0898 * 0899 * @return a polymorphic copy of this DecimalFormat. 0900 * @stable ICU 2.0 0901 */ 0902 DecimalFormat* clone() const override; 0903 0904 /** 0905 * Return true if the given Format objects are semantically equal. 0906 * Objects of different subclasses are considered unequal. 0907 * 0908 * @param other the object to be compared with. 0909 * @return true if the given Format objects are semantically equal. 0910 * @stable ICU 2.0 0911 */ 0912 bool operator==(const Format& other) const override; 0913 0914 0915 using NumberFormat::format; 0916 0917 /** 0918 * Format a double or long number using base-10 representation. 0919 * 0920 * @param number The value to be formatted. 0921 * @param appendTo Output parameter to receive result. 0922 * Result is appended to existing contents. 0923 * @param pos On input: an alignment field, if desired. 0924 * On output: the offsets of the alignment field. 0925 * @return Reference to 'appendTo' parameter. 0926 * @stable ICU 2.0 0927 */ 0928 UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos) const override; 0929 0930 #ifndef U_HIDE_INTERNAL_API 0931 /** 0932 * Format a double or long number using base-10 representation. 0933 * 0934 * @param number The value to be formatted. 0935 * @param appendTo Output parameter to receive result. 0936 * Result is appended to existing contents. 0937 * @param pos On input: an alignment field, if desired. 0938 * On output: the offsets of the alignment field. 0939 * @param status 0940 * @return Reference to 'appendTo' parameter. 0941 * @internal 0942 */ 0943 UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos, 0944 UErrorCode& status) const override; 0945 #endif /* U_HIDE_INTERNAL_API */ 0946 0947 /** 0948 * Format a double or long number using base-10 representation. 0949 * 0950 * @param number The value to be formatted. 0951 * @param appendTo Output parameter to receive result. 0952 * Result is appended to existing contents. 0953 * @param posIter On return, can be used to iterate over positions 0954 * of fields generated by this format call. 0955 * Can be nullptr. 0956 * @param status Output param filled with success/failure status. 0957 * @return Reference to 'appendTo' parameter. 0958 * @stable ICU 4.4 0959 */ 0960 UnicodeString& format(double number, UnicodeString& appendTo, FieldPositionIterator* posIter, 0961 UErrorCode& status) const override; 0962 0963 /** 0964 * Format a long number using base-10 representation. 0965 * 0966 * @param number The value to be formatted. 0967 * @param appendTo Output parameter to receive result. 0968 * Result is appended to existing contents. 0969 * @param pos On input: an alignment field, if desired. 0970 * On output: the offsets of the alignment field. 0971 * @return Reference to 'appendTo' parameter. 0972 * @stable ICU 2.0 0973 */ 0974 UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos) const override; 0975 0976 #ifndef U_HIDE_INTERNAL_API 0977 /** 0978 * Format a long number using base-10 representation. 0979 * 0980 * @param number The value to be formatted. 0981 * @param appendTo Output parameter to receive result. 0982 * Result is appended to existing contents. 0983 * @param pos On input: an alignment field, if desired. 0984 * On output: the offsets of the alignment field. 0985 * @param status Output param filled with success/failure status. 0986 * @return Reference to 'appendTo' parameter. 0987 * @internal 0988 */ 0989 UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos, 0990 UErrorCode& status) const override; 0991 #endif /* U_HIDE_INTERNAL_API */ 0992 0993 /** 0994 * Format a long number using base-10 representation. 0995 * 0996 * @param number The value to be formatted. 0997 * @param appendTo Output parameter to receive result. 0998 * Result is appended to existing contents. 0999 * @param posIter On return, can be used to iterate over positions 1000 * of fields generated by this format call. 1001 * Can be nullptr. 1002 * @param status Output param filled with success/failure status. 1003 * @return Reference to 'appendTo' parameter. 1004 * @stable ICU 4.4 1005 */ 1006 UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPositionIterator* posIter, 1007 UErrorCode& status) const override; 1008 1009 /** 1010 * Format an int64 number using base-10 representation. 1011 * 1012 * @param number The value to be formatted. 1013 * @param appendTo Output parameter to receive result. 1014 * Result is appended to existing contents. 1015 * @param pos On input: an alignment field, if desired. 1016 * On output: the offsets of the alignment field. 1017 * @return Reference to 'appendTo' parameter. 1018 * @stable ICU 2.8 1019 */ 1020 UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos) const override; 1021 1022 #ifndef U_HIDE_INTERNAL_API 1023 /** 1024 * Format an int64 number using base-10 representation. 1025 * 1026 * @param number The value to be formatted. 1027 * @param appendTo Output parameter to receive result. 1028 * Result is appended to existing contents. 1029 * @param pos On input: an alignment field, if desired. 1030 * On output: the offsets of the alignment field. 1031 * @param status Output param filled with success/failure status. 1032 * @return Reference to 'appendTo' parameter. 1033 * @internal 1034 */ 1035 UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos, 1036 UErrorCode& status) const override; 1037 #endif /* U_HIDE_INTERNAL_API */ 1038 1039 /** 1040 * Format an int64 number using base-10 representation. 1041 * 1042 * @param number The value to be formatted. 1043 * @param appendTo Output parameter to receive result. 1044 * Result is appended to existing contents. 1045 * @param posIter On return, can be used to iterate over positions 1046 * of fields generated by this format call. 1047 * Can be nullptr. 1048 * @param status Output param filled with success/failure status. 1049 * @return Reference to 'appendTo' parameter. 1050 * @stable ICU 4.4 1051 */ 1052 UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPositionIterator* posIter, 1053 UErrorCode& status) const override; 1054 1055 /** 1056 * Format a decimal number. 1057 * The syntax of the unformatted number is a "numeric string" 1058 * as defined in the Decimal Arithmetic Specification, available at 1059 * http://speleotrove.com/decimal 1060 * 1061 * @param number The unformatted number, as a string. 1062 * @param appendTo Output parameter to receive result. 1063 * Result is appended to existing contents. 1064 * @param posIter On return, can be used to iterate over positions 1065 * of fields generated by this format call. 1066 * Can be nullptr. 1067 * @param status Output param filled with success/failure status. 1068 * @return Reference to 'appendTo' parameter. 1069 * @stable ICU 4.4 1070 */ 1071 UnicodeString& format(StringPiece number, UnicodeString& appendTo, FieldPositionIterator* posIter, 1072 UErrorCode& status) const override; 1073 1074 #ifndef U_HIDE_INTERNAL_API 1075 1076 /** 1077 * Format a decimal number. 1078 * The number is a DecimalQuantity wrapper onto a floating point decimal number. 1079 * The default implementation in NumberFormat converts the decimal number 1080 * to a double and formats that. 1081 * 1082 * @param number The number, a DecimalQuantity format Decimal Floating Point. 1083 * @param appendTo Output parameter to receive result. 1084 * Result is appended to existing contents. 1085 * @param posIter On return, can be used to iterate over positions 1086 * of fields generated by this format call. 1087 * @param status Output param filled with success/failure status. 1088 * @return Reference to 'appendTo' parameter. 1089 * @internal 1090 */ 1091 UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo, 1092 FieldPositionIterator* posIter, UErrorCode& status) const override; 1093 1094 /** 1095 * Format a decimal number. 1096 * The number is a DecimalQuantity wrapper onto a floating point decimal number. 1097 * The default implementation in NumberFormat converts the decimal number 1098 * to a double and formats that. 1099 * 1100 * @param number The number, a DecimalQuantity format Decimal Floating Point. 1101 * @param appendTo Output parameter to receive result. 1102 * Result is appended to existing contents. 1103 * @param pos On input: an alignment field, if desired. 1104 * On output: the offsets of the alignment field. 1105 * @param status Output param filled with success/failure status. 1106 * @return Reference to 'appendTo' parameter. 1107 * @internal 1108 */ 1109 UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo, 1110 FieldPosition& pos, UErrorCode& status) const override; 1111 1112 #endif // U_HIDE_INTERNAL_API 1113 1114 using NumberFormat::parse; 1115 1116 /** 1117 * Parse the given string using this object's choices. The method 1118 * does string comparisons to try to find an optimal match. 1119 * If no object can be parsed, index is unchanged, and nullptr is 1120 * returned. The result is returned as the most parsimonious 1121 * type of Formattable that will accommodate all of the 1122 * necessary precision. For example, if the result is exactly 12, 1123 * it will be returned as a long. However, if it is 1.5, it will 1124 * be returned as a double. 1125 * 1126 * @param text The text to be parsed. 1127 * @param result Formattable to be set to the parse result. 1128 * If parse fails, return contents are undefined. 1129 * @param parsePosition The position to start parsing at on input. 1130 * On output, moved to after the last successfully 1131 * parse character. On parse failure, does not change. 1132 * @see Formattable 1133 * @stable ICU 2.0 1134 */ 1135 void parse(const UnicodeString& text, Formattable& result, 1136 ParsePosition& parsePosition) const override; 1137 1138 /** 1139 * Parses text from the given string as a currency amount. Unlike 1140 * the parse() method, this method will attempt to parse a generic 1141 * currency name, searching for a match of this object's locale's 1142 * currency display names, or for a 3-letter ISO currency code. 1143 * This method will fail if this format is not a currency format, 1144 * that is, if it does not contain the currency pattern symbol 1145 * (U+00A4) in its prefix or suffix. 1146 * 1147 * @param text the string to parse 1148 * @param pos input-output position; on input, the position within text 1149 * to match; must have 0 <= pos.getIndex() < text.length(); 1150 * on output, the position after the last matched character. 1151 * If the parse fails, the position in unchanged upon output. 1152 * @return if parse succeeds, a pointer to a newly-created CurrencyAmount 1153 * object (owned by the caller) containing information about 1154 * the parsed currency; if parse fails, this is nullptr. 1155 * @stable ICU 49 1156 */ 1157 CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const override; 1158 1159 /** 1160 * Returns the decimal format symbols, which is generally not changed 1161 * by the programmer or user. 1162 * @return desired DecimalFormatSymbols 1163 * @see DecimalFormatSymbols 1164 * @stable ICU 2.0 1165 */ 1166 virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const; 1167 1168 /** 1169 * Sets the decimal format symbols, which is generally not changed 1170 * by the programmer or user. 1171 * @param symbolsToAdopt DecimalFormatSymbols to be adopted. 1172 * @stable ICU 2.0 1173 */ 1174 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt); 1175 1176 /** 1177 * Sets the decimal format symbols, which is generally not changed 1178 * by the programmer or user. 1179 * @param symbols DecimalFormatSymbols. 1180 * @stable ICU 2.0 1181 */ 1182 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols); 1183 1184 1185 /** 1186 * Returns the currency plural format information, 1187 * which is generally not changed by the programmer or user. 1188 * @return desired CurrencyPluralInfo 1189 * @stable ICU 4.2 1190 */ 1191 virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const; 1192 1193 /** 1194 * Sets the currency plural format information, 1195 * which is generally not changed by the programmer or user. 1196 * @param toAdopt CurrencyPluralInfo to be adopted. 1197 * @stable ICU 4.2 1198 */ 1199 virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt); 1200 1201 /** 1202 * Sets the currency plural format information, 1203 * which is generally not changed by the programmer or user. 1204 * @param info Currency Plural Info. 1205 * @stable ICU 4.2 1206 */ 1207 virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info); 1208 1209 1210 /** 1211 * Get the positive prefix. 1212 * 1213 * @param result Output param which will receive the positive prefix. 1214 * @return A reference to 'result'. 1215 * Examples: +123, $123, sFr123 1216 * @stable ICU 2.0 1217 */ 1218 UnicodeString& getPositivePrefix(UnicodeString& result) const; 1219 1220 /** 1221 * Set the positive prefix. 1222 * 1223 * @param newValue the new value of the the positive prefix to be set. 1224 * Examples: +123, $123, sFr123 1225 * @stable ICU 2.0 1226 */ 1227 virtual void setPositivePrefix(const UnicodeString& newValue); 1228 1229 /** 1230 * Get the negative prefix. 1231 * 1232 * @param result Output param which will receive the negative prefix. 1233 * @return A reference to 'result'. 1234 * Examples: -123, ($123) (with negative suffix), sFr-123 1235 * @stable ICU 2.0 1236 */ 1237 UnicodeString& getNegativePrefix(UnicodeString& result) const; 1238 1239 /** 1240 * Set the negative prefix. 1241 * 1242 * @param newValue the new value of the the negative prefix to be set. 1243 * Examples: -123, ($123) (with negative suffix), sFr-123 1244 * @stable ICU 2.0 1245 */ 1246 virtual void setNegativePrefix(const UnicodeString& newValue); 1247 1248 /** 1249 * Get the positive suffix. 1250 * 1251 * @param result Output param which will receive the positive suffix. 1252 * @return A reference to 'result'. 1253 * Example: 123% 1254 * @stable ICU 2.0 1255 */ 1256 UnicodeString& getPositiveSuffix(UnicodeString& result) const; 1257 1258 /** 1259 * Set the positive suffix. 1260 * 1261 * @param newValue the new value of the positive suffix to be set. 1262 * Example: 123% 1263 * @stable ICU 2.0 1264 */ 1265 virtual void setPositiveSuffix(const UnicodeString& newValue); 1266 1267 /** 1268 * Get the negative suffix. 1269 * 1270 * @param result Output param which will receive the negative suffix. 1271 * @return A reference to 'result'. 1272 * Examples: -123%, ($123) (with positive suffixes) 1273 * @stable ICU 2.0 1274 */ 1275 UnicodeString& getNegativeSuffix(UnicodeString& result) const; 1276 1277 /** 1278 * Set the negative suffix. 1279 * 1280 * @param newValue the new value of the negative suffix to be set. 1281 * Examples: 123% 1282 * @stable ICU 2.0 1283 */ 1284 virtual void setNegativeSuffix(const UnicodeString& newValue); 1285 1286 /** 1287 * Whether to show the plus sign on positive (non-negative) numbers; for example, "+12" 1288 * 1289 * For more control over sign display, use NumberFormatter. 1290 * 1291 * @return Whether the sign is shown on positive numbers and zero. 1292 * @stable ICU 64 1293 */ 1294 UBool isSignAlwaysShown() const; 1295 1296 /** 1297 * Set whether to show the plus sign on positive (non-negative) numbers; for example, "+12". 1298 * 1299 * For more control over sign display, use NumberFormatter. 1300 * 1301 * @param value true to always show a sign; false to hide the sign on positive numbers and zero. 1302 * @stable ICU 64 1303 */ 1304 void setSignAlwaysShown(UBool value); 1305 1306 /** 1307 * Get the multiplier for use in percent, permill, etc. 1308 * For a percentage, set the suffixes to have "%" and the multiplier to be 100. 1309 * (For Arabic, use arabic percent symbol). 1310 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000. 1311 * 1312 * The number may also be multiplied by a power of ten; see getMultiplierScale(). 1313 * 1314 * @return the multiplier for use in percent, permill, etc. 1315 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23 1316 * @stable ICU 2.0 1317 */ 1318 int32_t getMultiplier(void) const; 1319 1320 /** 1321 * Set the multiplier for use in percent, permill, etc. 1322 * For a percentage, set the suffixes to have "%" and the multiplier to be 100. 1323 * (For Arabic, use arabic percent symbol). 1324 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000. 1325 * 1326 * This method only supports integer multipliers. To multiply by a non-integer, pair this 1327 * method with setMultiplierScale(). 1328 * 1329 * @param newValue the new value of the multiplier for use in percent, permill, etc. 1330 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23 1331 * @stable ICU 2.0 1332 */ 1333 virtual void setMultiplier(int32_t newValue); 1334 1335 /** 1336 * Gets the power of ten by which number should be multiplied before formatting, which 1337 * can be combined with setMultiplier() to multiply by any arbitrary decimal value. 1338 * 1339 * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale 1340 * of -2 corresponds to multiplication by 0.01. 1341 * 1342 * This method is analogous to UNUM_SCALE in getAttribute. 1343 * 1344 * @return the current value of the power-of-ten multiplier. 1345 * @stable ICU 62 1346 */ 1347 int32_t getMultiplierScale(void) const; 1348 1349 /** 1350 * Sets a power of ten by which number should be multiplied before formatting, which 1351 * can be combined with setMultiplier() to multiply by any arbitrary decimal value. 1352 * 1353 * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale 1354 * of -2 corresponds to multiplication by 0.01. 1355 * 1356 * For example, to multiply numbers by 0.5 before formatting, you can do: 1357 * 1358 * <pre> 1359 * df.setMultiplier(5); 1360 * df.setMultiplierScale(-1); 1361 * </pre> 1362 * 1363 * This method is analogous to UNUM_SCALE in setAttribute. 1364 * 1365 * @param newValue the new value of the power-of-ten multiplier. 1366 * @stable ICU 62 1367 */ 1368 void setMultiplierScale(int32_t newValue); 1369 1370 /** 1371 * Get the rounding increment. 1372 * @return A positive rounding increment, or 0.0 if a custom rounding 1373 * increment is not in effect. 1374 * @see #setRoundingIncrement 1375 * @see #getRoundingMode 1376 * @see #setRoundingMode 1377 * @stable ICU 2.0 1378 */ 1379 virtual double getRoundingIncrement(void) const; 1380 1381 /** 1382 * Set the rounding increment. In the absence of a rounding increment, 1383 * numbers will be rounded to the number of digits displayed. 1384 * @param newValue A positive rounding increment, or 0.0 to 1385 * use the default rounding increment. 1386 * Negative increments are equivalent to 0.0. 1387 * @see #getRoundingIncrement 1388 * @see #getRoundingMode 1389 * @see #setRoundingMode 1390 * @stable ICU 2.0 1391 */ 1392 virtual void setRoundingIncrement(double newValue); 1393 1394 /** 1395 * Get the rounding mode. 1396 * @return A rounding mode 1397 * @see #setRoundingIncrement 1398 * @see #getRoundingIncrement 1399 * @see #setRoundingMode 1400 * @stable ICU 2.0 1401 */ 1402 virtual ERoundingMode getRoundingMode(void) const override; 1403 1404 /** 1405 * Set the rounding mode. 1406 * @param roundingMode A rounding mode 1407 * @see #setRoundingIncrement 1408 * @see #getRoundingIncrement 1409 * @see #getRoundingMode 1410 * @stable ICU 2.0 1411 */ 1412 virtual void setRoundingMode(ERoundingMode roundingMode) override; 1413 1414 /** 1415 * Get the width to which the output of format() is padded. 1416 * The width is counted in 16-bit code units. 1417 * @return the format width, or zero if no padding is in effect 1418 * @see #setFormatWidth 1419 * @see #getPadCharacterString 1420 * @see #setPadCharacter 1421 * @see #getPadPosition 1422 * @see #setPadPosition 1423 * @stable ICU 2.0 1424 */ 1425 virtual int32_t getFormatWidth(void) const; 1426 1427 /** 1428 * Set the width to which the output of format() is padded. 1429 * The width is counted in 16-bit code units. 1430 * This method also controls whether padding is enabled. 1431 * @param width the width to which to pad the result of 1432 * format(), or zero to disable padding. A negative 1433 * width is equivalent to 0. 1434 * @see #getFormatWidth 1435 * @see #getPadCharacterString 1436 * @see #setPadCharacter 1437 * @see #getPadPosition 1438 * @see #setPadPosition 1439 * @stable ICU 2.0 1440 */ 1441 virtual void setFormatWidth(int32_t width); 1442 1443 /** 1444 * Get the pad character used to pad to the format width. The 1445 * default is ' '. 1446 * @return a string containing the pad character. This will always 1447 * have a length of one 32-bit code point. 1448 * @see #setFormatWidth 1449 * @see #getFormatWidth 1450 * @see #setPadCharacter 1451 * @see #getPadPosition 1452 * @see #setPadPosition 1453 * @stable ICU 2.0 1454 */ 1455 virtual UnicodeString getPadCharacterString() const; 1456 1457 /** 1458 * Set the character used to pad to the format width. If padding 1459 * is not enabled, then this will take effect if padding is later 1460 * enabled. 1461 * @param padChar a string containing the pad character. If the string 1462 * has length 0, then the pad character is set to ' '. Otherwise 1463 * padChar.char32At(0) will be used as the pad character. 1464 * @see #setFormatWidth 1465 * @see #getFormatWidth 1466 * @see #getPadCharacterString 1467 * @see #getPadPosition 1468 * @see #setPadPosition 1469 * @stable ICU 2.0 1470 */ 1471 virtual void setPadCharacter(const UnicodeString& padChar); 1472 1473 /** 1474 * Get the position at which padding will take place. This is the location 1475 * at which padding will be inserted if the result of format() 1476 * is shorter than the format width. 1477 * @return the pad position, one of kPadBeforePrefix, 1478 * kPadAfterPrefix, kPadBeforeSuffix, or 1479 * kPadAfterSuffix. 1480 * @see #setFormatWidth 1481 * @see #getFormatWidth 1482 * @see #setPadCharacter 1483 * @see #getPadCharacterString 1484 * @see #setPadPosition 1485 * @see #EPadPosition 1486 * @stable ICU 2.0 1487 */ 1488 virtual EPadPosition getPadPosition(void) const; 1489 1490 /** 1491 * Set the position at which padding will take place. This is the location 1492 * at which padding will be inserted if the result of format() 1493 * is shorter than the format width. This has no effect unless padding is 1494 * enabled. 1495 * @param padPos the pad position, one of kPadBeforePrefix, 1496 * kPadAfterPrefix, kPadBeforeSuffix, or 1497 * kPadAfterSuffix. 1498 * @see #setFormatWidth 1499 * @see #getFormatWidth 1500 * @see #setPadCharacter 1501 * @see #getPadCharacterString 1502 * @see #getPadPosition 1503 * @see #EPadPosition 1504 * @stable ICU 2.0 1505 */ 1506 virtual void setPadPosition(EPadPosition padPos); 1507 1508 /** 1509 * Return whether or not scientific notation is used. 1510 * @return true if this object formats and parses scientific notation 1511 * @see #setScientificNotation 1512 * @see #getMinimumExponentDigits 1513 * @see #setMinimumExponentDigits 1514 * @see #isExponentSignAlwaysShown 1515 * @see #setExponentSignAlwaysShown 1516 * @stable ICU 2.0 1517 */ 1518 virtual UBool isScientificNotation(void) const; 1519 1520 /** 1521 * Set whether or not scientific notation is used. When scientific notation 1522 * is used, the effective maximum number of integer digits is <= 8. If the 1523 * maximum number of integer digits is set to more than 8, the effective 1524 * maximum will be 1. This allows this call to generate a 'default' scientific 1525 * number format without additional changes. 1526 * @param useScientific true if this object formats and parses scientific 1527 * notation 1528 * @see #isScientificNotation 1529 * @see #getMinimumExponentDigits 1530 * @see #setMinimumExponentDigits 1531 * @see #isExponentSignAlwaysShown 1532 * @see #setExponentSignAlwaysShown 1533 * @stable ICU 2.0 1534 */ 1535 virtual void setScientificNotation(UBool useScientific); 1536 1537 /** 1538 * Return the minimum exponent digits that will be shown. 1539 * @return the minimum exponent digits that will be shown 1540 * @see #setScientificNotation 1541 * @see #isScientificNotation 1542 * @see #setMinimumExponentDigits 1543 * @see #isExponentSignAlwaysShown 1544 * @see #setExponentSignAlwaysShown 1545 * @stable ICU 2.0 1546 */ 1547 virtual int8_t getMinimumExponentDigits(void) const; 1548 1549 /** 1550 * Set the minimum exponent digits that will be shown. This has no 1551 * effect unless scientific notation is in use. 1552 * @param minExpDig a value >= 1 indicating the fewest exponent digits 1553 * that will be shown. Values less than 1 will be treated as 1. 1554 * @see #setScientificNotation 1555 * @see #isScientificNotation 1556 * @see #getMinimumExponentDigits 1557 * @see #isExponentSignAlwaysShown 1558 * @see #setExponentSignAlwaysShown 1559 * @stable ICU 2.0 1560 */ 1561 virtual void setMinimumExponentDigits(int8_t minExpDig); 1562 1563 /** 1564 * Return whether the exponent sign is always shown. 1565 * @return true if the exponent is always prefixed with either the 1566 * localized minus sign or the localized plus sign, false if only negative 1567 * exponents are prefixed with the localized minus sign. 1568 * @see #setScientificNotation 1569 * @see #isScientificNotation 1570 * @see #setMinimumExponentDigits 1571 * @see #getMinimumExponentDigits 1572 * @see #setExponentSignAlwaysShown 1573 * @stable ICU 2.0 1574 */ 1575 virtual UBool isExponentSignAlwaysShown(void) const; 1576 1577 /** 1578 * Set whether the exponent sign is always shown. This has no effect 1579 * unless scientific notation is in use. 1580 * @param expSignAlways true if the exponent is always prefixed with either 1581 * the localized minus sign or the localized plus sign, false if only 1582 * negative exponents are prefixed with the localized minus sign. 1583 * @see #setScientificNotation 1584 * @see #isScientificNotation 1585 * @see #setMinimumExponentDigits 1586 * @see #getMinimumExponentDigits 1587 * @see #isExponentSignAlwaysShown 1588 * @stable ICU 2.0 1589 */ 1590 virtual void setExponentSignAlwaysShown(UBool expSignAlways); 1591 1592 /** 1593 * Return the grouping size. Grouping size is the number of digits between 1594 * grouping separators in the integer portion of a number. For example, 1595 * in the number "123,456.78", the grouping size is 3. 1596 * 1597 * @return the grouping size. 1598 * @see setGroupingSize 1599 * @see NumberFormat::isGroupingUsed 1600 * @see DecimalFormatSymbols::getGroupingSeparator 1601 * @stable ICU 2.0 1602 */ 1603 int32_t getGroupingSize(void) const; 1604 1605 /** 1606 * Set the grouping size. Grouping size is the number of digits between 1607 * grouping separators in the integer portion of a number. For example, 1608 * in the number "123,456.78", the grouping size is 3. 1609 * 1610 * @param newValue the new value of the grouping size. 1611 * @see getGroupingSize 1612 * @see NumberFormat::setGroupingUsed 1613 * @see DecimalFormatSymbols::setGroupingSeparator 1614 * @stable ICU 2.0 1615 */ 1616 virtual void setGroupingSize(int32_t newValue); 1617 1618 /** 1619 * Return the secondary grouping size. In some locales one 1620 * grouping interval is used for the least significant integer 1621 * digits (the primary grouping size), and another is used for all 1622 * others (the secondary grouping size). A formatter supporting a 1623 * secondary grouping size will return a positive integer unequal 1624 * to the primary grouping size returned by 1625 * getGroupingSize(). For example, if the primary 1626 * grouping size is 4, and the secondary grouping size is 2, then 1627 * the number 123456789 formats as "1,23,45,6789", and the pattern 1628 * appears as "#,##,###0". 1629 * @return the secondary grouping size, or a value less than 1630 * one if there is none 1631 * @see setSecondaryGroupingSize 1632 * @see NumberFormat::isGroupingUsed 1633 * @see DecimalFormatSymbols::getGroupingSeparator 1634 * @stable ICU 2.4 1635 */ 1636 int32_t getSecondaryGroupingSize(void) const; 1637 1638 /** 1639 * Set the secondary grouping size. If set to a value less than 1, 1640 * then secondary grouping is turned off, and the primary grouping 1641 * size is used for all intervals, not just the least significant. 1642 * 1643 * @param newValue the new value of the secondary grouping size. 1644 * @see getSecondaryGroupingSize 1645 * @see NumberFormat#setGroupingUsed 1646 * @see DecimalFormatSymbols::setGroupingSeparator 1647 * @stable ICU 2.4 1648 */ 1649 virtual void setSecondaryGroupingSize(int32_t newValue); 1650 1651 /** 1652 * Returns the minimum number of grouping digits. 1653 * Grouping separators are output if there are at least this many 1654 * digits to the left of the first (rightmost) grouping separator, 1655 * that is, there are at least (minimum grouping + grouping size) integer digits. 1656 * (Subject to isGroupingUsed().) 1657 * 1658 * For example, if this value is 2, and the grouping size is 3, then 1659 * 9999 -> "9999" and 10000 -> "10,000" 1660 * 1661 * The default value for this attribute is 0. 1662 * A value of 1, 0, or lower, means that the use of grouping separators 1663 * only depends on the grouping size (and on isGroupingUsed()). 1664 * 1665 * NOTE: The CLDR data is used in NumberFormatter but not in DecimalFormat. 1666 * This is for backwards compatibility reasons. 1667 * 1668 * For more control over grouping strategies, use NumberFormatter. 1669 * 1670 * @see setMinimumGroupingDigits 1671 * @see getGroupingSize 1672 * @stable ICU 64 1673 */ 1674 int32_t getMinimumGroupingDigits() const; 1675 1676 /** 1677 * Sets the minimum grouping digits. Setting the value to 1678 * - 1: Turns off minimum grouping digits. 1679 * - 0 or -1: The behavior is undefined. 1680 * - UNUM_MINIMUM_GROUPING_DIGITS_AUTO: Display grouping using the default 1681 * strategy for all locales. 1682 * - UNUM_MINIMUM_GROUPING_DIGITS_MIN2: Display grouping using locale 1683 * defaults, except do not show grouping on values smaller than 10000 1684 * (such that there is a minimum of two digits before the first 1685 * separator). 1686 * 1687 * For more control over grouping strategies, use NumberFormatter. 1688 * 1689 * @param newValue the new value of minimum grouping digits. 1690 * @see getMinimumGroupingDigits 1691 * @stable ICU 64 1692 */ 1693 void setMinimumGroupingDigits(int32_t newValue); 1694 1695 /** 1696 * Allows you to get the behavior of the decimal separator with integers. 1697 * (The decimal separator will always appear with decimals.) 1698 * 1699 * @return true if the decimal separator always appear with decimals. 1700 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 1701 * @stable ICU 2.0 1702 */ 1703 UBool isDecimalSeparatorAlwaysShown(void) const; 1704 1705 /** 1706 * Allows you to set the behavior of the decimal separator with integers. 1707 * (The decimal separator will always appear with decimals.) 1708 * 1709 * @param newValue set true if the decimal separator will always appear with decimals. 1710 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 1711 * @stable ICU 2.0 1712 */ 1713 virtual void setDecimalSeparatorAlwaysShown(UBool newValue); 1714 1715 /** 1716 * Allows you to get the parse behavior of the pattern decimal mark. 1717 * 1718 * @return true if input must contain a match to decimal mark in pattern 1719 * @stable ICU 54 1720 */ 1721 UBool isDecimalPatternMatchRequired(void) const; 1722 1723 /** 1724 * Allows you to set the parse behavior of the pattern decimal mark. 1725 * 1726 * if true, the input must have a decimal mark if one was specified in the pattern. When 1727 * false the decimal mark may be omitted from the input. 1728 * 1729 * @param newValue set true if input must contain a match to decimal mark in pattern 1730 * @stable ICU 54 1731 */ 1732 virtual void setDecimalPatternMatchRequired(UBool newValue); 1733 1734 /** 1735 * Returns whether to ignore exponents when parsing. 1736 * 1737 * @return Whether to ignore exponents when parsing. 1738 * @see #setParseNoExponent 1739 * @stable ICU 64 1740 */ 1741 UBool isParseNoExponent() const; 1742 1743 /** 1744 * Specifies whether to stop parsing when an exponent separator is encountered. For 1745 * example, parses "123E4" to 123 (with parse position 3) instead of 1230000 (with parse position 1746 * 5). 1747 * 1748 * @param value true to prevent exponents from being parsed; false to allow them to be parsed. 1749 * @stable ICU 64 1750 */ 1751 void setParseNoExponent(UBool value); 1752 1753 /** 1754 * Returns whether parsing is sensitive to case (lowercase/uppercase). 1755 * 1756 * @return Whether parsing is case-sensitive. 1757 * @see #setParseCaseSensitive 1758 * @stable ICU 64 1759 */ 1760 UBool isParseCaseSensitive() const; 1761 1762 /** 1763 * Whether to pay attention to case when parsing; default is to ignore case (perform 1764 * case-folding). For example, "A" == "a" in case-insensitive but not case-sensitive mode. 1765 * 1766 * Currency symbols are never case-folded. For example, "us$1.00" will not parse in case-insensitive 1767 * mode, even though "US$1.00" parses. 1768 * 1769 * @param value true to enable case-sensitive parsing (the default); false to force 1770 * case-sensitive parsing behavior. 1771 * @stable ICU 64 1772 */ 1773 void setParseCaseSensitive(UBool value); 1774 1775 /** 1776 * Returns whether truncation of high-order integer digits should result in an error. 1777 * By default, setMaximumIntegerDigits truncates high-order digits silently. 1778 * 1779 * @return Whether an error code is set if high-order digits are truncated. 1780 * @see setFormatFailIfMoreThanMaxDigits 1781 * @stable ICU 64 1782 */ 1783 UBool isFormatFailIfMoreThanMaxDigits() const; 1784 1785 /** 1786 * Sets whether truncation of high-order integer digits should result in an error. 1787 * By default, setMaximumIntegerDigits truncates high-order digits silently. 1788 * 1789 * @param value Whether to set an error code if high-order digits are truncated. 1790 * @stable ICU 64 1791 */ 1792 void setFormatFailIfMoreThanMaxDigits(UBool value); 1793 1794 /** 1795 * Synthesizes a pattern string that represents the current state 1796 * of this Format object. 1797 * 1798 * @param result Output param which will receive the pattern. 1799 * Previous contents are deleted. 1800 * @return A reference to 'result'. 1801 * @see applyPattern 1802 * @stable ICU 2.0 1803 */ 1804 virtual UnicodeString& toPattern(UnicodeString& result) const; 1805 1806 /** 1807 * Synthesizes a localized pattern string that represents the current 1808 * state of this Format object. 1809 * 1810 * @param result Output param which will receive the localized pattern. 1811 * Previous contents are deleted. 1812 * @return A reference to 'result'. 1813 * @see applyPattern 1814 * @stable ICU 2.0 1815 */ 1816 virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const; 1817 1818 /** 1819 * Apply the given pattern to this Format object. A pattern is a 1820 * short-hand specification for the various formatting properties. 1821 * These properties can also be changed individually through the 1822 * various setter methods. 1823 * <P> 1824 * There is no limit to integer digits are set 1825 * by this routine, since that is the typical end-user desire; 1826 * use setMaximumInteger if you want to set a real value. 1827 * For negative numbers, use a second pattern, separated by a semicolon 1828 * <pre> 1829 * . Example "#,#00.0#" -> 1,234.56 1830 * </pre> 1831 * This means a minimum of 2 integer digits, 1 fraction digit, and 1832 * a maximum of 2 fraction digits. 1833 * <pre> 1834 * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parentheses. 1835 * </pre> 1836 * In negative patterns, the minimum and maximum counts are ignored; 1837 * these are presumed to be set in the positive pattern. 1838 * 1839 * @param pattern The pattern to be applied. 1840 * @param parseError Struct to receive information on position 1841 * of error if an error is encountered 1842 * @param status Output param set to success/failure code on 1843 * exit. If the pattern is invalid, this will be 1844 * set to a failure result. 1845 * @stable ICU 2.0 1846 */ 1847 virtual void applyPattern(const UnicodeString& pattern, UParseError& parseError, UErrorCode& status); 1848 1849 /** 1850 * Sets the pattern. 1851 * @param pattern The pattern to be applied. 1852 * @param status Output param set to success/failure code on 1853 * exit. If the pattern is invalid, this will be 1854 * set to a failure result. 1855 * @stable ICU 2.0 1856 */ 1857 virtual void applyPattern(const UnicodeString& pattern, UErrorCode& status); 1858 1859 /** 1860 * Apply the given pattern to this Format object. The pattern 1861 * is assumed to be in a localized notation. A pattern is a 1862 * short-hand specification for the various formatting properties. 1863 * These properties can also be changed individually through the 1864 * various setter methods. 1865 * <P> 1866 * There is no limit to integer digits are set 1867 * by this routine, since that is the typical end-user desire; 1868 * use setMaximumInteger if you want to set a real value. 1869 * For negative numbers, use a second pattern, separated by a semicolon 1870 * <pre> 1871 * . Example "#,#00.0#" -> 1,234.56 1872 * </pre> 1873 * This means a minimum of 2 integer digits, 1 fraction digit, and 1874 * a maximum of 2 fraction digits. 1875 * 1876 * Example: "#,#00.0#;(#,#00.0#)" for negatives in parentheses. 1877 * 1878 * In negative patterns, the minimum and maximum counts are ignored; 1879 * these are presumed to be set in the positive pattern. 1880 * 1881 * @param pattern The localized pattern to be applied. 1882 * @param parseError Struct to receive information on position 1883 * of error if an error is encountered 1884 * @param status Output param set to success/failure code on 1885 * exit. If the pattern is invalid, this will be 1886 * set to a failure result. 1887 * @stable ICU 2.0 1888 */ 1889 virtual void applyLocalizedPattern(const UnicodeString& pattern, UParseError& parseError, 1890 UErrorCode& status); 1891 1892 /** 1893 * Apply the given pattern to this Format object. 1894 * 1895 * @param pattern The localized pattern to be applied. 1896 * @param status Output param set to success/failure code on 1897 * exit. If the pattern is invalid, this will be 1898 * set to a failure result. 1899 * @stable ICU 2.0 1900 */ 1901 virtual void applyLocalizedPattern(const UnicodeString& pattern, UErrorCode& status); 1902 1903 1904 /** 1905 * Sets the maximum number of digits allowed in the integer portion of a 1906 * number. This override limits the integer digit count to 309. 1907 * 1908 * @param newValue the new value of the maximum number of digits 1909 * allowed in the integer portion of a number. 1910 * @see NumberFormat#setMaximumIntegerDigits 1911 * @stable ICU 2.0 1912 */ 1913 void setMaximumIntegerDigits(int32_t newValue) override; 1914 1915 /** 1916 * Sets the minimum number of digits allowed in the integer portion of a 1917 * number. This override limits the integer digit count to 309. 1918 * 1919 * @param newValue the new value of the minimum number of digits 1920 * allowed in the integer portion of a number. 1921 * @see NumberFormat#setMinimumIntegerDigits 1922 * @stable ICU 2.0 1923 */ 1924 void setMinimumIntegerDigits(int32_t newValue) override; 1925 1926 /** 1927 * Sets the maximum number of digits allowed in the fraction portion of a 1928 * number. This override limits the fraction digit count to 340. 1929 * 1930 * @param newValue the new value of the maximum number of digits 1931 * allowed in the fraction portion of a number. 1932 * @see NumberFormat#setMaximumFractionDigits 1933 * @stable ICU 2.0 1934 */ 1935 void setMaximumFractionDigits(int32_t newValue) override; 1936 1937 /** 1938 * Sets the minimum number of digits allowed in the fraction portion of a 1939 * number. This override limits the fraction digit count to 340. 1940 * 1941 * @param newValue the new value of the minimum number of digits 1942 * allowed in the fraction portion of a number. 1943 * @see NumberFormat#setMinimumFractionDigits 1944 * @stable ICU 2.0 1945 */ 1946 void setMinimumFractionDigits(int32_t newValue) override; 1947 1948 /** 1949 * Returns the minimum number of significant digits that will be 1950 * displayed. This value has no effect unless areSignificantDigitsUsed() 1951 * returns true. 1952 * @return the fewest significant digits that will be shown 1953 * @stable ICU 3.0 1954 */ 1955 int32_t getMinimumSignificantDigits() const; 1956 1957 /** 1958 * Returns the maximum number of significant digits that will be 1959 * displayed. This value has no effect unless areSignificantDigitsUsed() 1960 * returns true. 1961 * @return the most significant digits that will be shown 1962 * @stable ICU 3.0 1963 */ 1964 int32_t getMaximumSignificantDigits() const; 1965 1966 /** 1967 * Sets the minimum number of significant digits that will be 1968 * displayed. If <code>min</code> is less than one then it is set 1969 * to one. If the maximum significant digits count is less than 1970 * <code>min</code>, then it is set to <code>min</code>. 1971 * This function also enables the use of significant digits 1972 * by this formatter - areSignificantDigitsUsed() will return true. 1973 * @see #areSignificantDigitsUsed 1974 * @param min the fewest significant digits to be shown 1975 * @stable ICU 3.0 1976 */ 1977 void setMinimumSignificantDigits(int32_t min); 1978 1979 /** 1980 * Sets the maximum number of significant digits that will be 1981 * displayed. If <code>max</code> is less than one then it is set 1982 * to one. If the minimum significant digits count is greater 1983 * than <code>max</code>, then it is set to <code>max</code>. 1984 * This function also enables the use of significant digits 1985 * by this formatter - areSignificantDigitsUsed() will return true. 1986 * @see #areSignificantDigitsUsed 1987 * @param max the most significant digits to be shown 1988 * @stable ICU 3.0 1989 */ 1990 void setMaximumSignificantDigits(int32_t max); 1991 1992 /** 1993 * Returns true if significant digits are in use, or false if 1994 * integer and fraction digit counts are in use. 1995 * @return true if significant digits are in use 1996 * @stable ICU 3.0 1997 */ 1998 UBool areSignificantDigitsUsed() const; 1999 2000 /** 2001 * Sets whether significant digits are in use, or integer and 2002 * fraction digit counts are in use. 2003 * @param useSignificantDigits true to use significant digits, or 2004 * false to use integer and fraction digit counts 2005 * @stable ICU 3.0 2006 */ 2007 void setSignificantDigitsUsed(UBool useSignificantDigits); 2008 2009 /** 2010 * Sets the currency used to display currency 2011 * amounts. This takes effect immediately, if this format is a 2012 * currency format. If this format is not a currency format, then 2013 * the currency is used if and when this object becomes a 2014 * currency format through the application of a new pattern. 2015 * @param theCurrency a 3-letter ISO code indicating new currency 2016 * to use. It need not be null-terminated. May be the empty 2017 * string or nullptr to indicate no currency. 2018 * @param ec input-output error code 2019 * @stable ICU 3.0 2020 */ 2021 void setCurrency(const char16_t* theCurrency, UErrorCode& ec) override; 2022 2023 #ifndef U_FORCE_HIDE_DEPRECATED_API 2024 /** 2025 * Sets the currency used to display currency amounts. See 2026 * setCurrency(const char16_t*, UErrorCode&). 2027 * @deprecated ICU 3.0. Use setCurrency(const char16_t*, UErrorCode&). 2028 */ 2029 virtual void setCurrency(const char16_t* theCurrency); 2030 #endif // U_FORCE_HIDE_DEPRECATED_API 2031 2032 /** 2033 * Sets the `Currency Usage` object used to display currency. 2034 * This takes effect immediately, if this format is a 2035 * currency format. 2036 * @param newUsage new currency usage object to use. 2037 * @param ec input-output error code 2038 * @stable ICU 54 2039 */ 2040 void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec); 2041 2042 /** 2043 * Returns the `Currency Usage` object used to display currency 2044 * @stable ICU 54 2045 */ 2046 UCurrencyUsage getCurrencyUsage() const; 2047 2048 #ifndef U_HIDE_INTERNAL_API 2049 2050 /** 2051 * Format a number and save it into the given DecimalQuantity. 2052 * Internal, not intended for public use. 2053 * @internal 2054 */ 2055 void formatToDecimalQuantity(double number, number::impl::DecimalQuantity& output, 2056 UErrorCode& status) const; 2057 2058 /** 2059 * Get a DecimalQuantity corresponding to a formattable as it would be 2060 * formatted by this DecimalFormat. 2061 * Internal, not intended for public use. 2062 * @internal 2063 */ 2064 void formatToDecimalQuantity(const Formattable& number, number::impl::DecimalQuantity& output, 2065 UErrorCode& status) const; 2066 2067 #endif /* U_HIDE_INTERNAL_API */ 2068 2069 /** 2070 * Converts this DecimalFormat to a (Localized)NumberFormatter. Starting 2071 * in ICU 60, NumberFormatter is the recommended way to format numbers. 2072 * You can use the returned LocalizedNumberFormatter to format numbers and 2073 * get a FormattedNumber, which contains a string as well as additional 2074 * annotations about the formatted value. 2075 * 2076 * If a memory allocation failure occurs, the return value of this method 2077 * might be null. If you are concerned about correct recovery from 2078 * out-of-memory situations, use this pattern: 2079 * 2080 * <pre> 2081 * FormattedNumber result; 2082 * if (auto* ptr = df->toNumberFormatter(status)) { 2083 * result = ptr->formatDouble(123, status); 2084 * } 2085 * </pre> 2086 * 2087 * If you are not concerned about out-of-memory situations, or if your 2088 * environment throws exceptions when memory allocation failure occurs, 2089 * you can chain the methods, like this: 2090 * 2091 * <pre> 2092 * FormattedNumber result = df 2093 * ->toNumberFormatter(status) 2094 * ->formatDouble(123, status); 2095 * </pre> 2096 * 2097 * NOTE: The returned LocalizedNumberFormatter is owned by this DecimalFormat. 2098 * If a non-const method is called on the DecimalFormat, or if the DecimalFormat 2099 * is deleted, the object becomes invalid. If you plan to keep the return value 2100 * beyond the lifetime of the DecimalFormat, copy it to a local variable: 2101 * 2102 * <pre> 2103 * LocalizedNumberFormatter lnf; 2104 * if (auto* ptr = df->toNumberFormatter(status)) { 2105 * lnf = *ptr; 2106 * } 2107 * </pre> 2108 * 2109 * @param status Set on failure, like U_MEMORY_ALLOCATION_ERROR. 2110 * @return A pointer to an internal object, or nullptr on failure. 2111 * Do not delete the return value! 2112 * @stable ICU 64 2113 */ 2114 const number::LocalizedNumberFormatter* toNumberFormatter(UErrorCode& status) const; 2115 2116 /** 2117 * Return the class ID for this class. This is useful only for 2118 * comparing to a return value from getDynamicClassID(). For example: 2119 * <pre> 2120 * . Base* polymorphic_pointer = createPolymorphicObject(); 2121 * . if (polymorphic_pointer->getDynamicClassID() == 2122 * . Derived::getStaticClassID()) ... 2123 * </pre> 2124 * @return The class ID for all objects of this class. 2125 * @stable ICU 2.0 2126 */ 2127 static UClassID U_EXPORT2 getStaticClassID(void); 2128 2129 /** 2130 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. 2131 * This method is to implement a simple version of RTTI, since not all 2132 * C++ compilers support genuine RTTI. Polymorphic operator==() and 2133 * clone() methods call this method. 2134 * 2135 * @return The class ID for this object. All objects of a 2136 * given class have the same class ID. Objects of 2137 * other classes have different class IDs. 2138 * @stable ICU 2.0 2139 */ 2140 UClassID getDynamicClassID(void) const override; 2141 2142 private: 2143 2144 /** Rebuilds the formatter object from the property bag. */ 2145 void touch(UErrorCode& status); 2146 2147 /** Rebuilds the formatter object, ignoring any error code. */ 2148 void touchNoError(); 2149 2150 /** 2151 * Updates the property bag with settings from the given pattern. 2152 * 2153 * @param pattern The pattern string to parse. 2154 * @param ignoreRounding Whether to leave out rounding information (minFrac, maxFrac, and rounding 2155 * increment) when parsing the pattern. This may be desirable if a custom rounding mode, such 2156 * as CurrencyUsage, is to be used instead. One of {@link 2157 * PatternStringParser#IGNORE_ROUNDING_ALWAYS}, {@link PatternStringParser#IGNORE_ROUNDING_IF_CURRENCY}, 2158 * or {@link PatternStringParser#IGNORE_ROUNDING_NEVER}. 2159 * @see PatternAndPropertyUtils#parseToExistingProperties 2160 */ 2161 void setPropertiesFromPattern(const UnicodeString& pattern, int32_t ignoreRounding, 2162 UErrorCode& status); 2163 2164 const numparse::impl::NumberParserImpl* getParser(UErrorCode& status) const; 2165 2166 const numparse::impl::NumberParserImpl* getCurrencyParser(UErrorCode& status) const; 2167 2168 static void fieldPositionHelper( 2169 const number::impl::UFormattedNumberData& formatted, 2170 FieldPosition& fieldPosition, 2171 int32_t offset, 2172 UErrorCode& status); 2173 2174 static void fieldPositionIteratorHelper( 2175 const number::impl::UFormattedNumberData& formatted, 2176 FieldPositionIterator* fpi, 2177 int32_t offset, 2178 UErrorCode& status); 2179 2180 void setupFastFormat(); 2181 2182 bool fastFormatDouble(double input, UnicodeString& output) const; 2183 2184 bool fastFormatInt64(int64_t input, UnicodeString& output) const; 2185 2186 void doFastFormatInt32(int32_t input, bool isNegative, UnicodeString& output) const; 2187 2188 //=====================================================================================// 2189 // INSTANCE FIELDS // 2190 //=====================================================================================// 2191 2192 2193 // One instance field for the implementation, keep all fields inside of an implementation 2194 // class defined in number_mapper.h 2195 number::impl::DecimalFormatFields* fields = nullptr; 2196 2197 // Allow child class CompactDecimalFormat to access fProperties: 2198 friend class CompactDecimalFormat; 2199 2200 // Allow MeasureFormat to use fieldPositionHelper: 2201 friend class MeasureFormat; 2202 2203 }; 2204 2205 U_NAMESPACE_END 2206 2207 #endif /* #if !UCONFIG_NO_FORMATTING */ 2208 2209 #endif /* U_SHOW_CPLUSPLUS_API */ 2210 2211 #endif // _DECIMFMT 2212 //eof
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |