1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/decimfmt.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2407 @@ 1.4 +/* 1.5 +******************************************************************************** 1.6 +* Copyright (C) 1997-2013, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +******************************************************************************** 1.9 +* 1.10 +* File DECIMFMT.H 1.11 +* 1.12 +* Modification History: 1.13 +* 1.14 +* Date Name Description 1.15 +* 02/19/97 aliu Converted from java. 1.16 +* 03/20/97 clhuang Updated per C++ implementation. 1.17 +* 04/03/97 aliu Rewrote parsing and formatting completely, and 1.18 +* cleaned up and debugged. Actually works now. 1.19 +* 04/17/97 aliu Changed DigitCount to int per code review. 1.20 +* 07/10/97 helena Made ParsePosition a class and get rid of the function 1.21 +* hiding problems. 1.22 +* 09/09/97 aliu Ported over support for exponential formats. 1.23 +* 07/20/98 stephen Changed documentation 1.24 +* 01/30/13 emmons Added Scaling methods 1.25 +******************************************************************************** 1.26 +*/ 1.27 + 1.28 +#ifndef DECIMFMT_H 1.29 +#define DECIMFMT_H 1.30 + 1.31 +#include "unicode/utypes.h" 1.32 +/** 1.33 + * \file 1.34 + * \brief C++ API: Formats decimal numbers. 1.35 + */ 1.36 + 1.37 +#if !UCONFIG_NO_FORMATTING 1.38 + 1.39 +#include "unicode/dcfmtsym.h" 1.40 +#include "unicode/numfmt.h" 1.41 +#include "unicode/locid.h" 1.42 +#include "unicode/fpositer.h" 1.43 +#include "unicode/stringpiece.h" 1.44 +#include "unicode/curramt.h" 1.45 +#include "unicode/enumset.h" 1.46 + 1.47 +/** 1.48 + * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE 1.49 + * @internal 1.50 + */ 1.51 +#if UCONFIG_FORMAT_FASTPATHS_49 1.52 +#define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16 1.53 +#endif 1.54 + 1.55 +U_NAMESPACE_BEGIN 1.56 + 1.57 +class DigitList; 1.58 +class ChoiceFormat; 1.59 +class CurrencyPluralInfo; 1.60 +class Hashtable; 1.61 +class UnicodeSet; 1.62 +class FieldPositionHandler; 1.63 +class DecimalFormatStaticSets; 1.64 +class FixedDecimal; 1.65 + 1.66 +// explicit template instantiation. see digitlst.h 1.67 +#if defined (_MSC_VER) 1.68 +template class U_I18N_API EnumSet<UNumberFormatAttribute, 1.69 + UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, 1.70 + UNUM_LIMIT_BOOLEAN_ATTRIBUTE>; 1.71 +#endif 1.72 + 1.73 +/** 1.74 + * DecimalFormat is a concrete subclass of NumberFormat that formats decimal 1.75 + * numbers. It has a variety of features designed to make it possible to parse 1.76 + * and format numbers in any locale, including support for Western, Arabic, or 1.77 + * Indic digits. It also supports different flavors of numbers, including 1.78 + * integers ("123"), fixed-point numbers ("123.4"), scientific notation 1.79 + * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123", 1.80 + * "123 US dollars"). All of these flavors can be easily localized. 1.81 + * 1.82 + * <p>To obtain a NumberFormat for a specific locale (including the default 1.83 + * locale) call one of NumberFormat's factory methods such as 1.84 + * createInstance(). Do not call the DecimalFormat constructors directly, unless 1.85 + * you know what you are doing, since the NumberFormat factory methods may 1.86 + * return subclasses other than DecimalFormat. 1.87 + * 1.88 + * <p><strong>Example Usage</strong> 1.89 + * 1.90 + * \code 1.91 + * // Normally we would have a GUI with a menu for this 1.92 + * int32_t locCount; 1.93 + * const Locale* locales = NumberFormat::getAvailableLocales(locCount); 1.94 + * 1.95 + * double myNumber = -1234.56; 1.96 + * UErrorCode success = U_ZERO_ERROR; 1.97 + * NumberFormat* form; 1.98 + * 1.99 + * // Print out a number with the localized number, currency and percent 1.100 + * // format for each locale. 1.101 + * UnicodeString countryName; 1.102 + * UnicodeString displayName; 1.103 + * UnicodeString str; 1.104 + * UnicodeString pattern; 1.105 + * Formattable fmtable; 1.106 + * for (int32_t j = 0; j < 3; ++j) { 1.107 + * cout << endl << "FORMAT " << j << endl; 1.108 + * for (int32_t i = 0; i < locCount; ++i) { 1.109 + * if (locales[i].getCountry(countryName).size() == 0) { 1.110 + * // skip language-only 1.111 + * continue; 1.112 + * } 1.113 + * switch (j) { 1.114 + * case 0: 1.115 + * form = NumberFormat::createInstance(locales[i], success ); break; 1.116 + * case 1: 1.117 + * form = NumberFormat::createCurrencyInstance(locales[i], success ); break; 1.118 + * default: 1.119 + * form = NumberFormat::createPercentInstance(locales[i], success ); break; 1.120 + * } 1.121 + * if (form) { 1.122 + * str.remove(); 1.123 + * pattern = ((DecimalFormat*)form)->toPattern(pattern); 1.124 + * cout << locales[i].getDisplayName(displayName) << ": " << pattern; 1.125 + * cout << " -> " << form->format(myNumber,str) << endl; 1.126 + * form->parse(form->format(myNumber,str), fmtable, success); 1.127 + * delete form; 1.128 + * } 1.129 + * } 1.130 + * } 1.131 + * \endcode 1.132 + * <P> 1.133 + * Another example use createInstance(style) 1.134 + * <P> 1.135 + * <pre> 1.136 + * <strong>// Print out a number using the localized number, currency, 1.137 + * // percent, scientific, integer, iso currency, and plural currency 1.138 + * // format for each locale</strong> 1.139 + * Locale* locale = new Locale("en", "US"); 1.140 + * double myNumber = 1234.56; 1.141 + * UErrorCode success = U_ZERO_ERROR; 1.142 + * UnicodeString str; 1.143 + * Formattable fmtable; 1.144 + * for (int j=NumberFormat::kNumberStyle; 1.145 + * j<=NumberFormat::kPluralCurrencyStyle; 1.146 + * ++j) { 1.147 + * NumberFormat* format = NumberFormat::createInstance(locale, j, success); 1.148 + * str.remove(); 1.149 + * cout << "format result " << form->format(myNumber, str) << endl; 1.150 + * format->parse(form->format(myNumber, str), fmtable, success); 1.151 + * }</pre> 1.152 + * 1.153 + * 1.154 + * <p><strong>Patterns</strong> 1.155 + * 1.156 + * <p>A DecimalFormat consists of a <em>pattern</em> and a set of 1.157 + * <em>symbols</em>. The pattern may be set directly using 1.158 + * applyPattern(), or indirectly using other API methods which 1.159 + * manipulate aspects of the pattern, such as the minimum number of integer 1.160 + * digits. The symbols are stored in a DecimalFormatSymbols 1.161 + * object. When using the NumberFormat factory methods, the 1.162 + * pattern and symbols are read from ICU's locale data. 1.163 + * 1.164 + * <p><strong>Special Pattern Characters</strong> 1.165 + * 1.166 + * <p>Many characters in a pattern are taken literally; they are matched during 1.167 + * parsing and output unchanged during formatting. Special characters, on the 1.168 + * other hand, stand for other characters, strings, or classes of characters. 1.169 + * For example, the '#' character is replaced by a localized digit. Often the 1.170 + * replacement character is the same as the pattern character; in the U.S. locale, 1.171 + * the ',' grouping character is replaced by ','. However, the replacement is 1.172 + * still happening, and if the symbols are modified, the grouping character 1.173 + * changes. Some special characters affect the behavior of the formatter by 1.174 + * their presence; for example, if the percent character is seen, then the 1.175 + * value is multiplied by 100 before being displayed. 1.176 + * 1.177 + * <p>To insert a special character in a pattern as a literal, that is, without 1.178 + * any special meaning, the character must be quoted. There are some exceptions to 1.179 + * this which are noted below. 1.180 + * 1.181 + * <p>The characters listed here are used in non-localized patterns. Localized 1.182 + * patterns use the corresponding characters taken from this formatter's 1.183 + * DecimalFormatSymbols object instead, and these characters lose 1.184 + * their special status. Two exceptions are the currency sign and quote, which 1.185 + * are not localized. 1.186 + * 1.187 + * <table border=0 cellspacing=3 cellpadding=0> 1.188 + * <tr bgcolor="#ccccff"> 1.189 + * <td align=left><strong>Symbol</strong> 1.190 + * <td align=left><strong>Location</strong> 1.191 + * <td align=left><strong>Localized?</strong> 1.192 + * <td align=left><strong>Meaning</strong> 1.193 + * <tr valign=top> 1.194 + * <td><code>0</code> 1.195 + * <td>Number 1.196 + * <td>Yes 1.197 + * <td>Digit 1.198 + * <tr valign=top bgcolor="#eeeeff"> 1.199 + * <td><code>1-9</code> 1.200 + * <td>Number 1.201 + * <td>Yes 1.202 + * <td>'1' through '9' indicate rounding. 1.203 + * <tr valign=top> 1.204 + * <td><code>\htmlonly@\endhtmlonly</code> <!--doxygen doesn't like @--> 1.205 + * <td>Number 1.206 + * <td>No 1.207 + * <td>Significant digit 1.208 + * <tr valign=top bgcolor="#eeeeff"> 1.209 + * <td><code>#</code> 1.210 + * <td>Number 1.211 + * <td>Yes 1.212 + * <td>Digit, zero shows as absent 1.213 + * <tr valign=top> 1.214 + * <td><code>.</code> 1.215 + * <td>Number 1.216 + * <td>Yes 1.217 + * <td>Decimal separator or monetary decimal separator 1.218 + * <tr valign=top bgcolor="#eeeeff"> 1.219 + * <td><code>-</code> 1.220 + * <td>Number 1.221 + * <td>Yes 1.222 + * <td>Minus sign 1.223 + * <tr valign=top> 1.224 + * <td><code>,</code> 1.225 + * <td>Number 1.226 + * <td>Yes 1.227 + * <td>Grouping separator 1.228 + * <tr valign=top bgcolor="#eeeeff"> 1.229 + * <td><code>E</code> 1.230 + * <td>Number 1.231 + * <td>Yes 1.232 + * <td>Separates mantissa and exponent in scientific notation. 1.233 + * <em>Need not be quoted in prefix or suffix.</em> 1.234 + * <tr valign=top> 1.235 + * <td><code>+</code> 1.236 + * <td>Exponent 1.237 + * <td>Yes 1.238 + * <td>Prefix positive exponents with localized plus sign. 1.239 + * <em>Need not be quoted in prefix or suffix.</em> 1.240 + * <tr valign=top bgcolor="#eeeeff"> 1.241 + * <td><code>;</code> 1.242 + * <td>Subpattern boundary 1.243 + * <td>Yes 1.244 + * <td>Separates positive and negative subpatterns 1.245 + * <tr valign=top> 1.246 + * <td><code>\%</code> 1.247 + * <td>Prefix or suffix 1.248 + * <td>Yes 1.249 + * <td>Multiply by 100 and show as percentage 1.250 + * <tr valign=top bgcolor="#eeeeff"> 1.251 + * <td><code>\\u2030</code> 1.252 + * <td>Prefix or suffix 1.253 + * <td>Yes 1.254 + * <td>Multiply by 1000 and show as per mille 1.255 + * <tr valign=top> 1.256 + * <td><code>\htmlonly¤\endhtmlonly</code> (<code>\\u00A4</code>) 1.257 + * <td>Prefix or suffix 1.258 + * <td>No 1.259 + * <td>Currency sign, replaced by currency symbol. If 1.260 + * doubled, replaced by international currency symbol. 1.261 + * If tripled, replaced by currency plural names, for example, 1.262 + * "US dollar" or "US dollars" for America. 1.263 + * If present in a pattern, the monetary decimal separator 1.264 + * is used instead of the decimal separator. 1.265 + * <tr valign=top bgcolor="#eeeeff"> 1.266 + * <td><code>'</code> 1.267 + * <td>Prefix or suffix 1.268 + * <td>No 1.269 + * <td>Used to quote special characters in a prefix or suffix, 1.270 + * for example, <code>"'#'#"</code> formats 123 to 1.271 + * <code>"#123"</code>. To create a single quote 1.272 + * itself, use two in a row: <code>"# o''clock"</code>. 1.273 + * <tr valign=top> 1.274 + * <td><code>*</code> 1.275 + * <td>Prefix or suffix boundary 1.276 + * <td>Yes 1.277 + * <td>Pad escape, precedes pad character 1.278 + * </table> 1.279 + * 1.280 + * <p>A DecimalFormat pattern contains a postive and negative 1.281 + * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a 1.282 + * prefix, a numeric part, and a suffix. If there is no explicit negative 1.283 + * subpattern, the negative subpattern is the localized minus sign prefixed to the 1.284 + * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there 1.285 + * is an explicit negative subpattern, it serves only to specify the negative 1.286 + * prefix and suffix; the number of digits, minimal digits, and other 1.287 + * characteristics are ignored in the negative subpattern. That means that 1.288 + * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)". 1.289 + * 1.290 + * <p>The prefixes, suffixes, and various symbols used for infinity, digits, 1.291 + * thousands separators, decimal separators, etc. may be set to arbitrary 1.292 + * values, and they will appear properly during formatting. However, care must 1.293 + * be taken that the symbols and strings do not conflict, or parsing will be 1.294 + * unreliable. For example, either the positive and negative prefixes or the 1.295 + * suffixes must be distinct for parse() to be able 1.296 + * to distinguish positive from negative values. Another example is that the 1.297 + * decimal separator and thousands separator should be distinct characters, or 1.298 + * parsing will be impossible. 1.299 + * 1.300 + * <p>The <em>grouping separator</em> is a character that separates clusters of 1.301 + * integer digits to make large numbers more legible. It commonly used for 1.302 + * thousands, but in some locales it separates ten-thousands. The <em>grouping 1.303 + * size</em> is the number of digits between the grouping separators, such as 3 1.304 + * for "100,000,000" or 4 for "1 0000 0000". There are actually two different 1.305 + * grouping sizes: One used for the least significant integer digits, the 1.306 + * <em>primary grouping size</em>, and one used for all others, the 1.307 + * <em>secondary grouping size</em>. In most locales these are the same, but 1.308 + * sometimes they are different. For example, if the primary grouping interval 1.309 + * is 3, and the secondary is 2, then this corresponds to the pattern 1.310 + * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a 1.311 + * pattern contains multiple grouping separators, the interval between the last 1.312 + * one and the end of the integer defines the primary grouping size, and the 1.313 + * interval between the last two defines the secondary grouping size. All others 1.314 + * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####". 1.315 + * 1.316 + * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause 1.317 + * DecimalFormat to set a failing UErrorCode. 1.318 + * 1.319 + * <p><strong>Pattern BNF</strong> 1.320 + * 1.321 + * <pre> 1.322 + * pattern := subpattern (';' subpattern)? 1.323 + * subpattern := prefix? number exponent? suffix? 1.324 + * number := (integer ('.' fraction)?) | sigDigits 1.325 + * prefix := '\\u0000'..'\\uFFFD' - specialCharacters 1.326 + * suffix := '\\u0000'..'\\uFFFD' - specialCharacters 1.327 + * integer := '#'* '0'* '0' 1.328 + * fraction := '0'* '#'* 1.329 + * sigDigits := '#'* '@' '@'* '#'* 1.330 + * exponent := 'E' '+'? '0'* '0' 1.331 + * padSpec := '*' padChar 1.332 + * padChar := '\\u0000'..'\\uFFFD' - quote 1.333 + * 1.334 + * Notation: 1.335 + * X* 0 or more instances of X 1.336 + * X? 0 or 1 instances of X 1.337 + * X|Y either X or Y 1.338 + * C..D any character from C up to D, inclusive 1.339 + * S-T characters in S, except those in T 1.340 + * </pre> 1.341 + * The first subpattern is for positive numbers. The second (optional) 1.342 + * subpattern is for negative numbers. 1.343 + * 1.344 + * <p>Not indicated in the BNF syntax above: 1.345 + * 1.346 + * <ul><li>The grouping separator ',' can occur inside the integer and 1.347 + * sigDigits elements, between any two pattern characters of that 1.348 + * element, as long as the integer or sigDigits element is not 1.349 + * followed by the exponent element. 1.350 + * 1.351 + * <li>Two grouping intervals are recognized: That between the 1.352 + * decimal point and the first grouping symbol, and that 1.353 + * between the first and second grouping symbols. These 1.354 + * intervals are identical in most locales, but in some 1.355 + * locales they differ. For example, the pattern 1.356 + * "#,##,###" formats the number 123456789 as 1.357 + * "12,34,56,789".</li> 1.358 + * 1.359 + * <li>The pad specifier <code>padSpec</code> may appear before the prefix, 1.360 + * after the prefix, before the suffix, after the suffix, or not at all. 1.361 + * 1.362 + * <li>In place of '0', the digits '1' through '9' may be used to 1.363 + * indicate a rounding increment. 1.364 + * </ul> 1.365 + * 1.366 + * <p><strong>Parsing</strong> 1.367 + * 1.368 + * <p>DecimalFormat parses all Unicode characters that represent 1.369 + * decimal digits, as defined by u_charDigitValue(). In addition, 1.370 + * DecimalFormat also recognizes as digits the ten consecutive 1.371 + * characters starting with the localized zero digit defined in the 1.372 + * DecimalFormatSymbols object. During formatting, the 1.373 + * DecimalFormatSymbols-based digits are output. 1.374 + * 1.375 + * <p>During parsing, grouping separators are ignored if in lenient mode; 1.376 + * otherwise, if present, they must be in appropriate positions. 1.377 + * 1.378 + * <p>For currency parsing, the formatter is able to parse every currency 1.379 + * style formats no matter which style the formatter is constructed with. 1.380 + * For example, a formatter instance gotten from 1.381 + * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse 1.382 + * formats such as "USD1.00" and "3.00 US dollars". 1.383 + * 1.384 + * <p>If parse(UnicodeString&,Formattable&,ParsePosition&) 1.385 + * fails to parse a string, it leaves the parse position unchanged. 1.386 + * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&) 1.387 + * indicates parse failure by setting a failing 1.388 + * UErrorCode. 1.389 + * 1.390 + * <p><strong>Formatting</strong> 1.391 + * 1.392 + * <p>Formatting is guided by several parameters, all of which can be 1.393 + * specified either using a pattern or using the API. The following 1.394 + * description applies to formats that do not use <a href="#sci">scientific 1.395 + * notation</a> or <a href="#sigdig">significant digits</a>. 1.396 + * 1.397 + * <ul><li>If the number of actual integer digits exceeds the 1.398 + * <em>maximum integer digits</em>, then only the least significant 1.399 + * digits are shown. For example, 1997 is formatted as "97" if the 1.400 + * maximum integer digits is set to 2. 1.401 + * 1.402 + * <li>If the number of actual integer digits is less than the 1.403 + * <em>minimum integer digits</em>, then leading zeros are added. For 1.404 + * example, 1997 is formatted as "01997" if the minimum integer digits 1.405 + * is set to 5. 1.406 + * 1.407 + * <li>If the number of actual fraction digits exceeds the <em>maximum 1.408 + * fraction digits</em>, then rounding is performed to the 1.409 + * maximum fraction digits. For example, 0.125 is formatted as "0.12" 1.410 + * if the maximum fraction digits is 2. This behavior can be changed 1.411 + * by specifying a rounding increment and/or a rounding mode. 1.412 + * 1.413 + * <li>If the number of actual fraction digits is less than the 1.414 + * <em>minimum fraction digits</em>, then trailing zeros are added. 1.415 + * For example, 0.125 is formatted as "0.1250" if the mimimum fraction 1.416 + * digits is set to 4. 1.417 + * 1.418 + * <li>Trailing fractional zeros are not displayed if they occur 1.419 + * <em>j</em> positions after the decimal, where <em>j</em> is less 1.420 + * than the maximum fraction digits. For example, 0.10004 is 1.421 + * formatted as "0.1" if the maximum fraction digits is four or less. 1.422 + * </ul> 1.423 + * 1.424 + * <p><strong>Special Values</strong> 1.425 + * 1.426 + * <p><code>NaN</code> is represented as a single character, typically 1.427 + * <code>\\uFFFD</code>. This character is determined by the 1.428 + * DecimalFormatSymbols object. This is the only value for which 1.429 + * the prefixes and suffixes are not used. 1.430 + * 1.431 + * <p>Infinity is represented as a single character, typically 1.432 + * <code>\\u221E</code>, with the positive or negative prefixes and suffixes 1.433 + * applied. The infinity character is determined by the 1.434 + * DecimalFormatSymbols object. 1.435 + * 1.436 + * <a name="sci"><strong>Scientific Notation</strong></a> 1.437 + * 1.438 + * <p>Numbers in scientific notation are expressed as the product of a mantissa 1.439 + * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The 1.440 + * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0), 1.441 + * but it need not be. DecimalFormat supports arbitrary mantissas. 1.442 + * DecimalFormat can be instructed to use scientific 1.443 + * notation through the API or through the pattern. In a pattern, the exponent 1.444 + * character immediately followed by one or more digit characters indicates 1.445 + * scientific notation. Example: "0.###E0" formats the number 1234 as 1.446 + * "1.234E3". 1.447 + * 1.448 + * <ul> 1.449 + * <li>The number of digit characters after the exponent character gives the 1.450 + * minimum exponent digit count. There is no maximum. Negative exponents are 1.451 + * formatted using the localized minus sign, <em>not</em> the prefix and suffix 1.452 + * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix 1.453 + * positive exponents with a localized plus sign, specify '+' between the 1.454 + * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0", 1.455 + * "1E-1", etc. (In localized patterns, use the localized plus sign rather than 1.456 + * '+'.) 1.457 + * 1.458 + * <li>The minimum number of integer digits is achieved by adjusting the 1.459 + * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This 1.460 + * only happens if there is no maximum number of integer digits. If there is a 1.461 + * maximum, then the minimum number of integer digits is fixed at one. 1.462 + * 1.463 + * <li>The maximum number of integer digits, if present, specifies the exponent 1.464 + * grouping. The most common use of this is to generate <em>engineering 1.465 + * notation</em>, in which the exponent is a multiple of three, e.g., 1.466 + * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3". 1.467 + * 1.468 + * <li>When using scientific notation, the formatter controls the 1.469 + * digit counts using significant digits logic. The maximum number of 1.470 + * significant digits limits the total number of integer and fraction 1.471 + * digits that will be shown in the mantissa; it does not affect 1.472 + * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3". 1.473 + * See the section on significant digits for more details. 1.474 + * 1.475 + * <li>The number of significant digits shown is determined as 1.476 + * follows: If areSignificantDigitsUsed() returns false, then the 1.477 + * minimum number of significant digits shown is one, and the maximum 1.478 + * number of significant digits shown is the sum of the <em>minimum 1.479 + * integer</em> and <em>maximum fraction</em> digits, and is 1.480 + * unaffected by the maximum integer digits. If this sum is zero, 1.481 + * then all significant digits are shown. If 1.482 + * areSignificantDigitsUsed() returns true, then the significant digit 1.483 + * counts are specified by getMinimumSignificantDigits() and 1.484 + * getMaximumSignificantDigits(). In this case, the number of 1.485 + * integer digits is fixed at one, and there is no exponent grouping. 1.486 + * 1.487 + * <li>Exponential patterns may not contain grouping separators. 1.488 + * </ul> 1.489 + * 1.490 + * <a name="sigdig"><strong>Significant Digits</strong></a> 1.491 + * 1.492 + * <code>DecimalFormat</code> has two ways of controlling how many 1.493 + * digits are shows: (a) significant digits counts, or (b) integer and 1.494 + * fraction digit counts. Integer and fraction digit counts are 1.495 + * described above. When a formatter is using significant digits 1.496 + * counts, the number of integer and fraction digits is not specified 1.497 + * directly, and the formatter settings for these counts are ignored. 1.498 + * Instead, the formatter uses however many integer and fraction 1.499 + * digits are required to display the specified number of significant 1.500 + * digits. Examples: 1.501 + * 1.502 + * <table border=0 cellspacing=3 cellpadding=0> 1.503 + * <tr bgcolor="#ccccff"> 1.504 + * <td align=left>Pattern 1.505 + * <td align=left>Minimum significant digits 1.506 + * <td align=left>Maximum significant digits 1.507 + * <td align=left>Number 1.508 + * <td align=left>Output of format() 1.509 + * <tr valign=top> 1.510 + * <td><code>\@\@\@</code> 1.511 + * <td>3 1.512 + * <td>3 1.513 + * <td>12345 1.514 + * <td><code>12300</code> 1.515 + * <tr valign=top bgcolor="#eeeeff"> 1.516 + * <td><code>\@\@\@</code> 1.517 + * <td>3 1.518 + * <td>3 1.519 + * <td>0.12345 1.520 + * <td><code>0.123</code> 1.521 + * <tr valign=top> 1.522 + * <td><code>\@\@##</code> 1.523 + * <td>2 1.524 + * <td>4 1.525 + * <td>3.14159 1.526 + * <td><code>3.142</code> 1.527 + * <tr valign=top bgcolor="#eeeeff"> 1.528 + * <td><code>\@\@##</code> 1.529 + * <td>2 1.530 + * <td>4 1.531 + * <td>1.23004 1.532 + * <td><code>1.23</code> 1.533 + * </table> 1.534 + * 1.535 + * <ul> 1.536 + * <li>Significant digit counts may be expressed using patterns that 1.537 + * specify a minimum and maximum number of significant digits. These 1.538 + * are indicated by the <code>'@'</code> and <code>'#'</code> 1.539 + * characters. The minimum number of significant digits is the number 1.540 + * of <code>'@'</code> characters. The maximum number of significant 1.541 + * digits is the number of <code>'@'</code> characters plus the number 1.542 + * of <code>'#'</code> characters following on the right. For 1.543 + * example, the pattern <code>"@@@"</code> indicates exactly 3 1.544 + * significant digits. The pattern <code>"@##"</code> indicates from 1.545 + * 1 to 3 significant digits. Trailing zero digits to the right of 1.546 + * the decimal separator are suppressed after the minimum number of 1.547 + * significant digits have been shown. For example, the pattern 1.548 + * <code>"@##"</code> formats the number 0.1203 as 1.549 + * <code>"0.12"</code>. 1.550 + * 1.551 + * <li>If a pattern uses significant digits, it may not contain a 1.552 + * decimal separator, nor the <code>'0'</code> pattern character. 1.553 + * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are 1.554 + * disallowed. 1.555 + * 1.556 + * <li>Any number of <code>'#'</code> characters may be prepended to 1.557 + * the left of the leftmost <code>'@'</code> character. These have no 1.558 + * effect on the minimum and maximum significant digits counts, but 1.559 + * may be used to position grouping separators. For example, 1.560 + * <code>"#,#@#"</code> indicates a minimum of one significant digits, 1.561 + * a maximum of two significant digits, and a grouping size of three. 1.562 + * 1.563 + * <li>In order to enable significant digits formatting, use a pattern 1.564 + * containing the <code>'@'</code> pattern character. Alternatively, 1.565 + * call setSignificantDigitsUsed(TRUE). 1.566 + * 1.567 + * <li>In order to disable significant digits formatting, use a 1.568 + * pattern that does not contain the <code>'@'</code> pattern 1.569 + * character. Alternatively, call setSignificantDigitsUsed(FALSE). 1.570 + * 1.571 + * <li>The number of significant digits has no effect on parsing. 1.572 + * 1.573 + * <li>Significant digits may be used together with exponential notation. Such 1.574 + * patterns are equivalent to a normal exponential pattern with a minimum and 1.575 + * maximum integer digit count of one, a minimum fraction digit count of 1.576 + * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit 1.577 + * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the 1.578 + * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>. 1.579 + * 1.580 + * <li>If signficant digits are in use, then the integer and fraction 1.581 + * digit counts, as set via the API, are ignored. If significant 1.582 + * digits are not in use, then the signficant digit counts, as set via 1.583 + * the API, are ignored. 1.584 + * 1.585 + * </ul> 1.586 + * 1.587 + * <p><strong>Padding</strong> 1.588 + * 1.589 + * <p>DecimalFormat supports padding the result of 1.590 + * format() to a specific width. Padding may be specified either 1.591 + * through the API or through the pattern syntax. In a pattern the pad escape 1.592 + * character, followed by a single pad character, causes padding to be parsed 1.593 + * and formatted. The pad escape character is '*' in unlocalized patterns, and 1.594 + * can be localized using DecimalFormatSymbols::setSymbol() with a 1.595 + * DecimalFormatSymbols::kPadEscapeSymbol 1.596 + * selector. For example, <code>"$*x#,##0.00"</code> formats 123 to 1.597 + * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>. 1.598 + * 1.599 + * <ul> 1.600 + * <li>When padding is in effect, the width of the positive subpattern, 1.601 + * including prefix and suffix, determines the format width. For example, in 1.602 + * the pattern <code>"* #0 o''clock"</code>, the format width is 10. 1.603 + * 1.604 + * <li>The width is counted in 16-bit code units (UChars). 1.605 + * 1.606 + * <li>Some parameters which usually do not matter have meaning when padding is 1.607 + * used, because the pattern width is significant with padding. In the pattern 1.608 + * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##," 1.609 + * do not affect the grouping size or maximum integer digits, but they do affect 1.610 + * the format width. 1.611 + * 1.612 + * <li>Padding may be inserted at one of four locations: before the prefix, 1.613 + * after the prefix, before the suffix, or after the suffix. If padding is 1.614 + * specified in any other location, applyPattern() 1.615 + * sets a failing UErrorCode. If there is no prefix, 1.616 + * before the prefix and after the prefix are equivalent, likewise for the 1.617 + * suffix. 1.618 + * 1.619 + * <li>When specified in a pattern, the 32-bit code point immediately 1.620 + * following the pad escape is the pad character. This may be any character, 1.621 + * including a special pattern character. That is, the pad escape 1.622 + * <em>escapes</em> the following character. If there is no character after 1.623 + * the pad escape, then the pattern is illegal. 1.624 + * 1.625 + * </ul> 1.626 + * 1.627 + * <p><strong>Rounding</strong> 1.628 + * 1.629 + * <p>DecimalFormat supports rounding to a specific increment. For 1.630 + * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the 1.631 + * nearest 0.65 is 1.3. The rounding increment may be specified through the API 1.632 + * or in a pattern. To specify a rounding increment in a pattern, include the 1.633 + * increment in the pattern itself. "#,#50" specifies a rounding increment of 1.634 + * 50. "#,##0.05" specifies a rounding increment of 0.05. 1.635 + * 1.636 + * <p>In the absense of an explicit rounding increment numbers are 1.637 + * rounded to their formatted width. 1.638 + * 1.639 + * <ul> 1.640 + * <li>Rounding only affects the string produced by formatting. It does 1.641 + * not affect parsing or change any numerical values. 1.642 + * 1.643 + * <li>A <em>rounding mode</em> determines how values are rounded; see 1.644 + * DecimalFormat::ERoundingMode. The default rounding mode is 1.645 + * DecimalFormat::kRoundHalfEven. The rounding mode can only be set 1.646 + * through the API; it can not be set with a pattern. 1.647 + * 1.648 + * <li>Some locales use rounding in their currency formats to reflect the 1.649 + * smallest currency denomination. 1.650 + * 1.651 + * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise 1.652 + * behave identically to digit '0'. 1.653 + * </ul> 1.654 + * 1.655 + * <p><strong>Synchronization</strong> 1.656 + * 1.657 + * <p>DecimalFormat objects are not synchronized. Multiple 1.658 + * threads should not access one formatter concurrently. 1.659 + * 1.660 + * <p><strong>Subclassing</strong> 1.661 + * 1.662 + * <p><em>User subclasses are not supported.</em> While clients may write 1.663 + * subclasses, such code will not necessarily work and will not be 1.664 + * guaranteed to work stably from release to release. 1.665 + */ 1.666 +class U_I18N_API DecimalFormat: public NumberFormat { 1.667 +public: 1.668 + /** 1.669 + * Rounding mode. 1.670 + * @stable ICU 2.4 1.671 + */ 1.672 + enum ERoundingMode { 1.673 + kRoundCeiling, /**< Round towards positive infinity */ 1.674 + kRoundFloor, /**< Round towards negative infinity */ 1.675 + kRoundDown, /**< Round towards zero */ 1.676 + kRoundUp, /**< Round away from zero */ 1.677 + kRoundHalfEven, /**< Round towards the nearest integer, or 1.678 + towards the nearest even integer if equidistant */ 1.679 + kRoundHalfDown, /**< Round towards the nearest integer, or 1.680 + towards zero if equidistant */ 1.681 + kRoundHalfUp, /**< Round towards the nearest integer, or 1.682 + away from zero if equidistant */ 1.683 + /** 1.684 + * Return U_FORMAT_INEXACT_ERROR if number does not format exactly. 1.685 + * @stable ICU 4.8 1.686 + */ 1.687 + kRoundUnnecessary 1.688 + }; 1.689 + 1.690 + /** 1.691 + * Pad position. 1.692 + * @stable ICU 2.4 1.693 + */ 1.694 + enum EPadPosition { 1.695 + kPadBeforePrefix, 1.696 + kPadAfterPrefix, 1.697 + kPadBeforeSuffix, 1.698 + kPadAfterSuffix 1.699 + }; 1.700 + 1.701 + /** 1.702 + * Create a DecimalFormat using the default pattern and symbols 1.703 + * for the default locale. This is a convenient way to obtain a 1.704 + * DecimalFormat when internationalization is not the main concern. 1.705 + * <P> 1.706 + * To obtain standard formats for a given locale, use the factory methods 1.707 + * on NumberFormat such as createInstance. These factories will 1.708 + * return the most appropriate sub-class of NumberFormat for a given 1.709 + * locale. 1.710 + * @param status Output param set to success/failure code. If the 1.711 + * pattern is invalid this will be set to a failure code. 1.712 + * @stable ICU 2.0 1.713 + */ 1.714 + DecimalFormat(UErrorCode& status); 1.715 + 1.716 + /** 1.717 + * Create a DecimalFormat from the given pattern and the symbols 1.718 + * for the default locale. This is a convenient way to obtain a 1.719 + * DecimalFormat when internationalization is not the main concern. 1.720 + * <P> 1.721 + * To obtain standard formats for a given locale, use the factory methods 1.722 + * on NumberFormat such as createInstance. These factories will 1.723 + * return the most appropriate sub-class of NumberFormat for a given 1.724 + * locale. 1.725 + * @param pattern A non-localized pattern string. 1.726 + * @param status Output param set to success/failure code. If the 1.727 + * pattern is invalid this will be set to a failure code. 1.728 + * @stable ICU 2.0 1.729 + */ 1.730 + DecimalFormat(const UnicodeString& pattern, 1.731 + UErrorCode& status); 1.732 + 1.733 + /** 1.734 + * Create a DecimalFormat from the given pattern and symbols. 1.735 + * Use this constructor when you need to completely customize the 1.736 + * behavior of the format. 1.737 + * <P> 1.738 + * To obtain standard formats for a given 1.739 + * locale, use the factory methods on NumberFormat such as 1.740 + * createInstance or createCurrencyInstance. If you need only minor adjustments 1.741 + * to a standard format, you can modify the format returned by 1.742 + * a NumberFormat factory method. 1.743 + * 1.744 + * @param pattern a non-localized pattern string 1.745 + * @param symbolsToAdopt the set of symbols to be used. The caller should not 1.746 + * delete this object after making this call. 1.747 + * @param status Output param set to success/failure code. If the 1.748 + * pattern is invalid this will be set to a failure code. 1.749 + * @stable ICU 2.0 1.750 + */ 1.751 + DecimalFormat( const UnicodeString& pattern, 1.752 + DecimalFormatSymbols* symbolsToAdopt, 1.753 + UErrorCode& status); 1.754 + 1.755 +#ifndef U_HIDE_INTERNAL_API 1.756 + /** 1.757 + * This API is for ICU use only. 1.758 + * Create a DecimalFormat from the given pattern, symbols, and style. 1.759 + * 1.760 + * @param pattern a non-localized pattern string 1.761 + * @param symbolsToAdopt the set of symbols to be used. The caller should not 1.762 + * delete this object after making this call. 1.763 + * @param style style of decimal format 1.764 + * @param status Output param set to success/failure code. If the 1.765 + * pattern is invalid this will be set to a failure code. 1.766 + * @internal 1.767 + */ 1.768 + DecimalFormat( const UnicodeString& pattern, 1.769 + DecimalFormatSymbols* symbolsToAdopt, 1.770 + UNumberFormatStyle style, 1.771 + UErrorCode& status); 1.772 + 1.773 +#if UCONFIG_HAVE_PARSEALLINPUT 1.774 + /** 1.775 + * @internal 1.776 + */ 1.777 + void setParseAllInput(UNumberFormatAttributeValue value); 1.778 +#endif 1.779 + 1.780 +#endif /* U_HIDE_INTERNAL_API */ 1.781 + 1.782 + 1.783 + /** 1.784 + * Set an integer attribute on this DecimalFormat. 1.785 + * May return U_UNSUPPORTED_ERROR if this instance does not support 1.786 + * the specified attribute. 1.787 + * @param attr the attribute to set 1.788 + * @param newvalue new value 1.789 + * @param status the error type 1.790 + * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) ) 1.791 + * @draft ICU 51 1.792 + */ 1.793 + virtual DecimalFormat& setAttribute( UNumberFormatAttribute attr, 1.794 + int32_t newvalue, 1.795 + UErrorCode &status); 1.796 + 1.797 + /** 1.798 + * Get an integer 1.799 + * May return U_UNSUPPORTED_ERROR if this instance does not support 1.800 + * the specified attribute. 1.801 + * @param attr the attribute to set 1.802 + * @param status the error type 1.803 + * @return the attribute value. Undefined if there is an error. 1.804 + * @draft ICU 51 1.805 + */ 1.806 + virtual int32_t getAttribute( UNumberFormatAttribute attr, 1.807 + UErrorCode &status) const; 1.808 + 1.809 + 1.810 + 1.811 + /** 1.812 + * Create a DecimalFormat from the given pattern and symbols. 1.813 + * Use this constructor when you need to completely customize the 1.814 + * behavior of the format. 1.815 + * <P> 1.816 + * To obtain standard formats for a given 1.817 + * locale, use the factory methods on NumberFormat such as 1.818 + * createInstance or createCurrencyInstance. If you need only minor adjustments 1.819 + * to a standard format, you can modify the format returned by 1.820 + * a NumberFormat factory method. 1.821 + * 1.822 + * @param pattern a non-localized pattern string 1.823 + * @param symbolsToAdopt the set of symbols to be used. The caller should not 1.824 + * delete this object after making this call. 1.825 + * @param parseError Output param to receive errors occured during parsing 1.826 + * @param status Output param set to success/failure code. If the 1.827 + * pattern is invalid this will be set to a failure code. 1.828 + * @stable ICU 2.0 1.829 + */ 1.830 + DecimalFormat( const UnicodeString& pattern, 1.831 + DecimalFormatSymbols* symbolsToAdopt, 1.832 + UParseError& parseError, 1.833 + UErrorCode& status); 1.834 + /** 1.835 + * Create a DecimalFormat from the given pattern and symbols. 1.836 + * Use this constructor when you need to completely customize the 1.837 + * behavior of the format. 1.838 + * <P> 1.839 + * To obtain standard formats for a given 1.840 + * locale, use the factory methods on NumberFormat such as 1.841 + * createInstance or createCurrencyInstance. If you need only minor adjustments 1.842 + * to a standard format, you can modify the format returned by 1.843 + * a NumberFormat factory method. 1.844 + * 1.845 + * @param pattern a non-localized pattern string 1.846 + * @param symbols the set of symbols to be used 1.847 + * @param status Output param set to success/failure code. If the 1.848 + * pattern is invalid this will be set to a failure code. 1.849 + * @stable ICU 2.0 1.850 + */ 1.851 + DecimalFormat( const UnicodeString& pattern, 1.852 + const DecimalFormatSymbols& symbols, 1.853 + UErrorCode& status); 1.854 + 1.855 + /** 1.856 + * Copy constructor. 1.857 + * 1.858 + * @param source the DecimalFormat object to be copied from. 1.859 + * @stable ICU 2.0 1.860 + */ 1.861 + DecimalFormat(const DecimalFormat& source); 1.862 + 1.863 + /** 1.864 + * Assignment operator. 1.865 + * 1.866 + * @param rhs the DecimalFormat object to be copied. 1.867 + * @stable ICU 2.0 1.868 + */ 1.869 + DecimalFormat& operator=(const DecimalFormat& rhs); 1.870 + 1.871 + /** 1.872 + * Destructor. 1.873 + * @stable ICU 2.0 1.874 + */ 1.875 + virtual ~DecimalFormat(); 1.876 + 1.877 + /** 1.878 + * Clone this Format object polymorphically. The caller owns the 1.879 + * result and should delete it when done. 1.880 + * 1.881 + * @return a polymorphic copy of this DecimalFormat. 1.882 + * @stable ICU 2.0 1.883 + */ 1.884 + virtual Format* clone(void) const; 1.885 + 1.886 + /** 1.887 + * Return true if the given Format objects are semantically equal. 1.888 + * Objects of different subclasses are considered unequal. 1.889 + * 1.890 + * @param other the object to be compared with. 1.891 + * @return true if the given Format objects are semantically equal. 1.892 + * @stable ICU 2.0 1.893 + */ 1.894 + virtual UBool operator==(const Format& other) const; 1.895 + 1.896 + 1.897 + using NumberFormat::format; 1.898 + 1.899 + /** 1.900 + * Format a double or long number using base-10 representation. 1.901 + * 1.902 + * @param number The value to be formatted. 1.903 + * @param appendTo Output parameter to receive result. 1.904 + * Result is appended to existing contents. 1.905 + * @param pos On input: an alignment field, if desired. 1.906 + * On output: the offsets of the alignment field. 1.907 + * @return Reference to 'appendTo' parameter. 1.908 + * @stable ICU 2.0 1.909 + */ 1.910 + virtual UnicodeString& format(double number, 1.911 + UnicodeString& appendTo, 1.912 + FieldPosition& pos) const; 1.913 + 1.914 + 1.915 + /** 1.916 + * Format a double or long number using base-10 representation. 1.917 + * 1.918 + * @param number The value to be formatted. 1.919 + * @param appendTo Output parameter to receive result. 1.920 + * Result is appended to existing contents. 1.921 + * @param pos On input: an alignment field, if desired. 1.922 + * On output: the offsets of the alignment field. 1.923 + * @param status 1.924 + * @return Reference to 'appendTo' parameter. 1.925 + * @internal 1.926 + */ 1.927 + virtual UnicodeString& format(double number, 1.928 + UnicodeString& appendTo, 1.929 + FieldPosition& pos, 1.930 + UErrorCode &status) const; 1.931 + 1.932 + /** 1.933 + * Format a double or long number using base-10 representation. 1.934 + * 1.935 + * @param number The value to be formatted. 1.936 + * @param appendTo Output parameter to receive result. 1.937 + * Result is appended to existing contents. 1.938 + * @param posIter On return, can be used to iterate over positions 1.939 + * of fields generated by this format call. 1.940 + * Can be NULL. 1.941 + * @param status Output param filled with success/failure status. 1.942 + * @return Reference to 'appendTo' parameter. 1.943 + * @stable 4.4 1.944 + */ 1.945 + virtual UnicodeString& format(double number, 1.946 + UnicodeString& appendTo, 1.947 + FieldPositionIterator* posIter, 1.948 + UErrorCode& status) const; 1.949 + 1.950 + /** 1.951 + * Format a long number using base-10 representation. 1.952 + * 1.953 + * @param number The value to be formatted. 1.954 + * @param appendTo Output parameter to receive result. 1.955 + * Result is appended to existing contents. 1.956 + * @param pos On input: an alignment field, if desired. 1.957 + * On output: the offsets of the alignment field. 1.958 + * @return Reference to 'appendTo' parameter. 1.959 + * @stable ICU 2.0 1.960 + */ 1.961 + virtual UnicodeString& format(int32_t number, 1.962 + UnicodeString& appendTo, 1.963 + FieldPosition& pos) const; 1.964 + 1.965 + /** 1.966 + * Format a long number using base-10 representation. 1.967 + * 1.968 + * @param number The value to be formatted. 1.969 + * @param appendTo Output parameter to receive result. 1.970 + * Result is appended to existing contents. 1.971 + * @param pos On input: an alignment field, if desired. 1.972 + * On output: the offsets of the alignment field. 1.973 + * @return Reference to 'appendTo' parameter. 1.974 + * @internal 1.975 + */ 1.976 + virtual UnicodeString& format(int32_t number, 1.977 + UnicodeString& appendTo, 1.978 + FieldPosition& pos, 1.979 + UErrorCode &status) const; 1.980 + 1.981 + /** 1.982 + * Format a long number using base-10 representation. 1.983 + * 1.984 + * @param number The value to be formatted. 1.985 + * @param appendTo Output parameter to receive result. 1.986 + * Result is appended to existing contents. 1.987 + * @param posIter On return, can be used to iterate over positions 1.988 + * of fields generated by this format call. 1.989 + * Can be NULL. 1.990 + * @param status Output param filled with success/failure status. 1.991 + * @return Reference to 'appendTo' parameter. 1.992 + * @stable 4.4 1.993 + */ 1.994 + virtual UnicodeString& format(int32_t number, 1.995 + UnicodeString& appendTo, 1.996 + FieldPositionIterator* posIter, 1.997 + UErrorCode& status) const; 1.998 + 1.999 + /** 1.1000 + * Format an int64 number using base-10 representation. 1.1001 + * 1.1002 + * @param number The value to be formatted. 1.1003 + * @param appendTo Output parameter to receive result. 1.1004 + * Result is appended to existing contents. 1.1005 + * @param pos On input: an alignment field, if desired. 1.1006 + * On output: the offsets of the alignment field. 1.1007 + * @return Reference to 'appendTo' parameter. 1.1008 + * @stable ICU 2.8 1.1009 + */ 1.1010 + virtual UnicodeString& format(int64_t number, 1.1011 + UnicodeString& appendTo, 1.1012 + FieldPosition& pos) const; 1.1013 + 1.1014 + /** 1.1015 + * Format an int64 number using base-10 representation. 1.1016 + * 1.1017 + * @param number The value to be formatted. 1.1018 + * @param appendTo Output parameter to receive result. 1.1019 + * Result is appended to existing contents. 1.1020 + * @param pos On input: an alignment field, if desired. 1.1021 + * On output: the offsets of the alignment field. 1.1022 + * @return Reference to 'appendTo' parameter. 1.1023 + * @internal 1.1024 + */ 1.1025 + virtual UnicodeString& format(int64_t number, 1.1026 + UnicodeString& appendTo, 1.1027 + FieldPosition& pos, 1.1028 + UErrorCode &status) const; 1.1029 + 1.1030 + /** 1.1031 + * Format an int64 number using base-10 representation. 1.1032 + * 1.1033 + * @param number The value to be formatted. 1.1034 + * @param appendTo Output parameter to receive result. 1.1035 + * Result is appended to existing contents. 1.1036 + * @param posIter On return, can be used to iterate over positions 1.1037 + * of fields generated by this format call. 1.1038 + * Can be NULL. 1.1039 + * @param status Output param filled with success/failure status. 1.1040 + * @return Reference to 'appendTo' parameter. 1.1041 + * @stable 4.4 1.1042 + */ 1.1043 + virtual UnicodeString& format(int64_t number, 1.1044 + UnicodeString& appendTo, 1.1045 + FieldPositionIterator* posIter, 1.1046 + UErrorCode& status) const; 1.1047 + 1.1048 + /** 1.1049 + * Format a decimal number. 1.1050 + * The syntax of the unformatted number is a "numeric string" 1.1051 + * as defined in the Decimal Arithmetic Specification, available at 1.1052 + * http://speleotrove.com/decimal 1.1053 + * 1.1054 + * @param number The unformatted number, as a string. 1.1055 + * @param appendTo Output parameter to receive result. 1.1056 + * Result is appended to existing contents. 1.1057 + * @param posIter On return, can be used to iterate over positions 1.1058 + * of fields generated by this format call. 1.1059 + * Can be NULL. 1.1060 + * @param status Output param filled with success/failure status. 1.1061 + * @return Reference to 'appendTo' parameter. 1.1062 + * @stable 4.4 1.1063 + */ 1.1064 + virtual UnicodeString& format(const StringPiece &number, 1.1065 + UnicodeString& appendTo, 1.1066 + FieldPositionIterator* posIter, 1.1067 + UErrorCode& status) const; 1.1068 + 1.1069 + 1.1070 + /** 1.1071 + * Format a decimal number. 1.1072 + * The number is a DigitList wrapper onto a floating point decimal number. 1.1073 + * The default implementation in NumberFormat converts the decimal number 1.1074 + * to a double and formats that. 1.1075 + * 1.1076 + * @param number The number, a DigitList format Decimal Floating Point. 1.1077 + * @param appendTo Output parameter to receive result. 1.1078 + * Result is appended to existing contents. 1.1079 + * @param posIter On return, can be used to iterate over positions 1.1080 + * of fields generated by this format call. 1.1081 + * @param status Output param filled with success/failure status. 1.1082 + * @return Reference to 'appendTo' parameter. 1.1083 + * @internal 1.1084 + */ 1.1085 + virtual UnicodeString& format(const DigitList &number, 1.1086 + UnicodeString& appendTo, 1.1087 + FieldPositionIterator* posIter, 1.1088 + UErrorCode& status) const; 1.1089 + 1.1090 + /** 1.1091 + * Format a decimal number. 1.1092 + * The number is a DigitList wrapper onto a floating point decimal number. 1.1093 + * The default implementation in NumberFormat converts the decimal number 1.1094 + * to a double and formats that. 1.1095 + * 1.1096 + * @param number The number, a DigitList format Decimal Floating Point. 1.1097 + * @param appendTo Output parameter to receive result. 1.1098 + * Result is appended to existing contents. 1.1099 + * @param pos On input: an alignment field, if desired. 1.1100 + * On output: the offsets of the alignment field. 1.1101 + * @param status Output param filled with success/failure status. 1.1102 + * @return Reference to 'appendTo' parameter. 1.1103 + * @internal 1.1104 + */ 1.1105 + virtual UnicodeString& format(const DigitList &number, 1.1106 + UnicodeString& appendTo, 1.1107 + FieldPosition& pos, 1.1108 + UErrorCode& status) const; 1.1109 + 1.1110 + using NumberFormat::parse; 1.1111 + 1.1112 + /** 1.1113 + * Parse the given string using this object's choices. The method 1.1114 + * does string comparisons to try to find an optimal match. 1.1115 + * If no object can be parsed, index is unchanged, and NULL is 1.1116 + * returned. The result is returned as the most parsimonious 1.1117 + * type of Formattable that will accomodate all of the 1.1118 + * necessary precision. For example, if the result is exactly 12, 1.1119 + * it will be returned as a long. However, if it is 1.5, it will 1.1120 + * be returned as a double. 1.1121 + * 1.1122 + * @param text The text to be parsed. 1.1123 + * @param result Formattable to be set to the parse result. 1.1124 + * If parse fails, return contents are undefined. 1.1125 + * @param parsePosition The position to start parsing at on input. 1.1126 + * On output, moved to after the last successfully 1.1127 + * parse character. On parse failure, does not change. 1.1128 + * @see Formattable 1.1129 + * @stable ICU 2.0 1.1130 + */ 1.1131 + virtual void parse(const UnicodeString& text, 1.1132 + Formattable& result, 1.1133 + ParsePosition& parsePosition) const; 1.1134 + 1.1135 + /** 1.1136 + * Parses text from the given string as a currency amount. Unlike 1.1137 + * the parse() method, this method will attempt to parse a generic 1.1138 + * currency name, searching for a match of this object's locale's 1.1139 + * currency display names, or for a 3-letter ISO currency code. 1.1140 + * This method will fail if this format is not a currency format, 1.1141 + * that is, if it does not contain the currency pattern symbol 1.1142 + * (U+00A4) in its prefix or suffix. 1.1143 + * 1.1144 + * @param text the string to parse 1.1145 + * @param pos input-output position; on input, the position within text 1.1146 + * to match; must have 0 <= pos.getIndex() < text.length(); 1.1147 + * on output, the position after the last matched character. 1.1148 + * If the parse fails, the position in unchanged upon output. 1.1149 + * @return if parse succeeds, a pointer to a newly-created CurrencyAmount 1.1150 + * object (owned by the caller) containing information about 1.1151 + * the parsed currency; if parse fails, this is NULL. 1.1152 + * @stable ICU 49 1.1153 + */ 1.1154 + virtual CurrencyAmount* parseCurrency(const UnicodeString& text, 1.1155 + ParsePosition& pos) const; 1.1156 + 1.1157 + /** 1.1158 + * Returns the decimal format symbols, which is generally not changed 1.1159 + * by the programmer or user. 1.1160 + * @return desired DecimalFormatSymbols 1.1161 + * @see DecimalFormatSymbols 1.1162 + * @stable ICU 2.0 1.1163 + */ 1.1164 + virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const; 1.1165 + 1.1166 + /** 1.1167 + * Sets the decimal format symbols, which is generally not changed 1.1168 + * by the programmer or user. 1.1169 + * @param symbolsToAdopt DecimalFormatSymbols to be adopted. 1.1170 + * @stable ICU 2.0 1.1171 + */ 1.1172 + virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt); 1.1173 + 1.1174 + /** 1.1175 + * Sets the decimal format symbols, which is generally not changed 1.1176 + * by the programmer or user. 1.1177 + * @param symbols DecimalFormatSymbols. 1.1178 + * @stable ICU 2.0 1.1179 + */ 1.1180 + virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols); 1.1181 + 1.1182 + 1.1183 + /** 1.1184 + * Returns the currency plural format information, 1.1185 + * which is generally not changed by the programmer or user. 1.1186 + * @return desired CurrencyPluralInfo 1.1187 + * @stable ICU 4.2 1.1188 + */ 1.1189 + virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const; 1.1190 + 1.1191 + /** 1.1192 + * Sets the currency plural format information, 1.1193 + * which is generally not changed by the programmer or user. 1.1194 + * @param toAdopt CurrencyPluralInfo to be adopted. 1.1195 + * @stable ICU 4.2 1.1196 + */ 1.1197 + virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt); 1.1198 + 1.1199 + /** 1.1200 + * Sets the currency plural format information, 1.1201 + * which is generally not changed by the programmer or user. 1.1202 + * @param info Currency Plural Info. 1.1203 + * @stable ICU 4.2 1.1204 + */ 1.1205 + virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info); 1.1206 + 1.1207 + 1.1208 + /** 1.1209 + * Get the positive prefix. 1.1210 + * 1.1211 + * @param result Output param which will receive the positive prefix. 1.1212 + * @return A reference to 'result'. 1.1213 + * Examples: +123, $123, sFr123 1.1214 + * @stable ICU 2.0 1.1215 + */ 1.1216 + UnicodeString& getPositivePrefix(UnicodeString& result) const; 1.1217 + 1.1218 + /** 1.1219 + * Set the positive prefix. 1.1220 + * 1.1221 + * @param newValue the new value of the the positive prefix to be set. 1.1222 + * Examples: +123, $123, sFr123 1.1223 + * @stable ICU 2.0 1.1224 + */ 1.1225 + virtual void setPositivePrefix(const UnicodeString& newValue); 1.1226 + 1.1227 + /** 1.1228 + * Get the negative prefix. 1.1229 + * 1.1230 + * @param result Output param which will receive the negative prefix. 1.1231 + * @return A reference to 'result'. 1.1232 + * Examples: -123, ($123) (with negative suffix), sFr-123 1.1233 + * @stable ICU 2.0 1.1234 + */ 1.1235 + UnicodeString& getNegativePrefix(UnicodeString& result) const; 1.1236 + 1.1237 + /** 1.1238 + * Set the negative prefix. 1.1239 + * 1.1240 + * @param newValue the new value of the the negative prefix to be set. 1.1241 + * Examples: -123, ($123) (with negative suffix), sFr-123 1.1242 + * @stable ICU 2.0 1.1243 + */ 1.1244 + virtual void setNegativePrefix(const UnicodeString& newValue); 1.1245 + 1.1246 + /** 1.1247 + * Get the positive suffix. 1.1248 + * 1.1249 + * @param result Output param which will receive the positive suffix. 1.1250 + * @return A reference to 'result'. 1.1251 + * Example: 123% 1.1252 + * @stable ICU 2.0 1.1253 + */ 1.1254 + UnicodeString& getPositiveSuffix(UnicodeString& result) const; 1.1255 + 1.1256 + /** 1.1257 + * Set the positive suffix. 1.1258 + * 1.1259 + * @param newValue the new value of the positive suffix to be set. 1.1260 + * Example: 123% 1.1261 + * @stable ICU 2.0 1.1262 + */ 1.1263 + virtual void setPositiveSuffix(const UnicodeString& newValue); 1.1264 + 1.1265 + /** 1.1266 + * Get the negative suffix. 1.1267 + * 1.1268 + * @param result Output param which will receive the negative suffix. 1.1269 + * @return A reference to 'result'. 1.1270 + * Examples: -123%, ($123) (with positive suffixes) 1.1271 + * @stable ICU 2.0 1.1272 + */ 1.1273 + UnicodeString& getNegativeSuffix(UnicodeString& result) const; 1.1274 + 1.1275 + /** 1.1276 + * Set the negative suffix. 1.1277 + * 1.1278 + * @param newValue the new value of the negative suffix to be set. 1.1279 + * Examples: 123% 1.1280 + * @stable ICU 2.0 1.1281 + */ 1.1282 + virtual void setNegativeSuffix(const UnicodeString& newValue); 1.1283 + 1.1284 + /** 1.1285 + * Get the multiplier for use in percent, permill, etc. 1.1286 + * For a percentage, set the suffixes to have "%" and the multiplier to be 100. 1.1287 + * (For Arabic, use arabic percent symbol). 1.1288 + * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000. 1.1289 + * 1.1290 + * @return the multiplier for use in percent, permill, etc. 1.1291 + * Examples: with 100, 1.23 -> "123", and "123" -> 1.23 1.1292 + * @stable ICU 2.0 1.1293 + */ 1.1294 + int32_t getMultiplier(void) const; 1.1295 + 1.1296 + /** 1.1297 + * Set the multiplier for use in percent, permill, etc. 1.1298 + * For a percentage, set the suffixes to have "%" and the multiplier to be 100. 1.1299 + * (For Arabic, use arabic percent symbol). 1.1300 + * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000. 1.1301 + * 1.1302 + * @param newValue the new value of the multiplier for use in percent, permill, etc. 1.1303 + * Examples: with 100, 1.23 -> "123", and "123" -> 1.23 1.1304 + * @stable ICU 2.0 1.1305 + */ 1.1306 + virtual void setMultiplier(int32_t newValue); 1.1307 + 1.1308 + /** 1.1309 + * Get the rounding increment. 1.1310 + * @return A positive rounding increment, or 0.0 if a custom rounding 1.1311 + * increment is not in effect. 1.1312 + * @see #setRoundingIncrement 1.1313 + * @see #getRoundingMode 1.1314 + * @see #setRoundingMode 1.1315 + * @stable ICU 2.0 1.1316 + */ 1.1317 + virtual double getRoundingIncrement(void) const; 1.1318 + 1.1319 + /** 1.1320 + * Set the rounding increment. In the absence of a rounding increment, 1.1321 + * numbers will be rounded to the number of digits displayed. 1.1322 + * @param newValue A positive rounding increment, or 0.0 to 1.1323 + * use the default rounding increment. 1.1324 + * Negative increments are equivalent to 0.0. 1.1325 + * @see #getRoundingIncrement 1.1326 + * @see #getRoundingMode 1.1327 + * @see #setRoundingMode 1.1328 + * @stable ICU 2.0 1.1329 + */ 1.1330 + virtual void setRoundingIncrement(double newValue); 1.1331 + 1.1332 + /** 1.1333 + * Get the rounding mode. 1.1334 + * @return A rounding mode 1.1335 + * @see #setRoundingIncrement 1.1336 + * @see #getRoundingIncrement 1.1337 + * @see #setRoundingMode 1.1338 + * @stable ICU 2.0 1.1339 + */ 1.1340 + virtual ERoundingMode getRoundingMode(void) const; 1.1341 + 1.1342 + /** 1.1343 + * Set the rounding mode. 1.1344 + * @param roundingMode A rounding mode 1.1345 + * @see #setRoundingIncrement 1.1346 + * @see #getRoundingIncrement 1.1347 + * @see #getRoundingMode 1.1348 + * @stable ICU 2.0 1.1349 + */ 1.1350 + virtual void setRoundingMode(ERoundingMode roundingMode); 1.1351 + 1.1352 + /** 1.1353 + * Get the width to which the output of format() is padded. 1.1354 + * The width is counted in 16-bit code units. 1.1355 + * @return the format width, or zero if no padding is in effect 1.1356 + * @see #setFormatWidth 1.1357 + * @see #getPadCharacterString 1.1358 + * @see #setPadCharacter 1.1359 + * @see #getPadPosition 1.1360 + * @see #setPadPosition 1.1361 + * @stable ICU 2.0 1.1362 + */ 1.1363 + virtual int32_t getFormatWidth(void) const; 1.1364 + 1.1365 + /** 1.1366 + * Set the width to which the output of format() is padded. 1.1367 + * The width is counted in 16-bit code units. 1.1368 + * This method also controls whether padding is enabled. 1.1369 + * @param width the width to which to pad the result of 1.1370 + * format(), or zero to disable padding. A negative 1.1371 + * width is equivalent to 0. 1.1372 + * @see #getFormatWidth 1.1373 + * @see #getPadCharacterString 1.1374 + * @see #setPadCharacter 1.1375 + * @see #getPadPosition 1.1376 + * @see #setPadPosition 1.1377 + * @stable ICU 2.0 1.1378 + */ 1.1379 + virtual void setFormatWidth(int32_t width); 1.1380 + 1.1381 + /** 1.1382 + * Get the pad character used to pad to the format width. The 1.1383 + * default is ' '. 1.1384 + * @return a string containing the pad character. This will always 1.1385 + * have a length of one 32-bit code point. 1.1386 + * @see #setFormatWidth 1.1387 + * @see #getFormatWidth 1.1388 + * @see #setPadCharacter 1.1389 + * @see #getPadPosition 1.1390 + * @see #setPadPosition 1.1391 + * @stable ICU 2.0 1.1392 + */ 1.1393 + virtual UnicodeString getPadCharacterString() const; 1.1394 + 1.1395 + /** 1.1396 + * Set the character used to pad to the format width. If padding 1.1397 + * is not enabled, then this will take effect if padding is later 1.1398 + * enabled. 1.1399 + * @param padChar a string containing the pad charcter. If the string 1.1400 + * has length 0, then the pad characer is set to ' '. Otherwise 1.1401 + * padChar.char32At(0) will be used as the pad character. 1.1402 + * @see #setFormatWidth 1.1403 + * @see #getFormatWidth 1.1404 + * @see #getPadCharacterString 1.1405 + * @see #getPadPosition 1.1406 + * @see #setPadPosition 1.1407 + * @stable ICU 2.0 1.1408 + */ 1.1409 + virtual void setPadCharacter(const UnicodeString &padChar); 1.1410 + 1.1411 + /** 1.1412 + * Get the position at which padding will take place. This is the location 1.1413 + * at which padding will be inserted if the result of format() 1.1414 + * is shorter than the format width. 1.1415 + * @return the pad position, one of kPadBeforePrefix, 1.1416 + * kPadAfterPrefix, kPadBeforeSuffix, or 1.1417 + * kPadAfterSuffix. 1.1418 + * @see #setFormatWidth 1.1419 + * @see #getFormatWidth 1.1420 + * @see #setPadCharacter 1.1421 + * @see #getPadCharacterString 1.1422 + * @see #setPadPosition 1.1423 + * @see #EPadPosition 1.1424 + * @stable ICU 2.0 1.1425 + */ 1.1426 + virtual EPadPosition getPadPosition(void) const; 1.1427 + 1.1428 + /** 1.1429 + * Set the position at which padding will take place. This is the location 1.1430 + * at which padding will be inserted if the result of format() 1.1431 + * is shorter than the format width. This has no effect unless padding is 1.1432 + * enabled. 1.1433 + * @param padPos the pad position, one of kPadBeforePrefix, 1.1434 + * kPadAfterPrefix, kPadBeforeSuffix, or 1.1435 + * kPadAfterSuffix. 1.1436 + * @see #setFormatWidth 1.1437 + * @see #getFormatWidth 1.1438 + * @see #setPadCharacter 1.1439 + * @see #getPadCharacterString 1.1440 + * @see #getPadPosition 1.1441 + * @see #EPadPosition 1.1442 + * @stable ICU 2.0 1.1443 + */ 1.1444 + virtual void setPadPosition(EPadPosition padPos); 1.1445 + 1.1446 + /** 1.1447 + * Return whether or not scientific notation is used. 1.1448 + * @return TRUE if this object formats and parses scientific notation 1.1449 + * @see #setScientificNotation 1.1450 + * @see #getMinimumExponentDigits 1.1451 + * @see #setMinimumExponentDigits 1.1452 + * @see #isExponentSignAlwaysShown 1.1453 + * @see #setExponentSignAlwaysShown 1.1454 + * @stable ICU 2.0 1.1455 + */ 1.1456 + virtual UBool isScientificNotation(void) const; 1.1457 + 1.1458 + /** 1.1459 + * Set whether or not scientific notation is used. When scientific notation 1.1460 + * is used, the effective maximum number of integer digits is <= 8. If the 1.1461 + * maximum number of integer digits is set to more than 8, the effective 1.1462 + * maximum will be 1. This allows this call to generate a 'default' scientific 1.1463 + * number format without additional changes. 1.1464 + * @param useScientific TRUE if this object formats and parses scientific 1.1465 + * notation 1.1466 + * @see #isScientificNotation 1.1467 + * @see #getMinimumExponentDigits 1.1468 + * @see #setMinimumExponentDigits 1.1469 + * @see #isExponentSignAlwaysShown 1.1470 + * @see #setExponentSignAlwaysShown 1.1471 + * @stable ICU 2.0 1.1472 + */ 1.1473 + virtual void setScientificNotation(UBool useScientific); 1.1474 + 1.1475 + /** 1.1476 + * Return the minimum exponent digits that will be shown. 1.1477 + * @return the minimum exponent digits that will be shown 1.1478 + * @see #setScientificNotation 1.1479 + * @see #isScientificNotation 1.1480 + * @see #setMinimumExponentDigits 1.1481 + * @see #isExponentSignAlwaysShown 1.1482 + * @see #setExponentSignAlwaysShown 1.1483 + * @stable ICU 2.0 1.1484 + */ 1.1485 + virtual int8_t getMinimumExponentDigits(void) const; 1.1486 + 1.1487 + /** 1.1488 + * Set the minimum exponent digits that will be shown. This has no 1.1489 + * effect unless scientific notation is in use. 1.1490 + * @param minExpDig a value >= 1 indicating the fewest exponent digits 1.1491 + * that will be shown. Values less than 1 will be treated as 1. 1.1492 + * @see #setScientificNotation 1.1493 + * @see #isScientificNotation 1.1494 + * @see #getMinimumExponentDigits 1.1495 + * @see #isExponentSignAlwaysShown 1.1496 + * @see #setExponentSignAlwaysShown 1.1497 + * @stable ICU 2.0 1.1498 + */ 1.1499 + virtual void setMinimumExponentDigits(int8_t minExpDig); 1.1500 + 1.1501 + /** 1.1502 + * Return whether the exponent sign is always shown. 1.1503 + * @return TRUE if the exponent is always prefixed with either the 1.1504 + * localized minus sign or the localized plus sign, false if only negative 1.1505 + * exponents are prefixed with the localized minus sign. 1.1506 + * @see #setScientificNotation 1.1507 + * @see #isScientificNotation 1.1508 + * @see #setMinimumExponentDigits 1.1509 + * @see #getMinimumExponentDigits 1.1510 + * @see #setExponentSignAlwaysShown 1.1511 + * @stable ICU 2.0 1.1512 + */ 1.1513 + virtual UBool isExponentSignAlwaysShown(void) const; 1.1514 + 1.1515 + /** 1.1516 + * Set whether the exponent sign is always shown. This has no effect 1.1517 + * unless scientific notation is in use. 1.1518 + * @param expSignAlways TRUE if the exponent is always prefixed with either 1.1519 + * the localized minus sign or the localized plus sign, false if only 1.1520 + * negative exponents are prefixed with the localized minus sign. 1.1521 + * @see #setScientificNotation 1.1522 + * @see #isScientificNotation 1.1523 + * @see #setMinimumExponentDigits 1.1524 + * @see #getMinimumExponentDigits 1.1525 + * @see #isExponentSignAlwaysShown 1.1526 + * @stable ICU 2.0 1.1527 + */ 1.1528 + virtual void setExponentSignAlwaysShown(UBool expSignAlways); 1.1529 + 1.1530 + /** 1.1531 + * Return the grouping size. Grouping size is the number of digits between 1.1532 + * grouping separators in the integer portion of a number. For example, 1.1533 + * in the number "123,456.78", the grouping size is 3. 1.1534 + * 1.1535 + * @return the grouping size. 1.1536 + * @see setGroupingSize 1.1537 + * @see NumberFormat::isGroupingUsed 1.1538 + * @see DecimalFormatSymbols::getGroupingSeparator 1.1539 + * @stable ICU 2.0 1.1540 + */ 1.1541 + int32_t getGroupingSize(void) const; 1.1542 + 1.1543 + /** 1.1544 + * Set the grouping size. Grouping size is the number of digits between 1.1545 + * grouping separators in the integer portion of a number. For example, 1.1546 + * in the number "123,456.78", the grouping size is 3. 1.1547 + * 1.1548 + * @param newValue the new value of the grouping size. 1.1549 + * @see getGroupingSize 1.1550 + * @see NumberFormat::setGroupingUsed 1.1551 + * @see DecimalFormatSymbols::setGroupingSeparator 1.1552 + * @stable ICU 2.0 1.1553 + */ 1.1554 + virtual void setGroupingSize(int32_t newValue); 1.1555 + 1.1556 + /** 1.1557 + * Return the secondary grouping size. In some locales one 1.1558 + * grouping interval is used for the least significant integer 1.1559 + * digits (the primary grouping size), and another is used for all 1.1560 + * others (the secondary grouping size). A formatter supporting a 1.1561 + * secondary grouping size will return a positive integer unequal 1.1562 + * to the primary grouping size returned by 1.1563 + * getGroupingSize(). For example, if the primary 1.1564 + * grouping size is 4, and the secondary grouping size is 2, then 1.1565 + * the number 123456789 formats as "1,23,45,6789", and the pattern 1.1566 + * appears as "#,##,###0". 1.1567 + * @return the secondary grouping size, or a value less than 1.1568 + * one if there is none 1.1569 + * @see setSecondaryGroupingSize 1.1570 + * @see NumberFormat::isGroupingUsed 1.1571 + * @see DecimalFormatSymbols::getGroupingSeparator 1.1572 + * @stable ICU 2.4 1.1573 + */ 1.1574 + int32_t getSecondaryGroupingSize(void) const; 1.1575 + 1.1576 + /** 1.1577 + * Set the secondary grouping size. If set to a value less than 1, 1.1578 + * then secondary grouping is turned off, and the primary grouping 1.1579 + * size is used for all intervals, not just the least significant. 1.1580 + * 1.1581 + * @param newValue the new value of the secondary grouping size. 1.1582 + * @see getSecondaryGroupingSize 1.1583 + * @see NumberFormat#setGroupingUsed 1.1584 + * @see DecimalFormatSymbols::setGroupingSeparator 1.1585 + * @stable ICU 2.4 1.1586 + */ 1.1587 + virtual void setSecondaryGroupingSize(int32_t newValue); 1.1588 + 1.1589 + /** 1.1590 + * Allows you to get the behavior of the decimal separator with integers. 1.1591 + * (The decimal separator will always appear with decimals.) 1.1592 + * 1.1593 + * @return TRUE if the decimal separator always appear with decimals. 1.1594 + * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 1.1595 + * @stable ICU 2.0 1.1596 + */ 1.1597 + UBool isDecimalSeparatorAlwaysShown(void) const; 1.1598 + 1.1599 + /** 1.1600 + * Allows you to set the behavior of the decimal separator with integers. 1.1601 + * (The decimal separator will always appear with decimals.) 1.1602 + * 1.1603 + * @param newValue set TRUE if the decimal separator will always appear with decimals. 1.1604 + * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 1.1605 + * @stable ICU 2.0 1.1606 + */ 1.1607 + virtual void setDecimalSeparatorAlwaysShown(UBool newValue); 1.1608 + 1.1609 + /** 1.1610 + * Synthesizes a pattern string that represents the current state 1.1611 + * of this Format object. 1.1612 + * 1.1613 + * @param result Output param which will receive the pattern. 1.1614 + * Previous contents are deleted. 1.1615 + * @return A reference to 'result'. 1.1616 + * @see applyPattern 1.1617 + * @stable ICU 2.0 1.1618 + */ 1.1619 + virtual UnicodeString& toPattern(UnicodeString& result) const; 1.1620 + 1.1621 + /** 1.1622 + * Synthesizes a localized pattern string that represents the current 1.1623 + * state of this Format object. 1.1624 + * 1.1625 + * @param result Output param which will receive the localized pattern. 1.1626 + * Previous contents are deleted. 1.1627 + * @return A reference to 'result'. 1.1628 + * @see applyPattern 1.1629 + * @stable ICU 2.0 1.1630 + */ 1.1631 + virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const; 1.1632 + 1.1633 + /** 1.1634 + * Apply the given pattern to this Format object. A pattern is a 1.1635 + * short-hand specification for the various formatting properties. 1.1636 + * These properties can also be changed individually through the 1.1637 + * various setter methods. 1.1638 + * <P> 1.1639 + * There is no limit to integer digits are set 1.1640 + * by this routine, since that is the typical end-user desire; 1.1641 + * use setMaximumInteger if you want to set a real value. 1.1642 + * For negative numbers, use a second pattern, separated by a semicolon 1.1643 + * <pre> 1.1644 + * . Example "#,#00.0#" -> 1,234.56 1.1645 + * </pre> 1.1646 + * This means a minimum of 2 integer digits, 1 fraction digit, and 1.1647 + * a maximum of 2 fraction digits. 1.1648 + * <pre> 1.1649 + * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses. 1.1650 + * </pre> 1.1651 + * In negative patterns, the minimum and maximum counts are ignored; 1.1652 + * these are presumed to be set in the positive pattern. 1.1653 + * 1.1654 + * @param pattern The pattern to be applied. 1.1655 + * @param parseError Struct to recieve information on position 1.1656 + * of error if an error is encountered 1.1657 + * @param status Output param set to success/failure code on 1.1658 + * exit. If the pattern is invalid, this will be 1.1659 + * set to a failure result. 1.1660 + * @stable ICU 2.0 1.1661 + */ 1.1662 + virtual void applyPattern(const UnicodeString& pattern, 1.1663 + UParseError& parseError, 1.1664 + UErrorCode& status); 1.1665 + /** 1.1666 + * Sets the pattern. 1.1667 + * @param pattern The pattern to be applied. 1.1668 + * @param status Output param set to success/failure code on 1.1669 + * exit. If the pattern is invalid, this will be 1.1670 + * set to a failure result. 1.1671 + * @stable ICU 2.0 1.1672 + */ 1.1673 + virtual void applyPattern(const UnicodeString& pattern, 1.1674 + UErrorCode& status); 1.1675 + 1.1676 + /** 1.1677 + * Apply the given pattern to this Format object. The pattern 1.1678 + * is assumed to be in a localized notation. A pattern is a 1.1679 + * short-hand specification for the various formatting properties. 1.1680 + * These properties can also be changed individually through the 1.1681 + * various setter methods. 1.1682 + * <P> 1.1683 + * There is no limit to integer digits are set 1.1684 + * by this routine, since that is the typical end-user desire; 1.1685 + * use setMaximumInteger if you want to set a real value. 1.1686 + * For negative numbers, use a second pattern, separated by a semicolon 1.1687 + * <pre> 1.1688 + * . Example "#,#00.0#" -> 1,234.56 1.1689 + * </pre> 1.1690 + * This means a minimum of 2 integer digits, 1 fraction digit, and 1.1691 + * a maximum of 2 fraction digits. 1.1692 + * 1.1693 + * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses. 1.1694 + * 1.1695 + * In negative patterns, the minimum and maximum counts are ignored; 1.1696 + * these are presumed to be set in the positive pattern. 1.1697 + * 1.1698 + * @param pattern The localized pattern to be applied. 1.1699 + * @param parseError Struct to recieve information on position 1.1700 + * of error if an error is encountered 1.1701 + * @param status Output param set to success/failure code on 1.1702 + * exit. If the pattern is invalid, this will be 1.1703 + * set to a failure result. 1.1704 + * @stable ICU 2.0 1.1705 + */ 1.1706 + virtual void applyLocalizedPattern(const UnicodeString& pattern, 1.1707 + UParseError& parseError, 1.1708 + UErrorCode& status); 1.1709 + 1.1710 + /** 1.1711 + * Apply the given pattern to this Format object. 1.1712 + * 1.1713 + * @param pattern The localized pattern to be applied. 1.1714 + * @param status Output param set to success/failure code on 1.1715 + * exit. If the pattern is invalid, this will be 1.1716 + * set to a failure result. 1.1717 + * @stable ICU 2.0 1.1718 + */ 1.1719 + virtual void applyLocalizedPattern(const UnicodeString& pattern, 1.1720 + UErrorCode& status); 1.1721 + 1.1722 + 1.1723 + /** 1.1724 + * Sets the maximum number of digits allowed in the integer portion of a 1.1725 + * number. This override limits the integer digit count to 309. 1.1726 + * 1.1727 + * @param newValue the new value of the maximum number of digits 1.1728 + * allowed in the integer portion of a number. 1.1729 + * @see NumberFormat#setMaximumIntegerDigits 1.1730 + * @stable ICU 2.0 1.1731 + */ 1.1732 + virtual void setMaximumIntegerDigits(int32_t newValue); 1.1733 + 1.1734 + /** 1.1735 + * Sets the minimum number of digits allowed in the integer portion of a 1.1736 + * number. This override limits the integer digit count to 309. 1.1737 + * 1.1738 + * @param newValue the new value of the minimum number of digits 1.1739 + * allowed in the integer portion of a number. 1.1740 + * @see NumberFormat#setMinimumIntegerDigits 1.1741 + * @stable ICU 2.0 1.1742 + */ 1.1743 + virtual void setMinimumIntegerDigits(int32_t newValue); 1.1744 + 1.1745 + /** 1.1746 + * Sets the maximum number of digits allowed in the fraction portion of a 1.1747 + * number. This override limits the fraction digit count to 340. 1.1748 + * 1.1749 + * @param newValue the new value of the maximum number of digits 1.1750 + * allowed in the fraction portion of a number. 1.1751 + * @see NumberFormat#setMaximumFractionDigits 1.1752 + * @stable ICU 2.0 1.1753 + */ 1.1754 + virtual void setMaximumFractionDigits(int32_t newValue); 1.1755 + 1.1756 + /** 1.1757 + * Sets the minimum number of digits allowed in the fraction portion of a 1.1758 + * number. This override limits the fraction digit count to 340. 1.1759 + * 1.1760 + * @param newValue the new value of the minimum number of digits 1.1761 + * allowed in the fraction portion of a number. 1.1762 + * @see NumberFormat#setMinimumFractionDigits 1.1763 + * @stable ICU 2.0 1.1764 + */ 1.1765 + virtual void setMinimumFractionDigits(int32_t newValue); 1.1766 + 1.1767 + /** 1.1768 + * Returns the minimum number of significant digits that will be 1.1769 + * displayed. This value has no effect unless areSignificantDigitsUsed() 1.1770 + * returns true. 1.1771 + * @return the fewest significant digits that will be shown 1.1772 + * @stable ICU 3.0 1.1773 + */ 1.1774 + int32_t getMinimumSignificantDigits() const; 1.1775 + 1.1776 + /** 1.1777 + * Returns the maximum number of significant digits that will be 1.1778 + * displayed. This value has no effect unless areSignificantDigitsUsed() 1.1779 + * returns true. 1.1780 + * @return the most significant digits that will be shown 1.1781 + * @stable ICU 3.0 1.1782 + */ 1.1783 + int32_t getMaximumSignificantDigits() const; 1.1784 + 1.1785 + /** 1.1786 + * Sets the minimum number of significant digits that will be 1.1787 + * displayed. If <code>min</code> is less than one then it is set 1.1788 + * to one. If the maximum significant digits count is less than 1.1789 + * <code>min</code>, then it is set to <code>min</code>. 1.1790 + * This function also enables the use of significant digits 1.1791 + * by this formatter - areSignificantDigitsUsed() will return TRUE. 1.1792 + * @see #areSignificantDigitsUsed 1.1793 + * @param min the fewest significant digits to be shown 1.1794 + * @stable ICU 3.0 1.1795 + */ 1.1796 + void setMinimumSignificantDigits(int32_t min); 1.1797 + 1.1798 + /** 1.1799 + * Sets the maximum number of significant digits that will be 1.1800 + * displayed. If <code>max</code> is less than one then it is set 1.1801 + * to one. If the minimum significant digits count is greater 1.1802 + * than <code>max</code>, then it is set to <code>max</code>. 1.1803 + * This function also enables the use of significant digits 1.1804 + * by this formatter - areSignificantDigitsUsed() will return TRUE. 1.1805 + * @see #areSignificantDigitsUsed 1.1806 + * @param max the most significant digits to be shown 1.1807 + * @stable ICU 3.0 1.1808 + */ 1.1809 + void setMaximumSignificantDigits(int32_t max); 1.1810 + 1.1811 + /** 1.1812 + * Returns true if significant digits are in use, or false if 1.1813 + * integer and fraction digit counts are in use. 1.1814 + * @return true if significant digits are in use 1.1815 + * @stable ICU 3.0 1.1816 + */ 1.1817 + UBool areSignificantDigitsUsed() const; 1.1818 + 1.1819 + /** 1.1820 + * Sets whether significant digits are in use, or integer and 1.1821 + * fraction digit counts are in use. 1.1822 + * @param useSignificantDigits true to use significant digits, or 1.1823 + * false to use integer and fraction digit counts 1.1824 + * @stable ICU 3.0 1.1825 + */ 1.1826 + void setSignificantDigitsUsed(UBool useSignificantDigits); 1.1827 + 1.1828 + public: 1.1829 + /** 1.1830 + * Sets the currency used to display currency 1.1831 + * amounts. This takes effect immediately, if this format is a 1.1832 + * currency format. If this format is not a currency format, then 1.1833 + * the currency is used if and when this object becomes a 1.1834 + * currency format through the application of a new pattern. 1.1835 + * @param theCurrency a 3-letter ISO code indicating new currency 1.1836 + * to use. It need not be null-terminated. May be the empty 1.1837 + * string or NULL to indicate no currency. 1.1838 + * @param ec input-output error code 1.1839 + * @stable ICU 3.0 1.1840 + */ 1.1841 + virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec); 1.1842 + 1.1843 + /** 1.1844 + * Sets the currency used to display currency amounts. See 1.1845 + * setCurrency(const UChar*, UErrorCode&). 1.1846 + * @deprecated ICU 3.0. Use setCurrency(const UChar*, UErrorCode&). 1.1847 + */ 1.1848 + virtual void setCurrency(const UChar* theCurrency); 1.1849 + 1.1850 + /** 1.1851 + * The resource tags we use to retrieve decimal format data from 1.1852 + * locale resource bundles. 1.1853 + * @deprecated ICU 3.4. This string has no public purpose. Please don't use it. 1.1854 + */ 1.1855 + static const char fgNumberPatterns[]; 1.1856 + 1.1857 +#ifndef U_HIDE_INTERNAL_API 1.1858 + /** 1.1859 + * Get a FixedDecimal corresponding to a double as it would be 1.1860 + * formatted by this DecimalFormat. 1.1861 + * Internal, not intended for public use. 1.1862 + * @internal 1.1863 + */ 1.1864 + FixedDecimal getFixedDecimal(double number, UErrorCode &status) const; 1.1865 + 1.1866 + /** 1.1867 + * Get a FixedDecimal corresponding to a formattable as it would be 1.1868 + * formatted by this DecimalFormat. 1.1869 + * Internal, not intended for public use. 1.1870 + * @internal 1.1871 + */ 1.1872 + FixedDecimal getFixedDecimal(const Formattable &number, UErrorCode &status) const; 1.1873 + 1.1874 + /** 1.1875 + * Get a FixedDecimal corresponding to a DigitList as it would be 1.1876 + * formatted by this DecimalFormat. Note: the DigitList may be modified. 1.1877 + * Internal, not intended for public use. 1.1878 + * @internal 1.1879 + */ 1.1880 + FixedDecimal getFixedDecimal(DigitList &number, UErrorCode &status) const; 1.1881 +#endif /* U_HIDE_INTERNAL_API */ 1.1882 + 1.1883 +public: 1.1884 + 1.1885 + /** 1.1886 + * Return the class ID for this class. This is useful only for 1.1887 + * comparing to a return value from getDynamicClassID(). For example: 1.1888 + * <pre> 1.1889 + * . Base* polymorphic_pointer = createPolymorphicObject(); 1.1890 + * . if (polymorphic_pointer->getDynamicClassID() == 1.1891 + * . Derived::getStaticClassID()) ... 1.1892 + * </pre> 1.1893 + * @return The class ID for all objects of this class. 1.1894 + * @stable ICU 2.0 1.1895 + */ 1.1896 + static UClassID U_EXPORT2 getStaticClassID(void); 1.1897 + 1.1898 + /** 1.1899 + * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. 1.1900 + * This method is to implement a simple version of RTTI, since not all 1.1901 + * C++ compilers support genuine RTTI. Polymorphic operator==() and 1.1902 + * clone() methods call this method. 1.1903 + * 1.1904 + * @return The class ID for this object. All objects of a 1.1905 + * given class have the same class ID. Objects of 1.1906 + * other classes have different class IDs. 1.1907 + * @stable ICU 2.0 1.1908 + */ 1.1909 + virtual UClassID getDynamicClassID(void) const; 1.1910 + 1.1911 +private: 1.1912 + 1.1913 + DecimalFormat(); // default constructor not implemented 1.1914 + 1.1915 + int32_t precision() const; 1.1916 + 1.1917 + /** 1.1918 + * Initialize all fields of a new DecimalFormatter to a safe default value. 1.1919 + * Common code for use by constructors. 1.1920 + */ 1.1921 + void init(); 1.1922 + 1.1923 + /** 1.1924 + * Do real work of constructing a new DecimalFormat. 1.1925 + */ 1.1926 + void construct(UErrorCode& status, 1.1927 + UParseError& parseErr, 1.1928 + const UnicodeString* pattern = 0, 1.1929 + DecimalFormatSymbols* symbolsToAdopt = 0 1.1930 + ); 1.1931 + 1.1932 + /** 1.1933 + * Does the real work of generating a pattern. 1.1934 + * 1.1935 + * @param result Output param which will receive the pattern. 1.1936 + * Previous contents are deleted. 1.1937 + * @param localized TRUE return localized pattern. 1.1938 + * @return A reference to 'result'. 1.1939 + */ 1.1940 + UnicodeString& toPattern(UnicodeString& result, UBool localized) const; 1.1941 + 1.1942 + /** 1.1943 + * Does the real work of applying a pattern. 1.1944 + * @param pattern The pattern to be applied. 1.1945 + * @param localized If true, the pattern is localized; else false. 1.1946 + * @param parseError Struct to recieve information on position 1.1947 + * of error if an error is encountered 1.1948 + * @param status Output param set to success/failure code on 1.1949 + * exit. If the pattern is invalid, this will be 1.1950 + * set to a failure result. 1.1951 + */ 1.1952 + void applyPattern(const UnicodeString& pattern, 1.1953 + UBool localized, 1.1954 + UParseError& parseError, 1.1955 + UErrorCode& status); 1.1956 + 1.1957 + /* 1.1958 + * similar to applyPattern, but without re-gen affix for currency 1.1959 + */ 1.1960 + void applyPatternInternally(const UnicodeString& pluralCount, 1.1961 + const UnicodeString& pattern, 1.1962 + UBool localized, 1.1963 + UParseError& parseError, 1.1964 + UErrorCode& status); 1.1965 + 1.1966 + /* 1.1967 + * only apply pattern without expand affixes 1.1968 + */ 1.1969 + void applyPatternWithoutExpandAffix(const UnicodeString& pattern, 1.1970 + UBool localized, 1.1971 + UParseError& parseError, 1.1972 + UErrorCode& status); 1.1973 + 1.1974 + 1.1975 + /* 1.1976 + * expand affixes (after apply patter) and re-compute fFormatWidth 1.1977 + */ 1.1978 + void expandAffixAdjustWidth(const UnicodeString* pluralCount); 1.1979 + 1.1980 + 1.1981 + /** 1.1982 + * Do the work of formatting a number, either a double or a long. 1.1983 + * 1.1984 + * @param appendTo Output parameter to receive result. 1.1985 + * Result is appended to existing contents. 1.1986 + * @param handler Records information about field positions. 1.1987 + * @param digits the digits to be formatted. 1.1988 + * @param isInteger if TRUE format the digits as Integer. 1.1989 + * @return Reference to 'appendTo' parameter. 1.1990 + */ 1.1991 + UnicodeString& subformat(UnicodeString& appendTo, 1.1992 + FieldPositionHandler& handler, 1.1993 + DigitList& digits, 1.1994 + UBool isInteger, 1.1995 + UErrorCode &status) const; 1.1996 + 1.1997 + 1.1998 + void parse(const UnicodeString& text, 1.1999 + Formattable& result, 1.2000 + ParsePosition& pos, 1.2001 + UChar* currency) const; 1.2002 + 1.2003 + enum { 1.2004 + fgStatusInfinite, 1.2005 + fgStatusLength // Leave last in list. 1.2006 + } StatusFlags; 1.2007 + 1.2008 + UBool subparse(const UnicodeString& text, 1.2009 + const UnicodeString* negPrefix, 1.2010 + const UnicodeString* negSuffix, 1.2011 + const UnicodeString* posPrefix, 1.2012 + const UnicodeString* posSuffix, 1.2013 + UBool complexCurrencyParsing, 1.2014 + int8_t type, 1.2015 + ParsePosition& parsePosition, 1.2016 + DigitList& digits, UBool* status, 1.2017 + UChar* currency) const; 1.2018 + 1.2019 + // Mixed style parsing for currency. 1.2020 + // It parses against the current currency pattern 1.2021 + // using complex affix comparison 1.2022 + // parses against the currency plural patterns using complex affix comparison, 1.2023 + // and parses against the current pattern using simple affix comparison. 1.2024 + UBool parseForCurrency(const UnicodeString& text, 1.2025 + ParsePosition& parsePosition, 1.2026 + DigitList& digits, 1.2027 + UBool* status, 1.2028 + UChar* currency) const; 1.2029 + 1.2030 + int32_t skipPadding(const UnicodeString& text, int32_t position) const; 1.2031 + 1.2032 + int32_t compareAffix(const UnicodeString& input, 1.2033 + int32_t pos, 1.2034 + UBool isNegative, 1.2035 + UBool isPrefix, 1.2036 + const UnicodeString* affixPat, 1.2037 + UBool complexCurrencyParsing, 1.2038 + int8_t type, 1.2039 + UChar* currency) const; 1.2040 + 1.2041 + static UnicodeString& trimMarksFromAffix(const UnicodeString& affix, UnicodeString& trimmedAffix); 1.2042 + 1.2043 + UBool equalWithSignCompatibility(UChar32 lhs, UChar32 rhs) const; 1.2044 + 1.2045 + int32_t compareSimpleAffix(const UnicodeString& affix, 1.2046 + const UnicodeString& input, 1.2047 + int32_t pos, 1.2048 + UBool lenient) const; 1.2049 + 1.2050 + static int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos); 1.2051 + 1.2052 + static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos); 1.2053 + 1.2054 + static int32_t skipUWhiteSpaceAndMarks(const UnicodeString& text, int32_t pos); 1.2055 + 1.2056 + static int32_t skipBidiMarks(const UnicodeString& text, int32_t pos); 1.2057 + 1.2058 + int32_t compareComplexAffix(const UnicodeString& affixPat, 1.2059 + const UnicodeString& input, 1.2060 + int32_t pos, 1.2061 + int8_t type, 1.2062 + UChar* currency) const; 1.2063 + 1.2064 + static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch); 1.2065 + 1.2066 + static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str); 1.2067 + 1.2068 + static UBool matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol, 1.2069 + UnicodeSet *sset, UChar32 schar); 1.2070 + 1.2071 + static UBool matchDecimal(UChar32 symbolChar, 1.2072 + UBool sawDecimal, UChar32 sawDecimalChar, 1.2073 + const UnicodeSet *sset, UChar32 schar); 1.2074 + 1.2075 + static UBool matchGrouping(UChar32 groupingChar, 1.2076 + UBool sawGrouping, UChar32 sawGroupingChar, 1.2077 + const UnicodeSet *sset, 1.2078 + UChar32 decimalChar, const UnicodeSet *decimalSet, 1.2079 + UChar32 schar); 1.2080 + 1.2081 + /** 1.2082 + * Get a decimal format symbol. 1.2083 + * Returns a const reference to the symbol string. 1.2084 + * @internal 1.2085 + */ 1.2086 + inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const; 1.2087 + 1.2088 + int32_t appendAffix(UnicodeString& buf, 1.2089 + double number, 1.2090 + FieldPositionHandler& handler, 1.2091 + UBool isNegative, 1.2092 + UBool isPrefix) const; 1.2093 + 1.2094 + /** 1.2095 + * Append an affix to the given UnicodeString, using quotes if 1.2096 + * there are special characters. Single quotes themselves must be 1.2097 + * escaped in either case. 1.2098 + */ 1.2099 + void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix, 1.2100 + UBool localized) const; 1.2101 + 1.2102 + void appendAffixPattern(UnicodeString& appendTo, 1.2103 + const UnicodeString* affixPattern, 1.2104 + const UnicodeString& expAffix, UBool localized) const; 1.2105 + 1.2106 + void expandAffix(const UnicodeString& pattern, 1.2107 + UnicodeString& affix, 1.2108 + double number, 1.2109 + FieldPositionHandler& handler, 1.2110 + UBool doFormat, 1.2111 + const UnicodeString* pluralCount) const; 1.2112 + 1.2113 + void expandAffixes(const UnicodeString* pluralCount); 1.2114 + 1.2115 + void addPadding(UnicodeString& appendTo, 1.2116 + FieldPositionHandler& handler, 1.2117 + int32_t prefixLen, int32_t suffixLen) const; 1.2118 + 1.2119 + UBool isGroupingPosition(int32_t pos) const; 1.2120 + 1.2121 + void setCurrencyForSymbols(); 1.2122 + 1.2123 + // similar to setCurrency without re-compute the affixes for currency. 1.2124 + // If currency changes, the affix pattern for currency is not changed, 1.2125 + // but the affix will be changed. So, affixes need to be 1.2126 + // re-computed in setCurrency(), but not in setCurrencyInternally(). 1.2127 + virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec); 1.2128 + 1.2129 + // set up currency affix patterns for mix parsing. 1.2130 + // The patterns saved here are the affix patterns of default currency 1.2131 + // pattern and the unique affix patterns of the plural currency patterns. 1.2132 + // Those patterns are used by parseForCurrency(). 1.2133 + void setupCurrencyAffixPatterns(UErrorCode& status); 1.2134 + 1.2135 + // set up the currency affixes used in currency plural formatting. 1.2136 + // It sets up both fAffixesForCurrency for currency pattern if the current 1.2137 + // pattern contains 3 currency signs, 1.2138 + // and it sets up fPluralAffixesForCurrency for currency plural patterns. 1.2139 + void setupCurrencyAffixes(const UnicodeString& pattern, 1.2140 + UBool setupForCurrentPattern, 1.2141 + UBool setupForPluralPattern, 1.2142 + UErrorCode& status); 1.2143 + 1.2144 + // hashtable operations 1.2145 + Hashtable* initHashForAffixPattern(UErrorCode& status); 1.2146 + Hashtable* initHashForAffix(UErrorCode& status); 1.2147 + 1.2148 + void deleteHashForAffixPattern(); 1.2149 + void deleteHashForAffix(Hashtable*& table); 1.2150 + 1.2151 + void copyHashForAffixPattern(const Hashtable* source, 1.2152 + Hashtable* target, UErrorCode& status); 1.2153 + void copyHashForAffix(const Hashtable* source, 1.2154 + Hashtable* target, UErrorCode& status); 1.2155 + 1.2156 + UnicodeString& _format(int64_t number, 1.2157 + UnicodeString& appendTo, 1.2158 + FieldPositionHandler& handler, 1.2159 + UErrorCode &status) const; 1.2160 + UnicodeString& _format(double number, 1.2161 + UnicodeString& appendTo, 1.2162 + FieldPositionHandler& handler, 1.2163 + UErrorCode &status) const; 1.2164 + UnicodeString& _format(const DigitList &number, 1.2165 + UnicodeString& appendTo, 1.2166 + FieldPositionHandler& handler, 1.2167 + UErrorCode &status) const; 1.2168 + 1.2169 + // currency sign count 1.2170 + enum { 1.2171 + fgCurrencySignCountZero, 1.2172 + fgCurrencySignCountInSymbolFormat, 1.2173 + fgCurrencySignCountInISOFormat, 1.2174 + fgCurrencySignCountInPluralFormat 1.2175 + } CurrencySignCount; 1.2176 + 1.2177 + /** 1.2178 + * Constants. 1.2179 + */ 1.2180 + 1.2181 + UnicodeString fPositivePrefix; 1.2182 + UnicodeString fPositiveSuffix; 1.2183 + UnicodeString fNegativePrefix; 1.2184 + UnicodeString fNegativeSuffix; 1.2185 + UnicodeString* fPosPrefixPattern; 1.2186 + UnicodeString* fPosSuffixPattern; 1.2187 + UnicodeString* fNegPrefixPattern; 1.2188 + UnicodeString* fNegSuffixPattern; 1.2189 + 1.2190 + /** 1.2191 + * Formatter for ChoiceFormat-based currency names. If this field 1.2192 + * is not null, then delegate to it to format currency symbols. 1.2193 + * @since ICU 2.6 1.2194 + */ 1.2195 + ChoiceFormat* fCurrencyChoice; 1.2196 + 1.2197 + DigitList * fMultiplier; // NULL for multiplier of one 1.2198 + int32_t fScale; 1.2199 + int32_t fGroupingSize; 1.2200 + int32_t fGroupingSize2; 1.2201 + UBool fDecimalSeparatorAlwaysShown; 1.2202 + DecimalFormatSymbols* fSymbols; 1.2203 + 1.2204 + UBool fUseSignificantDigits; 1.2205 + int32_t fMinSignificantDigits; 1.2206 + int32_t fMaxSignificantDigits; 1.2207 + 1.2208 + UBool fUseExponentialNotation; 1.2209 + int8_t fMinExponentDigits; 1.2210 + UBool fExponentSignAlwaysShown; 1.2211 + 1.2212 + EnumSet<UNumberFormatAttribute, 1.2213 + UNUM_MAX_NONBOOLEAN_ATTRIBUTE+1, 1.2214 + UNUM_LIMIT_BOOLEAN_ATTRIBUTE> 1.2215 + fBoolFlags; 1.2216 + 1.2217 + DigitList* fRoundingIncrement; // NULL if no rounding increment specified. 1.2218 + ERoundingMode fRoundingMode; 1.2219 + 1.2220 + UChar32 fPad; 1.2221 + int32_t fFormatWidth; 1.2222 + EPadPosition fPadPosition; 1.2223 + 1.2224 + /* 1.2225 + * Following are used for currency format 1.2226 + */ 1.2227 + // pattern used in this formatter 1.2228 + UnicodeString fFormatPattern; 1.2229 + // style is only valid when decimal formatter is constructed by 1.2230 + // DecimalFormat(pattern, decimalFormatSymbol, style) 1.2231 + int fStyle; 1.2232 + /* 1.2233 + * Represents whether this is a currency format, and which 1.2234 + * currency format style. 1.2235 + * 0: not currency format type; 1.2236 + * 1: currency style -- symbol name, such as "$" for US dollar. 1.2237 + * 2: currency style -- ISO name, such as USD for US dollar. 1.2238 + * 3: currency style -- plural long name, such as "US Dollar" for 1.2239 + * "1.00 US Dollar", or "US Dollars" for 1.2240 + * "3.00 US Dollars". 1.2241 + */ 1.2242 + int fCurrencySignCount; 1.2243 + 1.2244 + 1.2245 + /* For currency parsing purose, 1.2246 + * Need to remember all prefix patterns and suffix patterns of 1.2247 + * every currency format pattern, 1.2248 + * including the pattern of default currecny style 1.2249 + * and plural currency style. And the patterns are set through applyPattern. 1.2250 + */ 1.2251 + // TODO: innerclass? 1.2252 + /* This is not needed in the class declaration, so it is moved into decimfmp.cpp 1.2253 + struct AffixPatternsForCurrency : public UMemory { 1.2254 + // negative prefix pattern 1.2255 + UnicodeString negPrefixPatternForCurrency; 1.2256 + // negative suffix pattern 1.2257 + UnicodeString negSuffixPatternForCurrency; 1.2258 + // positive prefix pattern 1.2259 + UnicodeString posPrefixPatternForCurrency; 1.2260 + // positive suffix pattern 1.2261 + UnicodeString posSuffixPatternForCurrency; 1.2262 + int8_t patternType; 1.2263 + 1.2264 + AffixPatternsForCurrency(const UnicodeString& negPrefix, 1.2265 + const UnicodeString& negSuffix, 1.2266 + const UnicodeString& posPrefix, 1.2267 + const UnicodeString& posSuffix, 1.2268 + int8_t type) { 1.2269 + negPrefixPatternForCurrency = negPrefix; 1.2270 + negSuffixPatternForCurrency = negSuffix; 1.2271 + posPrefixPatternForCurrency = posPrefix; 1.2272 + posSuffixPatternForCurrency = posSuffix; 1.2273 + patternType = type; 1.2274 + } 1.2275 + }; 1.2276 + */ 1.2277 + 1.2278 + /* affix for currency formatting when the currency sign in the pattern 1.2279 + * equals to 3, such as the pattern contains 3 currency sign or 1.2280 + * the formatter style is currency plural format style. 1.2281 + */ 1.2282 + /* This is not needed in the class declaration, so it is moved into decimfmp.cpp 1.2283 + struct AffixesForCurrency : public UMemory { 1.2284 + // negative prefix 1.2285 + UnicodeString negPrefixForCurrency; 1.2286 + // negative suffix 1.2287 + UnicodeString negSuffixForCurrency; 1.2288 + // positive prefix 1.2289 + UnicodeString posPrefixForCurrency; 1.2290 + // positive suffix 1.2291 + UnicodeString posSuffixForCurrency; 1.2292 + 1.2293 + int32_t formatWidth; 1.2294 + 1.2295 + AffixesForCurrency(const UnicodeString& negPrefix, 1.2296 + const UnicodeString& negSuffix, 1.2297 + const UnicodeString& posPrefix, 1.2298 + const UnicodeString& posSuffix) { 1.2299 + negPrefixForCurrency = negPrefix; 1.2300 + negSuffixForCurrency = negSuffix; 1.2301 + posPrefixForCurrency = posPrefix; 1.2302 + posSuffixForCurrency = posSuffix; 1.2303 + } 1.2304 + }; 1.2305 + */ 1.2306 + 1.2307 + // Affix pattern set for currency. 1.2308 + // It is a set of AffixPatternsForCurrency, 1.2309 + // each element of the set saves the negative prefix pattern, 1.2310 + // negative suffix pattern, positive prefix pattern, 1.2311 + // and positive suffix pattern of a pattern. 1.2312 + // It is used for currency mixed style parsing. 1.2313 + // It is actually is a set. 1.2314 + // The set contains the default currency pattern from the locale, 1.2315 + // and the currency plural patterns. 1.2316 + // Since it is a set, it does not contain duplicated items. 1.2317 + // For example, if 2 currency plural patterns are the same, only one pattern 1.2318 + // is included in the set. When parsing, we do not check whether the plural 1.2319 + // count match or not. 1.2320 + Hashtable* fAffixPatternsForCurrency; 1.2321 + 1.2322 + // Following 2 are affixes for currency. 1.2323 + // It is a hash map from plural count to AffixesForCurrency. 1.2324 + // AffixesForCurrency saves the negative prefix, 1.2325 + // negative suffix, positive prefix, and positive suffix of a pattern. 1.2326 + // It is used during currency formatting only when the currency sign count 1.2327 + // is 3. In which case, the affixes are getting from here, not 1.2328 + // from the fNegativePrefix etc. 1.2329 + Hashtable* fAffixesForCurrency; // for current pattern 1.2330 + Hashtable* fPluralAffixesForCurrency; // for plural pattern 1.2331 + 1.2332 + // Information needed for DecimalFormat to format/parse currency plural. 1.2333 + CurrencyPluralInfo* fCurrencyPluralInfo; 1.2334 + 1.2335 +#if UCONFIG_HAVE_PARSEALLINPUT 1.2336 + UNumberFormatAttributeValue fParseAllInput; 1.2337 +#endif 1.2338 + 1.2339 + // Decimal Format Static Sets singleton. 1.2340 + const DecimalFormatStaticSets *fStaticSets; 1.2341 + 1.2342 + 1.2343 +protected: 1.2344 + 1.2345 +#ifndef U_HIDE_INTERNAL_API 1.2346 + /** 1.2347 + * Rounds a value according to the rules of this object. 1.2348 + * @internal 1.2349 + */ 1.2350 + DigitList& _round(const DigitList& number, DigitList& adjustedNum, UBool& isNegative, UErrorCode& status) const; 1.2351 +#endif /* U_HIDE_INTERNAL_API */ 1.2352 + 1.2353 + /** 1.2354 + * Returns the currency in effect for this formatter. Subclasses 1.2355 + * should override this method as needed. Unlike getCurrency(), 1.2356 + * this method should never return "". 1.2357 + * @result output parameter for null-terminated result, which must 1.2358 + * have a capacity of at least 4 1.2359 + * @internal 1.2360 + */ 1.2361 + virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const; 1.2362 + 1.2363 + /** number of integer digits 1.2364 + * @stable ICU 2.4 1.2365 + */ 1.2366 + static const int32_t kDoubleIntegerDigits; 1.2367 + /** number of fraction digits 1.2368 + * @stable ICU 2.4 1.2369 + */ 1.2370 + static const int32_t kDoubleFractionDigits; 1.2371 + 1.2372 + /** 1.2373 + * When someone turns on scientific mode, we assume that more than this 1.2374 + * number of digits is due to flipping from some other mode that didn't 1.2375 + * restrict the maximum, and so we force 1 integer digit. We don't bother 1.2376 + * to track and see if someone is using exponential notation with more than 1.2377 + * this number, it wouldn't make sense anyway, and this is just to make sure 1.2378 + * that someone turning on scientific mode with default settings doesn't 1.2379 + * end up with lots of zeroes. 1.2380 + * @stable ICU 2.8 1.2381 + */ 1.2382 + static const int32_t kMaxScientificIntegerDigits; 1.2383 + 1.2384 +#if UCONFIG_FORMAT_FASTPATHS_49 1.2385 + private: 1.2386 + /** 1.2387 + * Internal state. 1.2388 + * @internal 1.2389 + */ 1.2390 + uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE]; 1.2391 + 1.2392 + 1.2393 + /** 1.2394 + * Called whenever any state changes. Recomputes whether fastpath is OK to use. 1.2395 + */ 1.2396 + void handleChanged(); 1.2397 +#endif 1.2398 +}; 1.2399 + 1.2400 +inline const UnicodeString & 1.2401 +DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const { 1.2402 + return fSymbols->getConstSymbol(symbol); 1.2403 +} 1.2404 + 1.2405 +U_NAMESPACE_END 1.2406 + 1.2407 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.2408 + 1.2409 +#endif // _DECIMFMT 1.2410 +//eof