annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/decimfmt.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 // © 2016 and later: Unicode, Inc. and others.
jpayne@69 2 // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69 3 /*
jpayne@69 4 ********************************************************************************
jpayne@69 5 * Copyright (C) 1997-2016, International Business Machines
jpayne@69 6 * Corporation and others. All Rights Reserved.
jpayne@69 7 ********************************************************************************
jpayne@69 8 *
jpayne@69 9 * File DECIMFMT.H
jpayne@69 10 *
jpayne@69 11 * Modification History:
jpayne@69 12 *
jpayne@69 13 * Date Name Description
jpayne@69 14 * 02/19/97 aliu Converted from java.
jpayne@69 15 * 03/20/97 clhuang Updated per C++ implementation.
jpayne@69 16 * 04/03/97 aliu Rewrote parsing and formatting completely, and
jpayne@69 17 * cleaned up and debugged. Actually works now.
jpayne@69 18 * 04/17/97 aliu Changed DigitCount to int per code review.
jpayne@69 19 * 07/10/97 helena Made ParsePosition a class and get rid of the function
jpayne@69 20 * hiding problems.
jpayne@69 21 * 09/09/97 aliu Ported over support for exponential formats.
jpayne@69 22 * 07/20/98 stephen Changed documentation
jpayne@69 23 * 01/30/13 emmons Added Scaling methods
jpayne@69 24 ********************************************************************************
jpayne@69 25 */
jpayne@69 26
jpayne@69 27 #ifndef DECIMFMT_H
jpayne@69 28 #define DECIMFMT_H
jpayne@69 29
jpayne@69 30 #include "unicode/utypes.h"
jpayne@69 31
jpayne@69 32 #if U_SHOW_CPLUSPLUS_API
jpayne@69 33
jpayne@69 34 /**
jpayne@69 35 * \file
jpayne@69 36 * \brief C++ API: Compatibility APIs for decimal formatting.
jpayne@69 37 */
jpayne@69 38
jpayne@69 39 #if !UCONFIG_NO_FORMATTING
jpayne@69 40
jpayne@69 41 #include "unicode/dcfmtsym.h"
jpayne@69 42 #include "unicode/numfmt.h"
jpayne@69 43 #include "unicode/locid.h"
jpayne@69 44 #include "unicode/fpositer.h"
jpayne@69 45 #include "unicode/stringpiece.h"
jpayne@69 46 #include "unicode/curramt.h"
jpayne@69 47 #include "unicode/enumset.h"
jpayne@69 48
jpayne@69 49 U_NAMESPACE_BEGIN
jpayne@69 50
jpayne@69 51 class CurrencyPluralInfo;
jpayne@69 52 class CompactDecimalFormat;
jpayne@69 53
jpayne@69 54 namespace number {
jpayne@69 55 class LocalizedNumberFormatter;
jpayne@69 56 namespace impl {
jpayne@69 57 class DecimalQuantity;
jpayne@69 58 struct DecimalFormatFields;
jpayne@69 59 class UFormattedNumberData;
jpayne@69 60 }
jpayne@69 61 }
jpayne@69 62
jpayne@69 63 namespace numparse {
jpayne@69 64 namespace impl {
jpayne@69 65 class NumberParserImpl;
jpayne@69 66 }
jpayne@69 67 }
jpayne@69 68
jpayne@69 69 /**
jpayne@69 70 * **IMPORTANT:** New users are strongly encouraged to see if
jpayne@69 71 * numberformatter.h fits their use case. Although not deprecated, this header
jpayne@69 72 * is provided for backwards compatibility only.
jpayne@69 73 *
jpayne@69 74 * DecimalFormat is a concrete subclass of NumberFormat that formats decimal
jpayne@69 75 * numbers. It has a variety of features designed to make it possible to parse
jpayne@69 76 * and format numbers in any locale, including support for Western, Arabic, or
jpayne@69 77 * Indic digits. It also supports different flavors of numbers, including
jpayne@69 78 * integers ("123"), fixed-point numbers ("123.4"), scientific notation
jpayne@69 79 * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123",
jpayne@69 80 * "123 US dollars"). All of these flavors can be easily localized.
jpayne@69 81 *
jpayne@69 82 * To obtain a NumberFormat for a specific locale (including the default
jpayne@69 83 * locale) call one of NumberFormat's factory methods such as
jpayne@69 84 * createInstance(). Do not call the DecimalFormat constructors directly, unless
jpayne@69 85 * you know what you are doing, since the NumberFormat factory methods may
jpayne@69 86 * return subclasses other than DecimalFormat.
jpayne@69 87 *
jpayne@69 88 * **Example Usage**
jpayne@69 89 *
jpayne@69 90 * \code
jpayne@69 91 * // Normally we would have a GUI with a menu for this
jpayne@69 92 * int32_t locCount;
jpayne@69 93 * const Locale* locales = NumberFormat::getAvailableLocales(locCount);
jpayne@69 94 *
jpayne@69 95 * double myNumber = -1234.56;
jpayne@69 96 * UErrorCode success = U_ZERO_ERROR;
jpayne@69 97 * NumberFormat* form;
jpayne@69 98 *
jpayne@69 99 * // Print out a number with the localized number, currency and percent
jpayne@69 100 * // format for each locale.
jpayne@69 101 * UnicodeString countryName;
jpayne@69 102 * UnicodeString displayName;
jpayne@69 103 * UnicodeString str;
jpayne@69 104 * UnicodeString pattern;
jpayne@69 105 * Formattable fmtable;
jpayne@69 106 * for (int32_t j = 0; j < 3; ++j) {
jpayne@69 107 * cout << endl << "FORMAT " << j << endl;
jpayne@69 108 * for (int32_t i = 0; i < locCount; ++i) {
jpayne@69 109 * if (locales[i].getCountry(countryName).size() == 0) {
jpayne@69 110 * // skip language-only
jpayne@69 111 * continue;
jpayne@69 112 * }
jpayne@69 113 * switch (j) {
jpayne@69 114 * case 0:
jpayne@69 115 * form = NumberFormat::createInstance(locales[i], success ); break;
jpayne@69 116 * case 1:
jpayne@69 117 * form = NumberFormat::createCurrencyInstance(locales[i], success ); break;
jpayne@69 118 * default:
jpayne@69 119 * form = NumberFormat::createPercentInstance(locales[i], success ); break;
jpayne@69 120 * }
jpayne@69 121 * if (form) {
jpayne@69 122 * str.remove();
jpayne@69 123 * pattern = ((DecimalFormat*)form)->toPattern(pattern);
jpayne@69 124 * cout << locales[i].getDisplayName(displayName) << ": " << pattern;
jpayne@69 125 * cout << " -> " << form->format(myNumber,str) << endl;
jpayne@69 126 * form->parse(form->format(myNumber,str), fmtable, success);
jpayne@69 127 * delete form;
jpayne@69 128 * }
jpayne@69 129 * }
jpayne@69 130 * }
jpayne@69 131 * \endcode
jpayne@69 132 *
jpayne@69 133 * **Another example use createInstance(style)**
jpayne@69 134 *
jpayne@69 135 * \code
jpayne@69 136 * // Print out a number using the localized number, currency,
jpayne@69 137 * // percent, scientific, integer, iso currency, and plural currency
jpayne@69 138 * // format for each locale</strong>
jpayne@69 139 * Locale* locale = new Locale("en", "US");
jpayne@69 140 * double myNumber = 1234.56;
jpayne@69 141 * UErrorCode success = U_ZERO_ERROR;
jpayne@69 142 * UnicodeString str;
jpayne@69 143 * Formattable fmtable;
jpayne@69 144 * for (int j=NumberFormat::kNumberStyle;
jpayne@69 145 * j<=NumberFormat::kPluralCurrencyStyle;
jpayne@69 146 * ++j) {
jpayne@69 147 * NumberFormat* form = NumberFormat::createInstance(locale, j, success);
jpayne@69 148 * str.remove();
jpayne@69 149 * cout << "format result " << form->format(myNumber, str) << endl;
jpayne@69 150 * format->parse(form->format(myNumber, str), fmtable, success);
jpayne@69 151 * delete form;
jpayne@69 152 * }
jpayne@69 153 * \endcode
jpayne@69 154 *
jpayne@69 155 *
jpayne@69 156 * <p><strong>Patterns</strong>
jpayne@69 157 *
jpayne@69 158 * <p>A DecimalFormat consists of a <em>pattern</em> and a set of
jpayne@69 159 * <em>symbols</em>. The pattern may be set directly using
jpayne@69 160 * applyPattern(), or indirectly using other API methods which
jpayne@69 161 * manipulate aspects of the pattern, such as the minimum number of integer
jpayne@69 162 * digits. The symbols are stored in a DecimalFormatSymbols
jpayne@69 163 * object. When using the NumberFormat factory methods, the
jpayne@69 164 * pattern and symbols are read from ICU's locale data.
jpayne@69 165 *
jpayne@69 166 * <p><strong>Special Pattern Characters</strong>
jpayne@69 167 *
jpayne@69 168 * <p>Many characters in a pattern are taken literally; they are matched during
jpayne@69 169 * parsing and output unchanged during formatting. Special characters, on the
jpayne@69 170 * other hand, stand for other characters, strings, or classes of characters.
jpayne@69 171 * For example, the '#' character is replaced by a localized digit. Often the
jpayne@69 172 * replacement character is the same as the pattern character; in the U.S. locale,
jpayne@69 173 * the ',' grouping character is replaced by ','. However, the replacement is
jpayne@69 174 * still happening, and if the symbols are modified, the grouping character
jpayne@69 175 * changes. Some special characters affect the behavior of the formatter by
jpayne@69 176 * their presence; for example, if the percent character is seen, then the
jpayne@69 177 * value is multiplied by 100 before being displayed.
jpayne@69 178 *
jpayne@69 179 * <p>To insert a special character in a pattern as a literal, that is, without
jpayne@69 180 * any special meaning, the character must be quoted. There are some exceptions to
jpayne@69 181 * this which are noted below.
jpayne@69 182 *
jpayne@69 183 * <p>The characters listed here are used in non-localized patterns. Localized
jpayne@69 184 * patterns use the corresponding characters taken from this formatter's
jpayne@69 185 * DecimalFormatSymbols object instead, and these characters lose
jpayne@69 186 * their special status. Two exceptions are the currency sign and quote, which
jpayne@69 187 * are not localized.
jpayne@69 188 *
jpayne@69 189 * <table border=0 cellspacing=3 cellpadding=0>
jpayne@69 190 * <tr bgcolor="#ccccff">
jpayne@69 191 * <td align=left><strong>Symbol</strong>
jpayne@69 192 * <td align=left><strong>Location</strong>
jpayne@69 193 * <td align=left><strong>Localized?</strong>
jpayne@69 194 * <td align=left><strong>Meaning</strong>
jpayne@69 195 * <tr valign=top>
jpayne@69 196 * <td><code>0</code>
jpayne@69 197 * <td>Number
jpayne@69 198 * <td>Yes
jpayne@69 199 * <td>Digit
jpayne@69 200 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 201 * <td><code>1-9</code>
jpayne@69 202 * <td>Number
jpayne@69 203 * <td>Yes
jpayne@69 204 * <td>'1' through '9' indicate rounding.
jpayne@69 205 * <tr valign=top>
jpayne@69 206 * <td><code>\htmlonly&#x40;\endhtmlonly</code> <!--doxygen doesn't like @-->
jpayne@69 207 * <td>Number
jpayne@69 208 * <td>No
jpayne@69 209 * <td>Significant digit
jpayne@69 210 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 211 * <td><code>#</code>
jpayne@69 212 * <td>Number
jpayne@69 213 * <td>Yes
jpayne@69 214 * <td>Digit, zero shows as absent
jpayne@69 215 * <tr valign=top>
jpayne@69 216 * <td><code>.</code>
jpayne@69 217 * <td>Number
jpayne@69 218 * <td>Yes
jpayne@69 219 * <td>Decimal separator or monetary decimal separator
jpayne@69 220 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 221 * <td><code>-</code>
jpayne@69 222 * <td>Number
jpayne@69 223 * <td>Yes
jpayne@69 224 * <td>Minus sign
jpayne@69 225 * <tr valign=top>
jpayne@69 226 * <td><code>,</code>
jpayne@69 227 * <td>Number
jpayne@69 228 * <td>Yes
jpayne@69 229 * <td>Grouping separator
jpayne@69 230 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 231 * <td><code>E</code>
jpayne@69 232 * <td>Number
jpayne@69 233 * <td>Yes
jpayne@69 234 * <td>Separates mantissa and exponent in scientific notation.
jpayne@69 235 * <em>Need not be quoted in prefix or suffix.</em>
jpayne@69 236 * <tr valign=top>
jpayne@69 237 * <td><code>+</code>
jpayne@69 238 * <td>Exponent
jpayne@69 239 * <td>Yes
jpayne@69 240 * <td>Prefix positive exponents with localized plus sign.
jpayne@69 241 * <em>Need not be quoted in prefix or suffix.</em>
jpayne@69 242 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 243 * <td><code>;</code>
jpayne@69 244 * <td>Subpattern boundary
jpayne@69 245 * <td>Yes
jpayne@69 246 * <td>Separates positive and negative subpatterns
jpayne@69 247 * <tr valign=top>
jpayne@69 248 * <td><code>\%</code>
jpayne@69 249 * <td>Prefix or suffix
jpayne@69 250 * <td>Yes
jpayne@69 251 * <td>Multiply by 100 and show as percentage
jpayne@69 252 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 253 * <td><code>\\u2030</code>
jpayne@69 254 * <td>Prefix or suffix
jpayne@69 255 * <td>Yes
jpayne@69 256 * <td>Multiply by 1000 and show as per mille
jpayne@69 257 * <tr valign=top>
jpayne@69 258 * <td><code>\htmlonly&curren;\endhtmlonly</code> (<code>\\u00A4</code>)
jpayne@69 259 * <td>Prefix or suffix
jpayne@69 260 * <td>No
jpayne@69 261 * <td>Currency sign, replaced by currency symbol. If
jpayne@69 262 * doubled, replaced by international currency symbol.
jpayne@69 263 * If tripled, replaced by currency plural names, for example,
jpayne@69 264 * "US dollar" or "US dollars" for America.
jpayne@69 265 * If present in a pattern, the monetary decimal separator
jpayne@69 266 * is used instead of the decimal separator.
jpayne@69 267 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 268 * <td><code>'</code>
jpayne@69 269 * <td>Prefix or suffix
jpayne@69 270 * <td>No
jpayne@69 271 * <td>Used to quote special characters in a prefix or suffix,
jpayne@69 272 * for example, <code>"'#'#"</code> formats 123 to
jpayne@69 273 * <code>"#123"</code>. To create a single quote
jpayne@69 274 * itself, use two in a row: <code>"# o''clock"</code>.
jpayne@69 275 * <tr valign=top>
jpayne@69 276 * <td><code>*</code>
jpayne@69 277 * <td>Prefix or suffix boundary
jpayne@69 278 * <td>Yes
jpayne@69 279 * <td>Pad escape, precedes pad character
jpayne@69 280 * </table>
jpayne@69 281 *
jpayne@69 282 * <p>A DecimalFormat pattern contains a positive and negative
jpayne@69 283 * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a
jpayne@69 284 * prefix, a numeric part, and a suffix. If there is no explicit negative
jpayne@69 285 * subpattern, the negative subpattern is the localized minus sign prefixed to the
jpayne@69 286 * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there
jpayne@69 287 * is an explicit negative subpattern, it serves only to specify the negative
jpayne@69 288 * prefix and suffix; the number of digits, minimal digits, and other
jpayne@69 289 * characteristics are ignored in the negative subpattern. That means that
jpayne@69 290 * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)".
jpayne@69 291 *
jpayne@69 292 * <p>The prefixes, suffixes, and various symbols used for infinity, digits,
jpayne@69 293 * thousands separators, decimal separators, etc. may be set to arbitrary
jpayne@69 294 * values, and they will appear properly during formatting. However, care must
jpayne@69 295 * be taken that the symbols and strings do not conflict, or parsing will be
jpayne@69 296 * unreliable. For example, either the positive and negative prefixes or the
jpayne@69 297 * suffixes must be distinct for parse() to be able
jpayne@69 298 * to distinguish positive from negative values. Another example is that the
jpayne@69 299 * decimal separator and thousands separator should be distinct characters, or
jpayne@69 300 * parsing will be impossible.
jpayne@69 301 *
jpayne@69 302 * <p>The <em>grouping separator</em> is a character that separates clusters of
jpayne@69 303 * integer digits to make large numbers more legible. It commonly used for
jpayne@69 304 * thousands, but in some locales it separates ten-thousands. The <em>grouping
jpayne@69 305 * size</em> is the number of digits between the grouping separators, such as 3
jpayne@69 306 * for "100,000,000" or 4 for "1 0000 0000". There are actually two different
jpayne@69 307 * grouping sizes: One used for the least significant integer digits, the
jpayne@69 308 * <em>primary grouping size</em>, and one used for all others, the
jpayne@69 309 * <em>secondary grouping size</em>. In most locales these are the same, but
jpayne@69 310 * sometimes they are different. For example, if the primary grouping interval
jpayne@69 311 * is 3, and the secondary is 2, then this corresponds to the pattern
jpayne@69 312 * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a
jpayne@69 313 * pattern contains multiple grouping separators, the interval between the last
jpayne@69 314 * one and the end of the integer defines the primary grouping size, and the
jpayne@69 315 * interval between the last two defines the secondary grouping size. All others
jpayne@69 316 * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####".
jpayne@69 317 *
jpayne@69 318 * <p>Illegal patterns, such as "#.#.#" or "#.###,###", will cause
jpayne@69 319 * DecimalFormat to set a failing UErrorCode.
jpayne@69 320 *
jpayne@69 321 * <p><strong>Pattern BNF</strong>
jpayne@69 322 *
jpayne@69 323 * <pre>
jpayne@69 324 * pattern := subpattern (';' subpattern)?
jpayne@69 325 * subpattern := prefix? number exponent? suffix?
jpayne@69 326 * number := (integer ('.' fraction)?) | sigDigits
jpayne@69 327 * prefix := '\\u0000'..'\\uFFFD' - specialCharacters
jpayne@69 328 * suffix := '\\u0000'..'\\uFFFD' - specialCharacters
jpayne@69 329 * integer := '#'* '0'* '0'
jpayne@69 330 * fraction := '0'* '#'*
jpayne@69 331 * sigDigits := '#'* '@' '@'* '#'*
jpayne@69 332 * exponent := 'E' '+'? '0'* '0'
jpayne@69 333 * padSpec := '*' padChar
jpayne@69 334 * padChar := '\\u0000'..'\\uFFFD' - quote
jpayne@69 335 * &nbsp;
jpayne@69 336 * Notation:
jpayne@69 337 * X* 0 or more instances of X
jpayne@69 338 * X? 0 or 1 instances of X
jpayne@69 339 * X|Y either X or Y
jpayne@69 340 * C..D any character from C up to D, inclusive
jpayne@69 341 * S-T characters in S, except those in T
jpayne@69 342 * </pre>
jpayne@69 343 * The first subpattern is for positive numbers. The second (optional)
jpayne@69 344 * subpattern is for negative numbers.
jpayne@69 345 *
jpayne@69 346 * <p>Not indicated in the BNF syntax above:
jpayne@69 347 *
jpayne@69 348 * <ul><li>The grouping separator ',' can occur inside the integer and
jpayne@69 349 * sigDigits elements, between any two pattern characters of that
jpayne@69 350 * element, as long as the integer or sigDigits element is not
jpayne@69 351 * followed by the exponent element.
jpayne@69 352 *
jpayne@69 353 * <li>Two grouping intervals are recognized: That between the
jpayne@69 354 * decimal point and the first grouping symbol, and that
jpayne@69 355 * between the first and second grouping symbols. These
jpayne@69 356 * intervals are identical in most locales, but in some
jpayne@69 357 * locales they differ. For example, the pattern
jpayne@69 358 * &quot;#,##,###&quot; formats the number 123456789 as
jpayne@69 359 * &quot;12,34,56,789&quot;.</li>
jpayne@69 360 *
jpayne@69 361 * <li>The pad specifier <code>padSpec</code> may appear before the prefix,
jpayne@69 362 * after the prefix, before the suffix, after the suffix, or not at all.
jpayne@69 363 *
jpayne@69 364 * <li>In place of '0', the digits '1' through '9' may be used to
jpayne@69 365 * indicate a rounding increment.
jpayne@69 366 * </ul>
jpayne@69 367 *
jpayne@69 368 * <p><strong>Parsing</strong>
jpayne@69 369 *
jpayne@69 370 * <p>DecimalFormat parses all Unicode characters that represent
jpayne@69 371 * decimal digits, as defined by u_charDigitValue(). In addition,
jpayne@69 372 * DecimalFormat also recognizes as digits the ten consecutive
jpayne@69 373 * characters starting with the localized zero digit defined in the
jpayne@69 374 * DecimalFormatSymbols object. During formatting, the
jpayne@69 375 * DecimalFormatSymbols-based digits are output.
jpayne@69 376 *
jpayne@69 377 * <p>During parsing, grouping separators are ignored if in lenient mode;
jpayne@69 378 * otherwise, if present, they must be in appropriate positions.
jpayne@69 379 *
jpayne@69 380 * <p>For currency parsing, the formatter is able to parse every currency
jpayne@69 381 * style formats no matter which style the formatter is constructed with.
jpayne@69 382 * For example, a formatter instance gotten from
jpayne@69 383 * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse
jpayne@69 384 * formats such as "USD1.00" and "3.00 US dollars".
jpayne@69 385 *
jpayne@69 386 * <p>If parse(UnicodeString&,Formattable&,ParsePosition&)
jpayne@69 387 * fails to parse a string, it leaves the parse position unchanged.
jpayne@69 388 * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&)
jpayne@69 389 * indicates parse failure by setting a failing
jpayne@69 390 * UErrorCode.
jpayne@69 391 *
jpayne@69 392 * <p><strong>Formatting</strong>
jpayne@69 393 *
jpayne@69 394 * <p>Formatting is guided by several parameters, all of which can be
jpayne@69 395 * specified either using a pattern or using the API. The following
jpayne@69 396 * description applies to formats that do not use <a href="#sci">scientific
jpayne@69 397 * notation</a> or <a href="#sigdig">significant digits</a>.
jpayne@69 398 *
jpayne@69 399 * <ul><li>If the number of actual integer digits exceeds the
jpayne@69 400 * <em>maximum integer digits</em>, then only the least significant
jpayne@69 401 * digits are shown. For example, 1997 is formatted as "97" if the
jpayne@69 402 * maximum integer digits is set to 2.
jpayne@69 403 *
jpayne@69 404 * <li>If the number of actual integer digits is less than the
jpayne@69 405 * <em>minimum integer digits</em>, then leading zeros are added. For
jpayne@69 406 * example, 1997 is formatted as "01997" if the minimum integer digits
jpayne@69 407 * is set to 5.
jpayne@69 408 *
jpayne@69 409 * <li>If the number of actual fraction digits exceeds the <em>maximum
jpayne@69 410 * fraction digits</em>, then rounding is performed to the
jpayne@69 411 * maximum fraction digits. For example, 0.125 is formatted as "0.12"
jpayne@69 412 * if the maximum fraction digits is 2. This behavior can be changed
jpayne@69 413 * by specifying a rounding increment and/or a rounding mode.
jpayne@69 414 *
jpayne@69 415 * <li>If the number of actual fraction digits is less than the
jpayne@69 416 * <em>minimum fraction digits</em>, then trailing zeros are added.
jpayne@69 417 * For example, 0.125 is formatted as "0.1250" if the minimum fraction
jpayne@69 418 * digits is set to 4.
jpayne@69 419 *
jpayne@69 420 * <li>Trailing fractional zeros are not displayed if they occur
jpayne@69 421 * <em>j</em> positions after the decimal, where <em>j</em> is less
jpayne@69 422 * than the maximum fraction digits. For example, 0.10004 is
jpayne@69 423 * formatted as "0.1" if the maximum fraction digits is four or less.
jpayne@69 424 * </ul>
jpayne@69 425 *
jpayne@69 426 * <p><strong>Special Values</strong>
jpayne@69 427 *
jpayne@69 428 * <p><code>NaN</code> is represented as a single character, typically
jpayne@69 429 * <code>\\uFFFD</code>. This character is determined by the
jpayne@69 430 * DecimalFormatSymbols object. This is the only value for which
jpayne@69 431 * the prefixes and suffixes are not used.
jpayne@69 432 *
jpayne@69 433 * <p>Infinity is represented as a single character, typically
jpayne@69 434 * <code>\\u221E</code>, with the positive or negative prefixes and suffixes
jpayne@69 435 * applied. The infinity character is determined by the
jpayne@69 436 * DecimalFormatSymbols object.
jpayne@69 437 *
jpayne@69 438 * <a name="sci"><strong>Scientific Notation</strong></a>
jpayne@69 439 *
jpayne@69 440 * <p>Numbers in scientific notation are expressed as the product of a mantissa
jpayne@69 441 * and a power of ten, for example, 1234 can be expressed as 1.234 x 10<sup>3</sup>. The
jpayne@69 442 * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0),
jpayne@69 443 * but it need not be. DecimalFormat supports arbitrary mantissas.
jpayne@69 444 * DecimalFormat can be instructed to use scientific
jpayne@69 445 * notation through the API or through the pattern. In a pattern, the exponent
jpayne@69 446 * character immediately followed by one or more digit characters indicates
jpayne@69 447 * scientific notation. Example: "0.###E0" formats the number 1234 as
jpayne@69 448 * "1.234E3".
jpayne@69 449 *
jpayne@69 450 * <ul>
jpayne@69 451 * <li>The number of digit characters after the exponent character gives the
jpayne@69 452 * minimum exponent digit count. There is no maximum. Negative exponents are
jpayne@69 453 * formatted using the localized minus sign, <em>not</em> the prefix and suffix
jpayne@69 454 * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix
jpayne@69 455 * positive exponents with a localized plus sign, specify '+' between the
jpayne@69 456 * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0",
jpayne@69 457 * "1E-1", etc. (In localized patterns, use the localized plus sign rather than
jpayne@69 458 * '+'.)
jpayne@69 459 *
jpayne@69 460 * <li>The minimum number of integer digits is achieved by adjusting the
jpayne@69 461 * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This
jpayne@69 462 * only happens if there is no maximum number of integer digits. If there is a
jpayne@69 463 * maximum, then the minimum number of integer digits is fixed at one.
jpayne@69 464 *
jpayne@69 465 * <li>The maximum number of integer digits, if present, specifies the exponent
jpayne@69 466 * grouping. The most common use of this is to generate <em>engineering
jpayne@69 467 * notation</em>, in which the exponent is a multiple of three, e.g.,
jpayne@69 468 * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3".
jpayne@69 469 *
jpayne@69 470 * <li>When using scientific notation, the formatter controls the
jpayne@69 471 * digit counts using significant digits logic. The maximum number of
jpayne@69 472 * significant digits limits the total number of integer and fraction
jpayne@69 473 * digits that will be shown in the mantissa; it does not affect
jpayne@69 474 * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3".
jpayne@69 475 * See the section on significant digits for more details.
jpayne@69 476 *
jpayne@69 477 * <li>The number of significant digits shown is determined as
jpayne@69 478 * follows: If areSignificantDigitsUsed() returns false, then the
jpayne@69 479 * minimum number of significant digits shown is one, and the maximum
jpayne@69 480 * number of significant digits shown is the sum of the <em>minimum
jpayne@69 481 * integer</em> and <em>maximum fraction</em> digits, and is
jpayne@69 482 * unaffected by the maximum integer digits. If this sum is zero,
jpayne@69 483 * then all significant digits are shown. If
jpayne@69 484 * areSignificantDigitsUsed() returns true, then the significant digit
jpayne@69 485 * counts are specified by getMinimumSignificantDigits() and
jpayne@69 486 * getMaximumSignificantDigits(). In this case, the number of
jpayne@69 487 * integer digits is fixed at one, and there is no exponent grouping.
jpayne@69 488 *
jpayne@69 489 * <li>Exponential patterns may not contain grouping separators.
jpayne@69 490 * </ul>
jpayne@69 491 *
jpayne@69 492 * <a name="sigdig"><strong>Significant Digits</strong></a>
jpayne@69 493 *
jpayne@69 494 * <code>DecimalFormat</code> has two ways of controlling how many
jpayne@69 495 * digits are shows: (a) significant digits counts, or (b) integer and
jpayne@69 496 * fraction digit counts. Integer and fraction digit counts are
jpayne@69 497 * described above. When a formatter is using significant digits
jpayne@69 498 * counts, the number of integer and fraction digits is not specified
jpayne@69 499 * directly, and the formatter settings for these counts are ignored.
jpayne@69 500 * Instead, the formatter uses however many integer and fraction
jpayne@69 501 * digits are required to display the specified number of significant
jpayne@69 502 * digits. Examples:
jpayne@69 503 *
jpayne@69 504 * <table border=0 cellspacing=3 cellpadding=0>
jpayne@69 505 * <tr bgcolor="#ccccff">
jpayne@69 506 * <td align=left>Pattern
jpayne@69 507 * <td align=left>Minimum significant digits
jpayne@69 508 * <td align=left>Maximum significant digits
jpayne@69 509 * <td align=left>Number
jpayne@69 510 * <td align=left>Output of format()
jpayne@69 511 * <tr valign=top>
jpayne@69 512 * <td><code>\@\@\@</code>
jpayne@69 513 * <td>3
jpayne@69 514 * <td>3
jpayne@69 515 * <td>12345
jpayne@69 516 * <td><code>12300</code>
jpayne@69 517 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 518 * <td><code>\@\@\@</code>
jpayne@69 519 * <td>3
jpayne@69 520 * <td>3
jpayne@69 521 * <td>0.12345
jpayne@69 522 * <td><code>0.123</code>
jpayne@69 523 * <tr valign=top>
jpayne@69 524 * <td><code>\@\@##</code>
jpayne@69 525 * <td>2
jpayne@69 526 * <td>4
jpayne@69 527 * <td>3.14159
jpayne@69 528 * <td><code>3.142</code>
jpayne@69 529 * <tr valign=top bgcolor="#eeeeff">
jpayne@69 530 * <td><code>\@\@##</code>
jpayne@69 531 * <td>2
jpayne@69 532 * <td>4
jpayne@69 533 * <td>1.23004
jpayne@69 534 * <td><code>1.23</code>
jpayne@69 535 * </table>
jpayne@69 536 *
jpayne@69 537 * <ul>
jpayne@69 538 * <li>Significant digit counts may be expressed using patterns that
jpayne@69 539 * specify a minimum and maximum number of significant digits. These
jpayne@69 540 * are indicated by the <code>'@'</code> and <code>'#'</code>
jpayne@69 541 * characters. The minimum number of significant digits is the number
jpayne@69 542 * of <code>'@'</code> characters. The maximum number of significant
jpayne@69 543 * digits is the number of <code>'@'</code> characters plus the number
jpayne@69 544 * of <code>'#'</code> characters following on the right. For
jpayne@69 545 * example, the pattern <code>"@@@"</code> indicates exactly 3
jpayne@69 546 * significant digits. The pattern <code>"@##"</code> indicates from
jpayne@69 547 * 1 to 3 significant digits. Trailing zero digits to the right of
jpayne@69 548 * the decimal separator are suppressed after the minimum number of
jpayne@69 549 * significant digits have been shown. For example, the pattern
jpayne@69 550 * <code>"@##"</code> formats the number 0.1203 as
jpayne@69 551 * <code>"0.12"</code>.
jpayne@69 552 *
jpayne@69 553 * <li>If a pattern uses significant digits, it may not contain a
jpayne@69 554 * decimal separator, nor the <code>'0'</code> pattern character.
jpayne@69 555 * Patterns such as <code>"@00"</code> or <code>"@.###"</code> are
jpayne@69 556 * disallowed.
jpayne@69 557 *
jpayne@69 558 * <li>Any number of <code>'#'</code> characters may be prepended to
jpayne@69 559 * the left of the leftmost <code>'@'</code> character. These have no
jpayne@69 560 * effect on the minimum and maximum significant digits counts, but
jpayne@69 561 * may be used to position grouping separators. For example,
jpayne@69 562 * <code>"#,#@#"</code> indicates a minimum of one significant digits,
jpayne@69 563 * a maximum of two significant digits, and a grouping size of three.
jpayne@69 564 *
jpayne@69 565 * <li>In order to enable significant digits formatting, use a pattern
jpayne@69 566 * containing the <code>'@'</code> pattern character. Alternatively,
jpayne@69 567 * call setSignificantDigitsUsed(TRUE).
jpayne@69 568 *
jpayne@69 569 * <li>In order to disable significant digits formatting, use a
jpayne@69 570 * pattern that does not contain the <code>'@'</code> pattern
jpayne@69 571 * character. Alternatively, call setSignificantDigitsUsed(FALSE).
jpayne@69 572 *
jpayne@69 573 * <li>The number of significant digits has no effect on parsing.
jpayne@69 574 *
jpayne@69 575 * <li>Significant digits may be used together with exponential notation. Such
jpayne@69 576 * patterns are equivalent to a normal exponential pattern with a minimum and
jpayne@69 577 * maximum integer digit count of one, a minimum fraction digit count of
jpayne@69 578 * <code>getMinimumSignificantDigits() - 1</code>, and a maximum fraction digit
jpayne@69 579 * count of <code>getMaximumSignificantDigits() - 1</code>. For example, the
jpayne@69 580 * pattern <code>"@@###E0"</code> is equivalent to <code>"0.0###E0"</code>.
jpayne@69 581 *
jpayne@69 582 * <li>If significant digits are in use, then the integer and fraction
jpayne@69 583 * digit counts, as set via the API, are ignored. If significant
jpayne@69 584 * digits are not in use, then the significant digit counts, as set via
jpayne@69 585 * the API, are ignored.
jpayne@69 586 *
jpayne@69 587 * </ul>
jpayne@69 588 *
jpayne@69 589 * <p><strong>Padding</strong>
jpayne@69 590 *
jpayne@69 591 * <p>DecimalFormat supports padding the result of
jpayne@69 592 * format() to a specific width. Padding may be specified either
jpayne@69 593 * through the API or through the pattern syntax. In a pattern the pad escape
jpayne@69 594 * character, followed by a single pad character, causes padding to be parsed
jpayne@69 595 * and formatted. The pad escape character is '*' in unlocalized patterns, and
jpayne@69 596 * can be localized using DecimalFormatSymbols::setSymbol() with a
jpayne@69 597 * DecimalFormatSymbols::kPadEscapeSymbol
jpayne@69 598 * selector. For example, <code>"$*x#,##0.00"</code> formats 123 to
jpayne@69 599 * <code>"$xx123.00"</code>, and 1234 to <code>"$1,234.00"</code>.
jpayne@69 600 *
jpayne@69 601 * <ul>
jpayne@69 602 * <li>When padding is in effect, the width of the positive subpattern,
jpayne@69 603 * including prefix and suffix, determines the format width. For example, in
jpayne@69 604 * the pattern <code>"* #0 o''clock"</code>, the format width is 10.
jpayne@69 605 *
jpayne@69 606 * <li>The width is counted in 16-bit code units (char16_ts).
jpayne@69 607 *
jpayne@69 608 * <li>Some parameters which usually do not matter have meaning when padding is
jpayne@69 609 * used, because the pattern width is significant with padding. In the pattern
jpayne@69 610 * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##,"
jpayne@69 611 * do not affect the grouping size or maximum integer digits, but they do affect
jpayne@69 612 * the format width.
jpayne@69 613 *
jpayne@69 614 * <li>Padding may be inserted at one of four locations: before the prefix,
jpayne@69 615 * after the prefix, before the suffix, or after the suffix. If padding is
jpayne@69 616 * specified in any other location, applyPattern()
jpayne@69 617 * sets a failing UErrorCode. If there is no prefix,
jpayne@69 618 * before the prefix and after the prefix are equivalent, likewise for the
jpayne@69 619 * suffix.
jpayne@69 620 *
jpayne@69 621 * <li>When specified in a pattern, the 32-bit code point immediately
jpayne@69 622 * following the pad escape is the pad character. This may be any character,
jpayne@69 623 * including a special pattern character. That is, the pad escape
jpayne@69 624 * <em>escapes</em> the following character. If there is no character after
jpayne@69 625 * the pad escape, then the pattern is illegal.
jpayne@69 626 *
jpayne@69 627 * </ul>
jpayne@69 628 *
jpayne@69 629 * <p><strong>Rounding</strong>
jpayne@69 630 *
jpayne@69 631 * <p>DecimalFormat supports rounding to a specific increment. For
jpayne@69 632 * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the
jpayne@69 633 * nearest 0.65 is 1.3. The rounding increment may be specified through the API
jpayne@69 634 * or in a pattern. To specify a rounding increment in a pattern, include the
jpayne@69 635 * increment in the pattern itself. "#,#50" specifies a rounding increment of
jpayne@69 636 * 50. "#,##0.05" specifies a rounding increment of 0.05.
jpayne@69 637 *
jpayne@69 638 * <p>In the absence of an explicit rounding increment numbers are
jpayne@69 639 * rounded to their formatted width.
jpayne@69 640 *
jpayne@69 641 * <ul>
jpayne@69 642 * <li>Rounding only affects the string produced by formatting. It does
jpayne@69 643 * not affect parsing or change any numerical values.
jpayne@69 644 *
jpayne@69 645 * <li>A <em>rounding mode</em> determines how values are rounded; see
jpayne@69 646 * DecimalFormat::ERoundingMode. The default rounding mode is
jpayne@69 647 * DecimalFormat::kRoundHalfEven. The rounding mode can only be set
jpayne@69 648 * through the API; it can not be set with a pattern.
jpayne@69 649 *
jpayne@69 650 * <li>Some locales use rounding in their currency formats to reflect the
jpayne@69 651 * smallest currency denomination.
jpayne@69 652 *
jpayne@69 653 * <li>In a pattern, digits '1' through '9' specify rounding, but otherwise
jpayne@69 654 * behave identically to digit '0'.
jpayne@69 655 * </ul>
jpayne@69 656 *
jpayne@69 657 * <p><strong>Synchronization</strong>
jpayne@69 658 *
jpayne@69 659 * <p>DecimalFormat objects are not synchronized. Multiple
jpayne@69 660 * threads should not access one formatter concurrently.
jpayne@69 661 *
jpayne@69 662 * <p><strong>Subclassing</strong>
jpayne@69 663 *
jpayne@69 664 * <p><em>User subclasses are not supported.</em> While clients may write
jpayne@69 665 * subclasses, such code will not necessarily work and will not be
jpayne@69 666 * guaranteed to work stably from release to release.
jpayne@69 667 */
jpayne@69 668 class U_I18N_API DecimalFormat : public NumberFormat {
jpayne@69 669 public:
jpayne@69 670 /**
jpayne@69 671 * Pad position.
jpayne@69 672 * @stable ICU 2.4
jpayne@69 673 */
jpayne@69 674 enum EPadPosition {
jpayne@69 675 kPadBeforePrefix, kPadAfterPrefix, kPadBeforeSuffix, kPadAfterSuffix
jpayne@69 676 };
jpayne@69 677
jpayne@69 678 /**
jpayne@69 679 * Create a DecimalFormat using the default pattern and symbols
jpayne@69 680 * for the default locale. This is a convenient way to obtain a
jpayne@69 681 * DecimalFormat when internationalization is not the main concern.
jpayne@69 682 * <P>
jpayne@69 683 * To obtain standard formats for a given locale, use the factory methods
jpayne@69 684 * on NumberFormat such as createInstance. These factories will
jpayne@69 685 * return the most appropriate sub-class of NumberFormat for a given
jpayne@69 686 * locale.
jpayne@69 687 * <p>
jpayne@69 688 * <strong>NOTE:</strong> New users are strongly encouraged to use
jpayne@69 689 * #icu::number::NumberFormatter instead of DecimalFormat.
jpayne@69 690 * @param status Output param set to success/failure code. If the
jpayne@69 691 * pattern is invalid this will be set to a failure code.
jpayne@69 692 * @stable ICU 2.0
jpayne@69 693 */
jpayne@69 694 DecimalFormat(UErrorCode& status);
jpayne@69 695
jpayne@69 696 /**
jpayne@69 697 * Create a DecimalFormat from the given pattern and the symbols
jpayne@69 698 * for the default locale. This is a convenient way to obtain a
jpayne@69 699 * DecimalFormat when internationalization is not the main concern.
jpayne@69 700 * <P>
jpayne@69 701 * To obtain standard formats for a given locale, use the factory methods
jpayne@69 702 * on NumberFormat such as createInstance. These factories will
jpayne@69 703 * return the most appropriate sub-class of NumberFormat for a given
jpayne@69 704 * locale.
jpayne@69 705 * <p>
jpayne@69 706 * <strong>NOTE:</strong> New users are strongly encouraged to use
jpayne@69 707 * #icu::number::NumberFormatter instead of DecimalFormat.
jpayne@69 708 * @param pattern A non-localized pattern string.
jpayne@69 709 * @param status Output param set to success/failure code. If the
jpayne@69 710 * pattern is invalid this will be set to a failure code.
jpayne@69 711 * @stable ICU 2.0
jpayne@69 712 */
jpayne@69 713 DecimalFormat(const UnicodeString& pattern, UErrorCode& status);
jpayne@69 714
jpayne@69 715 /**
jpayne@69 716 * Create a DecimalFormat from the given pattern and symbols.
jpayne@69 717 * Use this constructor when you need to completely customize the
jpayne@69 718 * behavior of the format.
jpayne@69 719 * <P>
jpayne@69 720 * To obtain standard formats for a given
jpayne@69 721 * locale, use the factory methods on NumberFormat such as
jpayne@69 722 * createInstance or createCurrencyInstance. If you need only minor adjustments
jpayne@69 723 * to a standard format, you can modify the format returned by
jpayne@69 724 * a NumberFormat factory method.
jpayne@69 725 * <p>
jpayne@69 726 * <strong>NOTE:</strong> New users are strongly encouraged to use
jpayne@69 727 * #icu::number::NumberFormatter instead of DecimalFormat.
jpayne@69 728 *
jpayne@69 729 * @param pattern a non-localized pattern string
jpayne@69 730 * @param symbolsToAdopt the set of symbols to be used. The caller should not
jpayne@69 731 * delete this object after making this call.
jpayne@69 732 * @param status Output param set to success/failure code. If the
jpayne@69 733 * pattern is invalid this will be set to a failure code.
jpayne@69 734 * @stable ICU 2.0
jpayne@69 735 */
jpayne@69 736 DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status);
jpayne@69 737
jpayne@69 738 #ifndef U_HIDE_INTERNAL_API
jpayne@69 739
jpayne@69 740 /**
jpayne@69 741 * This API is for ICU use only.
jpayne@69 742 * Create a DecimalFormat from the given pattern, symbols, and style.
jpayne@69 743 *
jpayne@69 744 * @param pattern a non-localized pattern string
jpayne@69 745 * @param symbolsToAdopt the set of symbols to be used. The caller should not
jpayne@69 746 * delete this object after making this call.
jpayne@69 747 * @param style style of decimal format
jpayne@69 748 * @param status Output param set to success/failure code. If the
jpayne@69 749 * pattern is invalid this will be set to a failure code.
jpayne@69 750 * @internal
jpayne@69 751 */
jpayne@69 752 DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
jpayne@69 753 UNumberFormatStyle style, UErrorCode& status);
jpayne@69 754
jpayne@69 755 #if UCONFIG_HAVE_PARSEALLINPUT
jpayne@69 756
jpayne@69 757 /**
jpayne@69 758 * @internal
jpayne@69 759 */
jpayne@69 760 void setParseAllInput(UNumberFormatAttributeValue value);
jpayne@69 761
jpayne@69 762 #endif
jpayne@69 763
jpayne@69 764 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 765
jpayne@69 766 private:
jpayne@69 767
jpayne@69 768 /**
jpayne@69 769 * Internal constructor for DecimalFormat; sets up internal fields. All public constructors should
jpayne@69 770 * call this constructor.
jpayne@69 771 */
jpayne@69 772 DecimalFormat(const DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status);
jpayne@69 773
jpayne@69 774 public:
jpayne@69 775
jpayne@69 776 /**
jpayne@69 777 * Set an integer attribute on this DecimalFormat.
jpayne@69 778 * May return U_UNSUPPORTED_ERROR if this instance does not support
jpayne@69 779 * the specified attribute.
jpayne@69 780 * @param attr the attribute to set
jpayne@69 781 * @param newValue new value
jpayne@69 782 * @param status the error type
jpayne@69 783 * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) )
jpayne@69 784 * @stable ICU 51
jpayne@69 785 */
jpayne@69 786 virtual DecimalFormat& setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErrorCode& status);
jpayne@69 787
jpayne@69 788 /**
jpayne@69 789 * Get an integer
jpayne@69 790 * May return U_UNSUPPORTED_ERROR if this instance does not support
jpayne@69 791 * the specified attribute.
jpayne@69 792 * @param attr the attribute to set
jpayne@69 793 * @param status the error type
jpayne@69 794 * @return the attribute value. Undefined if there is an error.
jpayne@69 795 * @stable ICU 51
jpayne@69 796 */
jpayne@69 797 virtual int32_t getAttribute(UNumberFormatAttribute attr, UErrorCode& status) const;
jpayne@69 798
jpayne@69 799
jpayne@69 800 /**
jpayne@69 801 * Set whether or not grouping will be used in this format.
jpayne@69 802 * @param newValue True, grouping will be used in this format.
jpayne@69 803 * @see getGroupingUsed
jpayne@69 804 * @stable ICU 53
jpayne@69 805 */
jpayne@69 806 void setGroupingUsed(UBool newValue) U_OVERRIDE;
jpayne@69 807
jpayne@69 808 /**
jpayne@69 809 * Sets whether or not numbers should be parsed as integers only.
jpayne@69 810 * @param value set True, this format will parse numbers as integers
jpayne@69 811 * only.
jpayne@69 812 * @see isParseIntegerOnly
jpayne@69 813 * @stable ICU 53
jpayne@69 814 */
jpayne@69 815 void setParseIntegerOnly(UBool value) U_OVERRIDE;
jpayne@69 816
jpayne@69 817 /**
jpayne@69 818 * Sets whether lenient parsing should be enabled (it is off by default).
jpayne@69 819 *
jpayne@69 820 * @param enable \c TRUE if lenient parsing should be used,
jpayne@69 821 * \c FALSE otherwise.
jpayne@69 822 * @stable ICU 4.8
jpayne@69 823 */
jpayne@69 824 void setLenient(UBool enable) U_OVERRIDE;
jpayne@69 825
jpayne@69 826 /**
jpayne@69 827 * Create a DecimalFormat from the given pattern and symbols.
jpayne@69 828 * Use this constructor when you need to completely customize the
jpayne@69 829 * behavior of the format.
jpayne@69 830 * <P>
jpayne@69 831 * To obtain standard formats for a given
jpayne@69 832 * locale, use the factory methods on NumberFormat such as
jpayne@69 833 * createInstance or createCurrencyInstance. If you need only minor adjustments
jpayne@69 834 * to a standard format, you can modify the format returned by
jpayne@69 835 * a NumberFormat factory method.
jpayne@69 836 * <p>
jpayne@69 837 * <strong>NOTE:</strong> New users are strongly encouraged to use
jpayne@69 838 * #icu::number::NumberFormatter instead of DecimalFormat.
jpayne@69 839 *
jpayne@69 840 * @param pattern a non-localized pattern string
jpayne@69 841 * @param symbolsToAdopt the set of symbols to be used. The caller should not
jpayne@69 842 * delete this object after making this call.
jpayne@69 843 * @param parseError Output param to receive errors occurred during parsing
jpayne@69 844 * @param status Output param set to success/failure code. If the
jpayne@69 845 * pattern is invalid this will be set to a failure code.
jpayne@69 846 * @stable ICU 2.0
jpayne@69 847 */
jpayne@69 848 DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt,
jpayne@69 849 UParseError& parseError, UErrorCode& status);
jpayne@69 850
jpayne@69 851 /**
jpayne@69 852 * Create a DecimalFormat from the given pattern and symbols.
jpayne@69 853 * Use this constructor when you need to completely customize the
jpayne@69 854 * behavior of the format.
jpayne@69 855 * <P>
jpayne@69 856 * To obtain standard formats for a given
jpayne@69 857 * locale, use the factory methods on NumberFormat such as
jpayne@69 858 * createInstance or createCurrencyInstance. If you need only minor adjustments
jpayne@69 859 * to a standard format, you can modify the format returned by
jpayne@69 860 * a NumberFormat factory method.
jpayne@69 861 * <p>
jpayne@69 862 * <strong>NOTE:</strong> New users are strongly encouraged to use
jpayne@69 863 * #icu::number::NumberFormatter instead of DecimalFormat.
jpayne@69 864 *
jpayne@69 865 * @param pattern a non-localized pattern string
jpayne@69 866 * @param symbols the set of symbols to be used
jpayne@69 867 * @param status Output param set to success/failure code. If the
jpayne@69 868 * pattern is invalid this will be set to a failure code.
jpayne@69 869 * @stable ICU 2.0
jpayne@69 870 */
jpayne@69 871 DecimalFormat(const UnicodeString& pattern, const DecimalFormatSymbols& symbols, UErrorCode& status);
jpayne@69 872
jpayne@69 873 /**
jpayne@69 874 * Copy constructor.
jpayne@69 875 *
jpayne@69 876 * @param source the DecimalFormat object to be copied from.
jpayne@69 877 * @stable ICU 2.0
jpayne@69 878 */
jpayne@69 879 DecimalFormat(const DecimalFormat& source);
jpayne@69 880
jpayne@69 881 /**
jpayne@69 882 * Assignment operator.
jpayne@69 883 *
jpayne@69 884 * @param rhs the DecimalFormat object to be copied.
jpayne@69 885 * @stable ICU 2.0
jpayne@69 886 */
jpayne@69 887 DecimalFormat& operator=(const DecimalFormat& rhs);
jpayne@69 888
jpayne@69 889 /**
jpayne@69 890 * Destructor.
jpayne@69 891 * @stable ICU 2.0
jpayne@69 892 */
jpayne@69 893 ~DecimalFormat() U_OVERRIDE;
jpayne@69 894
jpayne@69 895 /**
jpayne@69 896 * Clone this Format object polymorphically. The caller owns the
jpayne@69 897 * result and should delete it when done.
jpayne@69 898 *
jpayne@69 899 * @return a polymorphic copy of this DecimalFormat.
jpayne@69 900 * @stable ICU 2.0
jpayne@69 901 */
jpayne@69 902 DecimalFormat* clone() const U_OVERRIDE;
jpayne@69 903
jpayne@69 904 /**
jpayne@69 905 * Return true if the given Format objects are semantically equal.
jpayne@69 906 * Objects of different subclasses are considered unequal.
jpayne@69 907 *
jpayne@69 908 * @param other the object to be compared with.
jpayne@69 909 * @return true if the given Format objects are semantically equal.
jpayne@69 910 * @stable ICU 2.0
jpayne@69 911 */
jpayne@69 912 UBool operator==(const Format& other) const U_OVERRIDE;
jpayne@69 913
jpayne@69 914
jpayne@69 915 using NumberFormat::format;
jpayne@69 916
jpayne@69 917 /**
jpayne@69 918 * Format a double or long number using base-10 representation.
jpayne@69 919 *
jpayne@69 920 * @param number The value to be formatted.
jpayne@69 921 * @param appendTo Output parameter to receive result.
jpayne@69 922 * Result is appended to existing contents.
jpayne@69 923 * @param pos On input: an alignment field, if desired.
jpayne@69 924 * On output: the offsets of the alignment field.
jpayne@69 925 * @return Reference to 'appendTo' parameter.
jpayne@69 926 * @stable ICU 2.0
jpayne@69 927 */
jpayne@69 928 UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE;
jpayne@69 929
jpayne@69 930 #ifndef U_HIDE_INTERNAL_API
jpayne@69 931 /**
jpayne@69 932 * Format a double or long number using base-10 representation.
jpayne@69 933 *
jpayne@69 934 * @param number The value to be formatted.
jpayne@69 935 * @param appendTo Output parameter to receive result.
jpayne@69 936 * Result is appended to existing contents.
jpayne@69 937 * @param pos On input: an alignment field, if desired.
jpayne@69 938 * On output: the offsets of the alignment field.
jpayne@69 939 * @param status
jpayne@69 940 * @return Reference to 'appendTo' parameter.
jpayne@69 941 * @internal
jpayne@69 942 */
jpayne@69 943 UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos,
jpayne@69 944 UErrorCode& status) const U_OVERRIDE;
jpayne@69 945 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 946
jpayne@69 947 /**
jpayne@69 948 * Format a double or long number using base-10 representation.
jpayne@69 949 *
jpayne@69 950 * @param number The value to be formatted.
jpayne@69 951 * @param appendTo Output parameter to receive result.
jpayne@69 952 * Result is appended to existing contents.
jpayne@69 953 * @param posIter On return, can be used to iterate over positions
jpayne@69 954 * of fields generated by this format call.
jpayne@69 955 * Can be NULL.
jpayne@69 956 * @param status Output param filled with success/failure status.
jpayne@69 957 * @return Reference to 'appendTo' parameter.
jpayne@69 958 * @stable ICU 4.4
jpayne@69 959 */
jpayne@69 960 UnicodeString& format(double number, UnicodeString& appendTo, FieldPositionIterator* posIter,
jpayne@69 961 UErrorCode& status) const U_OVERRIDE;
jpayne@69 962
jpayne@69 963 /**
jpayne@69 964 * Format a long number using base-10 representation.
jpayne@69 965 *
jpayne@69 966 * @param number The value to be formatted.
jpayne@69 967 * @param appendTo Output parameter to receive result.
jpayne@69 968 * Result is appended to existing contents.
jpayne@69 969 * @param pos On input: an alignment field, if desired.
jpayne@69 970 * On output: the offsets of the alignment field.
jpayne@69 971 * @return Reference to 'appendTo' parameter.
jpayne@69 972 * @stable ICU 2.0
jpayne@69 973 */
jpayne@69 974 UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE;
jpayne@69 975
jpayne@69 976 #ifndef U_HIDE_INTERNAL_API
jpayne@69 977 /**
jpayne@69 978 * Format a long number using base-10 representation.
jpayne@69 979 *
jpayne@69 980 * @param number The value to be formatted.
jpayne@69 981 * @param appendTo Output parameter to receive result.
jpayne@69 982 * Result is appended to existing contents.
jpayne@69 983 * @param pos On input: an alignment field, if desired.
jpayne@69 984 * On output: the offsets of the alignment field.
jpayne@69 985 * @param status Output param filled with success/failure status.
jpayne@69 986 * @return Reference to 'appendTo' parameter.
jpayne@69 987 * @internal
jpayne@69 988 */
jpayne@69 989 UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos,
jpayne@69 990 UErrorCode& status) const U_OVERRIDE;
jpayne@69 991 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 992
jpayne@69 993 /**
jpayne@69 994 * Format a long number using base-10 representation.
jpayne@69 995 *
jpayne@69 996 * @param number The value to be formatted.
jpayne@69 997 * @param appendTo Output parameter to receive result.
jpayne@69 998 * Result is appended to existing contents.
jpayne@69 999 * @param posIter On return, can be used to iterate over positions
jpayne@69 1000 * of fields generated by this format call.
jpayne@69 1001 * Can be NULL.
jpayne@69 1002 * @param status Output param filled with success/failure status.
jpayne@69 1003 * @return Reference to 'appendTo' parameter.
jpayne@69 1004 * @stable ICU 4.4
jpayne@69 1005 */
jpayne@69 1006 UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPositionIterator* posIter,
jpayne@69 1007 UErrorCode& status) const U_OVERRIDE;
jpayne@69 1008
jpayne@69 1009 /**
jpayne@69 1010 * Format an int64 number using base-10 representation.
jpayne@69 1011 *
jpayne@69 1012 * @param number The value to be formatted.
jpayne@69 1013 * @param appendTo Output parameter to receive result.
jpayne@69 1014 * Result is appended to existing contents.
jpayne@69 1015 * @param pos On input: an alignment field, if desired.
jpayne@69 1016 * On output: the offsets of the alignment field.
jpayne@69 1017 * @return Reference to 'appendTo' parameter.
jpayne@69 1018 * @stable ICU 2.8
jpayne@69 1019 */
jpayne@69 1020 UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE;
jpayne@69 1021
jpayne@69 1022 #ifndef U_HIDE_INTERNAL_API
jpayne@69 1023 /**
jpayne@69 1024 * Format an int64 number using base-10 representation.
jpayne@69 1025 *
jpayne@69 1026 * @param number The value to be formatted.
jpayne@69 1027 * @param appendTo Output parameter to receive result.
jpayne@69 1028 * Result is appended to existing contents.
jpayne@69 1029 * @param pos On input: an alignment field, if desired.
jpayne@69 1030 * On output: the offsets of the alignment field.
jpayne@69 1031 * @param status Output param filled with success/failure status.
jpayne@69 1032 * @return Reference to 'appendTo' parameter.
jpayne@69 1033 * @internal
jpayne@69 1034 */
jpayne@69 1035 UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos,
jpayne@69 1036 UErrorCode& status) const U_OVERRIDE;
jpayne@69 1037 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 1038
jpayne@69 1039 /**
jpayne@69 1040 * Format an int64 number using base-10 representation.
jpayne@69 1041 *
jpayne@69 1042 * @param number The value to be formatted.
jpayne@69 1043 * @param appendTo Output parameter to receive result.
jpayne@69 1044 * Result is appended to existing contents.
jpayne@69 1045 * @param posIter On return, can be used to iterate over positions
jpayne@69 1046 * of fields generated by this format call.
jpayne@69 1047 * Can be NULL.
jpayne@69 1048 * @param status Output param filled with success/failure status.
jpayne@69 1049 * @return Reference to 'appendTo' parameter.
jpayne@69 1050 * @stable ICU 4.4
jpayne@69 1051 */
jpayne@69 1052 UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPositionIterator* posIter,
jpayne@69 1053 UErrorCode& status) const U_OVERRIDE;
jpayne@69 1054
jpayne@69 1055 /**
jpayne@69 1056 * Format a decimal number.
jpayne@69 1057 * The syntax of the unformatted number is a "numeric string"
jpayne@69 1058 * as defined in the Decimal Arithmetic Specification, available at
jpayne@69 1059 * http://speleotrove.com/decimal
jpayne@69 1060 *
jpayne@69 1061 * @param number The unformatted number, as a string.
jpayne@69 1062 * @param appendTo Output parameter to receive result.
jpayne@69 1063 * Result is appended to existing contents.
jpayne@69 1064 * @param posIter On return, can be used to iterate over positions
jpayne@69 1065 * of fields generated by this format call.
jpayne@69 1066 * Can be NULL.
jpayne@69 1067 * @param status Output param filled with success/failure status.
jpayne@69 1068 * @return Reference to 'appendTo' parameter.
jpayne@69 1069 * @stable ICU 4.4
jpayne@69 1070 */
jpayne@69 1071 UnicodeString& format(StringPiece number, UnicodeString& appendTo, FieldPositionIterator* posIter,
jpayne@69 1072 UErrorCode& status) const U_OVERRIDE;
jpayne@69 1073
jpayne@69 1074 #ifndef U_HIDE_INTERNAL_API
jpayne@69 1075
jpayne@69 1076 /**
jpayne@69 1077 * Format a decimal number.
jpayne@69 1078 * The number is a DecimalQuantity wrapper onto a floating point decimal number.
jpayne@69 1079 * The default implementation in NumberFormat converts the decimal number
jpayne@69 1080 * to a double and formats that.
jpayne@69 1081 *
jpayne@69 1082 * @param number The number, a DecimalQuantity format Decimal Floating Point.
jpayne@69 1083 * @param appendTo Output parameter to receive result.
jpayne@69 1084 * Result is appended to existing contents.
jpayne@69 1085 * @param posIter On return, can be used to iterate over positions
jpayne@69 1086 * of fields generated by this format call.
jpayne@69 1087 * @param status Output param filled with success/failure status.
jpayne@69 1088 * @return Reference to 'appendTo' parameter.
jpayne@69 1089 * @internal
jpayne@69 1090 */
jpayne@69 1091 UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo,
jpayne@69 1092 FieldPositionIterator* posIter, UErrorCode& status) const U_OVERRIDE;
jpayne@69 1093
jpayne@69 1094 /**
jpayne@69 1095 * Format a decimal number.
jpayne@69 1096 * The number is a DecimalQuantity wrapper onto a floating point decimal number.
jpayne@69 1097 * The default implementation in NumberFormat converts the decimal number
jpayne@69 1098 * to a double and formats that.
jpayne@69 1099 *
jpayne@69 1100 * @param number The number, a DecimalQuantity format Decimal Floating Point.
jpayne@69 1101 * @param appendTo Output parameter to receive result.
jpayne@69 1102 * Result is appended to existing contents.
jpayne@69 1103 * @param pos On input: an alignment field, if desired.
jpayne@69 1104 * On output: the offsets of the alignment field.
jpayne@69 1105 * @param status Output param filled with success/failure status.
jpayne@69 1106 * @return Reference to 'appendTo' parameter.
jpayne@69 1107 * @internal
jpayne@69 1108 */
jpayne@69 1109 UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo,
jpayne@69 1110 FieldPosition& pos, UErrorCode& status) const U_OVERRIDE;
jpayne@69 1111
jpayne@69 1112 #endif // U_HIDE_INTERNAL_API
jpayne@69 1113
jpayne@69 1114 using NumberFormat::parse;
jpayne@69 1115
jpayne@69 1116 /**
jpayne@69 1117 * Parse the given string using this object's choices. The method
jpayne@69 1118 * does string comparisons to try to find an optimal match.
jpayne@69 1119 * If no object can be parsed, index is unchanged, and NULL is
jpayne@69 1120 * returned. The result is returned as the most parsimonious
jpayne@69 1121 * type of Formattable that will accommodate all of the
jpayne@69 1122 * necessary precision. For example, if the result is exactly 12,
jpayne@69 1123 * it will be returned as a long. However, if it is 1.5, it will
jpayne@69 1124 * be returned as a double.
jpayne@69 1125 *
jpayne@69 1126 * @param text The text to be parsed.
jpayne@69 1127 * @param result Formattable to be set to the parse result.
jpayne@69 1128 * If parse fails, return contents are undefined.
jpayne@69 1129 * @param parsePosition The position to start parsing at on input.
jpayne@69 1130 * On output, moved to after the last successfully
jpayne@69 1131 * parse character. On parse failure, does not change.
jpayne@69 1132 * @see Formattable
jpayne@69 1133 * @stable ICU 2.0
jpayne@69 1134 */
jpayne@69 1135 void parse(const UnicodeString& text, Formattable& result,
jpayne@69 1136 ParsePosition& parsePosition) const U_OVERRIDE;
jpayne@69 1137
jpayne@69 1138 /**
jpayne@69 1139 * Parses text from the given string as a currency amount. Unlike
jpayne@69 1140 * the parse() method, this method will attempt to parse a generic
jpayne@69 1141 * currency name, searching for a match of this object's locale's
jpayne@69 1142 * currency display names, or for a 3-letter ISO currency code.
jpayne@69 1143 * This method will fail if this format is not a currency format,
jpayne@69 1144 * that is, if it does not contain the currency pattern symbol
jpayne@69 1145 * (U+00A4) in its prefix or suffix.
jpayne@69 1146 *
jpayne@69 1147 * @param text the string to parse
jpayne@69 1148 * @param pos input-output position; on input, the position within text
jpayne@69 1149 * to match; must have 0 <= pos.getIndex() < text.length();
jpayne@69 1150 * on output, the position after the last matched character.
jpayne@69 1151 * If the parse fails, the position in unchanged upon output.
jpayne@69 1152 * @return if parse succeeds, a pointer to a newly-created CurrencyAmount
jpayne@69 1153 * object (owned by the caller) containing information about
jpayne@69 1154 * the parsed currency; if parse fails, this is NULL.
jpayne@69 1155 * @stable ICU 49
jpayne@69 1156 */
jpayne@69 1157 CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const U_OVERRIDE;
jpayne@69 1158
jpayne@69 1159 /**
jpayne@69 1160 * Returns the decimal format symbols, which is generally not changed
jpayne@69 1161 * by the programmer or user.
jpayne@69 1162 * @return desired DecimalFormatSymbols
jpayne@69 1163 * @see DecimalFormatSymbols
jpayne@69 1164 * @stable ICU 2.0
jpayne@69 1165 */
jpayne@69 1166 virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const;
jpayne@69 1167
jpayne@69 1168 /**
jpayne@69 1169 * Sets the decimal format symbols, which is generally not changed
jpayne@69 1170 * by the programmer or user.
jpayne@69 1171 * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
jpayne@69 1172 * @stable ICU 2.0
jpayne@69 1173 */
jpayne@69 1174 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
jpayne@69 1175
jpayne@69 1176 /**
jpayne@69 1177 * Sets the decimal format symbols, which is generally not changed
jpayne@69 1178 * by the programmer or user.
jpayne@69 1179 * @param symbols DecimalFormatSymbols.
jpayne@69 1180 * @stable ICU 2.0
jpayne@69 1181 */
jpayne@69 1182 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
jpayne@69 1183
jpayne@69 1184
jpayne@69 1185 /**
jpayne@69 1186 * Returns the currency plural format information,
jpayne@69 1187 * which is generally not changed by the programmer or user.
jpayne@69 1188 * @return desired CurrencyPluralInfo
jpayne@69 1189 * @stable ICU 4.2
jpayne@69 1190 */
jpayne@69 1191 virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
jpayne@69 1192
jpayne@69 1193 /**
jpayne@69 1194 * Sets the currency plural format information,
jpayne@69 1195 * which is generally not changed by the programmer or user.
jpayne@69 1196 * @param toAdopt CurrencyPluralInfo to be adopted.
jpayne@69 1197 * @stable ICU 4.2
jpayne@69 1198 */
jpayne@69 1199 virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt);
jpayne@69 1200
jpayne@69 1201 /**
jpayne@69 1202 * Sets the currency plural format information,
jpayne@69 1203 * which is generally not changed by the programmer or user.
jpayne@69 1204 * @param info Currency Plural Info.
jpayne@69 1205 * @stable ICU 4.2
jpayne@69 1206 */
jpayne@69 1207 virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info);
jpayne@69 1208
jpayne@69 1209
jpayne@69 1210 /**
jpayne@69 1211 * Get the positive prefix.
jpayne@69 1212 *
jpayne@69 1213 * @param result Output param which will receive the positive prefix.
jpayne@69 1214 * @return A reference to 'result'.
jpayne@69 1215 * Examples: +123, $123, sFr123
jpayne@69 1216 * @stable ICU 2.0
jpayne@69 1217 */
jpayne@69 1218 UnicodeString& getPositivePrefix(UnicodeString& result) const;
jpayne@69 1219
jpayne@69 1220 /**
jpayne@69 1221 * Set the positive prefix.
jpayne@69 1222 *
jpayne@69 1223 * @param newValue the new value of the the positive prefix to be set.
jpayne@69 1224 * Examples: +123, $123, sFr123
jpayne@69 1225 * @stable ICU 2.0
jpayne@69 1226 */
jpayne@69 1227 virtual void setPositivePrefix(const UnicodeString& newValue);
jpayne@69 1228
jpayne@69 1229 /**
jpayne@69 1230 * Get the negative prefix.
jpayne@69 1231 *
jpayne@69 1232 * @param result Output param which will receive the negative prefix.
jpayne@69 1233 * @return A reference to 'result'.
jpayne@69 1234 * Examples: -123, ($123) (with negative suffix), sFr-123
jpayne@69 1235 * @stable ICU 2.0
jpayne@69 1236 */
jpayne@69 1237 UnicodeString& getNegativePrefix(UnicodeString& result) const;
jpayne@69 1238
jpayne@69 1239 /**
jpayne@69 1240 * Set the negative prefix.
jpayne@69 1241 *
jpayne@69 1242 * @param newValue the new value of the the negative prefix to be set.
jpayne@69 1243 * Examples: -123, ($123) (with negative suffix), sFr-123
jpayne@69 1244 * @stable ICU 2.0
jpayne@69 1245 */
jpayne@69 1246 virtual void setNegativePrefix(const UnicodeString& newValue);
jpayne@69 1247
jpayne@69 1248 /**
jpayne@69 1249 * Get the positive suffix.
jpayne@69 1250 *
jpayne@69 1251 * @param result Output param which will receive the positive suffix.
jpayne@69 1252 * @return A reference to 'result'.
jpayne@69 1253 * Example: 123%
jpayne@69 1254 * @stable ICU 2.0
jpayne@69 1255 */
jpayne@69 1256 UnicodeString& getPositiveSuffix(UnicodeString& result) const;
jpayne@69 1257
jpayne@69 1258 /**
jpayne@69 1259 * Set the positive suffix.
jpayne@69 1260 *
jpayne@69 1261 * @param newValue the new value of the positive suffix to be set.
jpayne@69 1262 * Example: 123%
jpayne@69 1263 * @stable ICU 2.0
jpayne@69 1264 */
jpayne@69 1265 virtual void setPositiveSuffix(const UnicodeString& newValue);
jpayne@69 1266
jpayne@69 1267 /**
jpayne@69 1268 * Get the negative suffix.
jpayne@69 1269 *
jpayne@69 1270 * @param result Output param which will receive the negative suffix.
jpayne@69 1271 * @return A reference to 'result'.
jpayne@69 1272 * Examples: -123%, ($123) (with positive suffixes)
jpayne@69 1273 * @stable ICU 2.0
jpayne@69 1274 */
jpayne@69 1275 UnicodeString& getNegativeSuffix(UnicodeString& result) const;
jpayne@69 1276
jpayne@69 1277 /**
jpayne@69 1278 * Set the negative suffix.
jpayne@69 1279 *
jpayne@69 1280 * @param newValue the new value of the negative suffix to be set.
jpayne@69 1281 * Examples: 123%
jpayne@69 1282 * @stable ICU 2.0
jpayne@69 1283 */
jpayne@69 1284 virtual void setNegativeSuffix(const UnicodeString& newValue);
jpayne@69 1285
jpayne@69 1286 /**
jpayne@69 1287 * Whether to show the plus sign on positive (non-negative) numbers; for example, "+12"
jpayne@69 1288 *
jpayne@69 1289 * For more control over sign display, use NumberFormatter.
jpayne@69 1290 *
jpayne@69 1291 * @return Whether the sign is shown on positive numbers and zero.
jpayne@69 1292 * @stable ICU 64
jpayne@69 1293 */
jpayne@69 1294 UBool isSignAlwaysShown() const;
jpayne@69 1295
jpayne@69 1296 /**
jpayne@69 1297 * Set whether to show the plus sign on positive (non-negative) numbers; for example, "+12".
jpayne@69 1298 *
jpayne@69 1299 * For more control over sign display, use NumberFormatter.
jpayne@69 1300 *
jpayne@69 1301 * @param value true to always show a sign; false to hide the sign on positive numbers and zero.
jpayne@69 1302 * @stable ICU 64
jpayne@69 1303 */
jpayne@69 1304 void setSignAlwaysShown(UBool value);
jpayne@69 1305
jpayne@69 1306 /**
jpayne@69 1307 * Get the multiplier for use in percent, permill, etc.
jpayne@69 1308 * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
jpayne@69 1309 * (For Arabic, use arabic percent symbol).
jpayne@69 1310 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
jpayne@69 1311 *
jpayne@69 1312 * The number may also be multiplied by a power of ten; see getMultiplierScale().
jpayne@69 1313 *
jpayne@69 1314 * @return the multiplier for use in percent, permill, etc.
jpayne@69 1315 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
jpayne@69 1316 * @stable ICU 2.0
jpayne@69 1317 */
jpayne@69 1318 int32_t getMultiplier(void) const;
jpayne@69 1319
jpayne@69 1320 /**
jpayne@69 1321 * Set the multiplier for use in percent, permill, etc.
jpayne@69 1322 * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
jpayne@69 1323 * (For Arabic, use arabic percent symbol).
jpayne@69 1324 * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
jpayne@69 1325 *
jpayne@69 1326 * This method only supports integer multipliers. To multiply by a non-integer, pair this
jpayne@69 1327 * method with setMultiplierScale().
jpayne@69 1328 *
jpayne@69 1329 * @param newValue the new value of the multiplier for use in percent, permill, etc.
jpayne@69 1330 * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
jpayne@69 1331 * @stable ICU 2.0
jpayne@69 1332 */
jpayne@69 1333 virtual void setMultiplier(int32_t newValue);
jpayne@69 1334
jpayne@69 1335 /**
jpayne@69 1336 * Gets the power of ten by which number should be multiplied before formatting, which
jpayne@69 1337 * can be combined with setMultiplier() to multiply by any arbitrary decimal value.
jpayne@69 1338 *
jpayne@69 1339 * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale
jpayne@69 1340 * of -2 corresponds to multiplication by 0.01.
jpayne@69 1341 *
jpayne@69 1342 * This method is analogous to UNUM_SCALE in getAttribute.
jpayne@69 1343 *
jpayne@69 1344 * @return the current value of the power-of-ten multiplier.
jpayne@69 1345 * @stable ICU 62
jpayne@69 1346 */
jpayne@69 1347 int32_t getMultiplierScale(void) const;
jpayne@69 1348
jpayne@69 1349 /**
jpayne@69 1350 * Sets a power of ten by which number should be multiplied before formatting, which
jpayne@69 1351 * can be combined with setMultiplier() to multiply by any arbitrary decimal value.
jpayne@69 1352 *
jpayne@69 1353 * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale
jpayne@69 1354 * of -2 corresponds to multiplication by 0.01.
jpayne@69 1355 *
jpayne@69 1356 * For example, to multiply numbers by 0.5 before formatting, you can do:
jpayne@69 1357 *
jpayne@69 1358 * <pre>
jpayne@69 1359 * df.setMultiplier(5);
jpayne@69 1360 * df.setMultiplierScale(-1);
jpayne@69 1361 * </pre>
jpayne@69 1362 *
jpayne@69 1363 * This method is analogous to UNUM_SCALE in setAttribute.
jpayne@69 1364 *
jpayne@69 1365 * @param newValue the new value of the power-of-ten multiplier.
jpayne@69 1366 * @stable ICU 62
jpayne@69 1367 */
jpayne@69 1368 void setMultiplierScale(int32_t newValue);
jpayne@69 1369
jpayne@69 1370 /**
jpayne@69 1371 * Get the rounding increment.
jpayne@69 1372 * @return A positive rounding increment, or 0.0 if a custom rounding
jpayne@69 1373 * increment is not in effect.
jpayne@69 1374 * @see #setRoundingIncrement
jpayne@69 1375 * @see #getRoundingMode
jpayne@69 1376 * @see #setRoundingMode
jpayne@69 1377 * @stable ICU 2.0
jpayne@69 1378 */
jpayne@69 1379 virtual double getRoundingIncrement(void) const;
jpayne@69 1380
jpayne@69 1381 /**
jpayne@69 1382 * Set the rounding increment. In the absence of a rounding increment,
jpayne@69 1383 * numbers will be rounded to the number of digits displayed.
jpayne@69 1384 * @param newValue A positive rounding increment, or 0.0 to
jpayne@69 1385 * use the default rounding increment.
jpayne@69 1386 * Negative increments are equivalent to 0.0.
jpayne@69 1387 * @see #getRoundingIncrement
jpayne@69 1388 * @see #getRoundingMode
jpayne@69 1389 * @see #setRoundingMode
jpayne@69 1390 * @stable ICU 2.0
jpayne@69 1391 */
jpayne@69 1392 virtual void setRoundingIncrement(double newValue);
jpayne@69 1393
jpayne@69 1394 /**
jpayne@69 1395 * Get the rounding mode.
jpayne@69 1396 * @return A rounding mode
jpayne@69 1397 * @see #setRoundingIncrement
jpayne@69 1398 * @see #getRoundingIncrement
jpayne@69 1399 * @see #setRoundingMode
jpayne@69 1400 * @stable ICU 2.0
jpayne@69 1401 */
jpayne@69 1402 virtual ERoundingMode getRoundingMode(void) const U_OVERRIDE;
jpayne@69 1403
jpayne@69 1404 /**
jpayne@69 1405 * Set the rounding mode.
jpayne@69 1406 * @param roundingMode A rounding mode
jpayne@69 1407 * @see #setRoundingIncrement
jpayne@69 1408 * @see #getRoundingIncrement
jpayne@69 1409 * @see #getRoundingMode
jpayne@69 1410 * @stable ICU 2.0
jpayne@69 1411 */
jpayne@69 1412 virtual void setRoundingMode(ERoundingMode roundingMode) U_OVERRIDE;
jpayne@69 1413
jpayne@69 1414 /**
jpayne@69 1415 * Get the width to which the output of format() is padded.
jpayne@69 1416 * The width is counted in 16-bit code units.
jpayne@69 1417 * @return the format width, or zero if no padding is in effect
jpayne@69 1418 * @see #setFormatWidth
jpayne@69 1419 * @see #getPadCharacterString
jpayne@69 1420 * @see #setPadCharacter
jpayne@69 1421 * @see #getPadPosition
jpayne@69 1422 * @see #setPadPosition
jpayne@69 1423 * @stable ICU 2.0
jpayne@69 1424 */
jpayne@69 1425 virtual int32_t getFormatWidth(void) const;
jpayne@69 1426
jpayne@69 1427 /**
jpayne@69 1428 * Set the width to which the output of format() is padded.
jpayne@69 1429 * The width is counted in 16-bit code units.
jpayne@69 1430 * This method also controls whether padding is enabled.
jpayne@69 1431 * @param width the width to which to pad the result of
jpayne@69 1432 * format(), or zero to disable padding. A negative
jpayne@69 1433 * width is equivalent to 0.
jpayne@69 1434 * @see #getFormatWidth
jpayne@69 1435 * @see #getPadCharacterString
jpayne@69 1436 * @see #setPadCharacter
jpayne@69 1437 * @see #getPadPosition
jpayne@69 1438 * @see #setPadPosition
jpayne@69 1439 * @stable ICU 2.0
jpayne@69 1440 */
jpayne@69 1441 virtual void setFormatWidth(int32_t width);
jpayne@69 1442
jpayne@69 1443 /**
jpayne@69 1444 * Get the pad character used to pad to the format width. The
jpayne@69 1445 * default is ' '.
jpayne@69 1446 * @return a string containing the pad character. This will always
jpayne@69 1447 * have a length of one 32-bit code point.
jpayne@69 1448 * @see #setFormatWidth
jpayne@69 1449 * @see #getFormatWidth
jpayne@69 1450 * @see #setPadCharacter
jpayne@69 1451 * @see #getPadPosition
jpayne@69 1452 * @see #setPadPosition
jpayne@69 1453 * @stable ICU 2.0
jpayne@69 1454 */
jpayne@69 1455 virtual UnicodeString getPadCharacterString() const;
jpayne@69 1456
jpayne@69 1457 /**
jpayne@69 1458 * Set the character used to pad to the format width. If padding
jpayne@69 1459 * is not enabled, then this will take effect if padding is later
jpayne@69 1460 * enabled.
jpayne@69 1461 * @param padChar a string containing the pad character. If the string
jpayne@69 1462 * has length 0, then the pad character is set to ' '. Otherwise
jpayne@69 1463 * padChar.char32At(0) will be used as the pad character.
jpayne@69 1464 * @see #setFormatWidth
jpayne@69 1465 * @see #getFormatWidth
jpayne@69 1466 * @see #getPadCharacterString
jpayne@69 1467 * @see #getPadPosition
jpayne@69 1468 * @see #setPadPosition
jpayne@69 1469 * @stable ICU 2.0
jpayne@69 1470 */
jpayne@69 1471 virtual void setPadCharacter(const UnicodeString& padChar);
jpayne@69 1472
jpayne@69 1473 /**
jpayne@69 1474 * Get the position at which padding will take place. This is the location
jpayne@69 1475 * at which padding will be inserted if the result of format()
jpayne@69 1476 * is shorter than the format width.
jpayne@69 1477 * @return the pad position, one of kPadBeforePrefix,
jpayne@69 1478 * kPadAfterPrefix, kPadBeforeSuffix, or
jpayne@69 1479 * kPadAfterSuffix.
jpayne@69 1480 * @see #setFormatWidth
jpayne@69 1481 * @see #getFormatWidth
jpayne@69 1482 * @see #setPadCharacter
jpayne@69 1483 * @see #getPadCharacterString
jpayne@69 1484 * @see #setPadPosition
jpayne@69 1485 * @see #EPadPosition
jpayne@69 1486 * @stable ICU 2.0
jpayne@69 1487 */
jpayne@69 1488 virtual EPadPosition getPadPosition(void) const;
jpayne@69 1489
jpayne@69 1490 /**
jpayne@69 1491 * Set the position at which padding will take place. This is the location
jpayne@69 1492 * at which padding will be inserted if the result of format()
jpayne@69 1493 * is shorter than the format width. This has no effect unless padding is
jpayne@69 1494 * enabled.
jpayne@69 1495 * @param padPos the pad position, one of kPadBeforePrefix,
jpayne@69 1496 * kPadAfterPrefix, kPadBeforeSuffix, or
jpayne@69 1497 * kPadAfterSuffix.
jpayne@69 1498 * @see #setFormatWidth
jpayne@69 1499 * @see #getFormatWidth
jpayne@69 1500 * @see #setPadCharacter
jpayne@69 1501 * @see #getPadCharacterString
jpayne@69 1502 * @see #getPadPosition
jpayne@69 1503 * @see #EPadPosition
jpayne@69 1504 * @stable ICU 2.0
jpayne@69 1505 */
jpayne@69 1506 virtual void setPadPosition(EPadPosition padPos);
jpayne@69 1507
jpayne@69 1508 /**
jpayne@69 1509 * Return whether or not scientific notation is used.
jpayne@69 1510 * @return TRUE if this object formats and parses scientific notation
jpayne@69 1511 * @see #setScientificNotation
jpayne@69 1512 * @see #getMinimumExponentDigits
jpayne@69 1513 * @see #setMinimumExponentDigits
jpayne@69 1514 * @see #isExponentSignAlwaysShown
jpayne@69 1515 * @see #setExponentSignAlwaysShown
jpayne@69 1516 * @stable ICU 2.0
jpayne@69 1517 */
jpayne@69 1518 virtual UBool isScientificNotation(void) const;
jpayne@69 1519
jpayne@69 1520 /**
jpayne@69 1521 * Set whether or not scientific notation is used. When scientific notation
jpayne@69 1522 * is used, the effective maximum number of integer digits is <= 8. If the
jpayne@69 1523 * maximum number of integer digits is set to more than 8, the effective
jpayne@69 1524 * maximum will be 1. This allows this call to generate a 'default' scientific
jpayne@69 1525 * number format without additional changes.
jpayne@69 1526 * @param useScientific TRUE if this object formats and parses scientific
jpayne@69 1527 * notation
jpayne@69 1528 * @see #isScientificNotation
jpayne@69 1529 * @see #getMinimumExponentDigits
jpayne@69 1530 * @see #setMinimumExponentDigits
jpayne@69 1531 * @see #isExponentSignAlwaysShown
jpayne@69 1532 * @see #setExponentSignAlwaysShown
jpayne@69 1533 * @stable ICU 2.0
jpayne@69 1534 */
jpayne@69 1535 virtual void setScientificNotation(UBool useScientific);
jpayne@69 1536
jpayne@69 1537 /**
jpayne@69 1538 * Return the minimum exponent digits that will be shown.
jpayne@69 1539 * @return the minimum exponent digits that will be shown
jpayne@69 1540 * @see #setScientificNotation
jpayne@69 1541 * @see #isScientificNotation
jpayne@69 1542 * @see #setMinimumExponentDigits
jpayne@69 1543 * @see #isExponentSignAlwaysShown
jpayne@69 1544 * @see #setExponentSignAlwaysShown
jpayne@69 1545 * @stable ICU 2.0
jpayne@69 1546 */
jpayne@69 1547 virtual int8_t getMinimumExponentDigits(void) const;
jpayne@69 1548
jpayne@69 1549 /**
jpayne@69 1550 * Set the minimum exponent digits that will be shown. This has no
jpayne@69 1551 * effect unless scientific notation is in use.
jpayne@69 1552 * @param minExpDig a value >= 1 indicating the fewest exponent digits
jpayne@69 1553 * that will be shown. Values less than 1 will be treated as 1.
jpayne@69 1554 * @see #setScientificNotation
jpayne@69 1555 * @see #isScientificNotation
jpayne@69 1556 * @see #getMinimumExponentDigits
jpayne@69 1557 * @see #isExponentSignAlwaysShown
jpayne@69 1558 * @see #setExponentSignAlwaysShown
jpayne@69 1559 * @stable ICU 2.0
jpayne@69 1560 */
jpayne@69 1561 virtual void setMinimumExponentDigits(int8_t minExpDig);
jpayne@69 1562
jpayne@69 1563 /**
jpayne@69 1564 * Return whether the exponent sign is always shown.
jpayne@69 1565 * @return TRUE if the exponent is always prefixed with either the
jpayne@69 1566 * localized minus sign or the localized plus sign, false if only negative
jpayne@69 1567 * exponents are prefixed with the localized minus sign.
jpayne@69 1568 * @see #setScientificNotation
jpayne@69 1569 * @see #isScientificNotation
jpayne@69 1570 * @see #setMinimumExponentDigits
jpayne@69 1571 * @see #getMinimumExponentDigits
jpayne@69 1572 * @see #setExponentSignAlwaysShown
jpayne@69 1573 * @stable ICU 2.0
jpayne@69 1574 */
jpayne@69 1575 virtual UBool isExponentSignAlwaysShown(void) const;
jpayne@69 1576
jpayne@69 1577 /**
jpayne@69 1578 * Set whether the exponent sign is always shown. This has no effect
jpayne@69 1579 * unless scientific notation is in use.
jpayne@69 1580 * @param expSignAlways TRUE if the exponent is always prefixed with either
jpayne@69 1581 * the localized minus sign or the localized plus sign, false if only
jpayne@69 1582 * negative exponents are prefixed with the localized minus sign.
jpayne@69 1583 * @see #setScientificNotation
jpayne@69 1584 * @see #isScientificNotation
jpayne@69 1585 * @see #setMinimumExponentDigits
jpayne@69 1586 * @see #getMinimumExponentDigits
jpayne@69 1587 * @see #isExponentSignAlwaysShown
jpayne@69 1588 * @stable ICU 2.0
jpayne@69 1589 */
jpayne@69 1590 virtual void setExponentSignAlwaysShown(UBool expSignAlways);
jpayne@69 1591
jpayne@69 1592 /**
jpayne@69 1593 * Return the grouping size. Grouping size is the number of digits between
jpayne@69 1594 * grouping separators in the integer portion of a number. For example,
jpayne@69 1595 * in the number "123,456.78", the grouping size is 3.
jpayne@69 1596 *
jpayne@69 1597 * @return the grouping size.
jpayne@69 1598 * @see setGroupingSize
jpayne@69 1599 * @see NumberFormat::isGroupingUsed
jpayne@69 1600 * @see DecimalFormatSymbols::getGroupingSeparator
jpayne@69 1601 * @stable ICU 2.0
jpayne@69 1602 */
jpayne@69 1603 int32_t getGroupingSize(void) const;
jpayne@69 1604
jpayne@69 1605 /**
jpayne@69 1606 * Set the grouping size. Grouping size is the number of digits between
jpayne@69 1607 * grouping separators in the integer portion of a number. For example,
jpayne@69 1608 * in the number "123,456.78", the grouping size is 3.
jpayne@69 1609 *
jpayne@69 1610 * @param newValue the new value of the grouping size.
jpayne@69 1611 * @see getGroupingSize
jpayne@69 1612 * @see NumberFormat::setGroupingUsed
jpayne@69 1613 * @see DecimalFormatSymbols::setGroupingSeparator
jpayne@69 1614 * @stable ICU 2.0
jpayne@69 1615 */
jpayne@69 1616 virtual void setGroupingSize(int32_t newValue);
jpayne@69 1617
jpayne@69 1618 /**
jpayne@69 1619 * Return the secondary grouping size. In some locales one
jpayne@69 1620 * grouping interval is used for the least significant integer
jpayne@69 1621 * digits (the primary grouping size), and another is used for all
jpayne@69 1622 * others (the secondary grouping size). A formatter supporting a
jpayne@69 1623 * secondary grouping size will return a positive integer unequal
jpayne@69 1624 * to the primary grouping size returned by
jpayne@69 1625 * getGroupingSize(). For example, if the primary
jpayne@69 1626 * grouping size is 4, and the secondary grouping size is 2, then
jpayne@69 1627 * the number 123456789 formats as "1,23,45,6789", and the pattern
jpayne@69 1628 * appears as "#,##,###0".
jpayne@69 1629 * @return the secondary grouping size, or a value less than
jpayne@69 1630 * one if there is none
jpayne@69 1631 * @see setSecondaryGroupingSize
jpayne@69 1632 * @see NumberFormat::isGroupingUsed
jpayne@69 1633 * @see DecimalFormatSymbols::getGroupingSeparator
jpayne@69 1634 * @stable ICU 2.4
jpayne@69 1635 */
jpayne@69 1636 int32_t getSecondaryGroupingSize(void) const;
jpayne@69 1637
jpayne@69 1638 /**
jpayne@69 1639 * Set the secondary grouping size. If set to a value less than 1,
jpayne@69 1640 * then secondary grouping is turned off, and the primary grouping
jpayne@69 1641 * size is used for all intervals, not just the least significant.
jpayne@69 1642 *
jpayne@69 1643 * @param newValue the new value of the secondary grouping size.
jpayne@69 1644 * @see getSecondaryGroupingSize
jpayne@69 1645 * @see NumberFormat#setGroupingUsed
jpayne@69 1646 * @see DecimalFormatSymbols::setGroupingSeparator
jpayne@69 1647 * @stable ICU 2.4
jpayne@69 1648 */
jpayne@69 1649 virtual void setSecondaryGroupingSize(int32_t newValue);
jpayne@69 1650
jpayne@69 1651 /**
jpayne@69 1652 * Returns the minimum number of grouping digits.
jpayne@69 1653 * Grouping separators are output if there are at least this many
jpayne@69 1654 * digits to the left of the first (rightmost) grouping separator,
jpayne@69 1655 * that is, there are at least (minimum grouping + grouping size) integer digits.
jpayne@69 1656 * (Subject to isGroupingUsed().)
jpayne@69 1657 *
jpayne@69 1658 * For example, if this value is 2, and the grouping size is 3, then
jpayne@69 1659 * 9999 -> "9999" and 10000 -> "10,000"
jpayne@69 1660 *
jpayne@69 1661 * The default value for this attribute is 0.
jpayne@69 1662 * A value of 1, 0, or lower, means that the use of grouping separators
jpayne@69 1663 * only depends on the grouping size (and on isGroupingUsed()).
jpayne@69 1664 *
jpayne@69 1665 * NOTE: The CLDR data is used in NumberFormatter but not in DecimalFormat.
jpayne@69 1666 * This is for backwards compatibility reasons.
jpayne@69 1667 *
jpayne@69 1668 * For more control over grouping strategies, use NumberFormatter.
jpayne@69 1669 *
jpayne@69 1670 * @see setMinimumGroupingDigits
jpayne@69 1671 * @see getGroupingSize
jpayne@69 1672 * @stable ICU 64
jpayne@69 1673 */
jpayne@69 1674 int32_t getMinimumGroupingDigits() const;
jpayne@69 1675
jpayne@69 1676 /**
jpayne@69 1677 * Sets the minimum grouping digits. Setting to a value less than or
jpayne@69 1678 * equal to 1 turns off minimum grouping digits.
jpayne@69 1679 *
jpayne@69 1680 * For more control over grouping strategies, use NumberFormatter.
jpayne@69 1681 *
jpayne@69 1682 * @param newValue the new value of minimum grouping digits.
jpayne@69 1683 * @see getMinimumGroupingDigits
jpayne@69 1684 * @stable ICU 64
jpayne@69 1685 */
jpayne@69 1686 void setMinimumGroupingDigits(int32_t newValue);
jpayne@69 1687
jpayne@69 1688 /**
jpayne@69 1689 * Allows you to get the behavior of the decimal separator with integers.
jpayne@69 1690 * (The decimal separator will always appear with decimals.)
jpayne@69 1691 *
jpayne@69 1692 * @return TRUE if the decimal separator always appear with decimals.
jpayne@69 1693 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
jpayne@69 1694 * @stable ICU 2.0
jpayne@69 1695 */
jpayne@69 1696 UBool isDecimalSeparatorAlwaysShown(void) const;
jpayne@69 1697
jpayne@69 1698 /**
jpayne@69 1699 * Allows you to set the behavior of the decimal separator with integers.
jpayne@69 1700 * (The decimal separator will always appear with decimals.)
jpayne@69 1701 *
jpayne@69 1702 * @param newValue set TRUE if the decimal separator will always appear with decimals.
jpayne@69 1703 * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
jpayne@69 1704 * @stable ICU 2.0
jpayne@69 1705 */
jpayne@69 1706 virtual void setDecimalSeparatorAlwaysShown(UBool newValue);
jpayne@69 1707
jpayne@69 1708 /**
jpayne@69 1709 * Allows you to get the parse behavior of the pattern decimal mark.
jpayne@69 1710 *
jpayne@69 1711 * @return TRUE if input must contain a match to decimal mark in pattern
jpayne@69 1712 * @stable ICU 54
jpayne@69 1713 */
jpayne@69 1714 UBool isDecimalPatternMatchRequired(void) const;
jpayne@69 1715
jpayne@69 1716 /**
jpayne@69 1717 * Allows you to set the parse behavior of the pattern decimal mark.
jpayne@69 1718 *
jpayne@69 1719 * if TRUE, the input must have a decimal mark if one was specified in the pattern. When
jpayne@69 1720 * FALSE the decimal mark may be omitted from the input.
jpayne@69 1721 *
jpayne@69 1722 * @param newValue set TRUE if input must contain a match to decimal mark in pattern
jpayne@69 1723 * @stable ICU 54
jpayne@69 1724 */
jpayne@69 1725 virtual void setDecimalPatternMatchRequired(UBool newValue);
jpayne@69 1726
jpayne@69 1727 /**
jpayne@69 1728 * Returns whether to ignore exponents when parsing.
jpayne@69 1729 *
jpayne@69 1730 * @return Whether to ignore exponents when parsing.
jpayne@69 1731 * @see #setParseNoExponent
jpayne@69 1732 * @stable ICU 64
jpayne@69 1733 */
jpayne@69 1734 UBool isParseNoExponent() const;
jpayne@69 1735
jpayne@69 1736 /**
jpayne@69 1737 * Specifies whether to stop parsing when an exponent separator is encountered. For
jpayne@69 1738 * example, parses "123E4" to 123 (with parse position 3) instead of 1230000 (with parse position
jpayne@69 1739 * 5).
jpayne@69 1740 *
jpayne@69 1741 * @param value true to prevent exponents from being parsed; false to allow them to be parsed.
jpayne@69 1742 * @stable ICU 64
jpayne@69 1743 */
jpayne@69 1744 void setParseNoExponent(UBool value);
jpayne@69 1745
jpayne@69 1746 /**
jpayne@69 1747 * Returns whether parsing is sensitive to case (lowercase/uppercase).
jpayne@69 1748 *
jpayne@69 1749 * @return Whether parsing is case-sensitive.
jpayne@69 1750 * @see #setParseCaseSensitive
jpayne@69 1751 * @stable ICU 64
jpayne@69 1752 */
jpayne@69 1753 UBool isParseCaseSensitive() const;
jpayne@69 1754
jpayne@69 1755 /**
jpayne@69 1756 * Whether to pay attention to case when parsing; default is to ignore case (perform
jpayne@69 1757 * case-folding). For example, "A" == "a" in case-insensitive but not case-sensitive mode.
jpayne@69 1758 *
jpayne@69 1759 * Currency symbols are never case-folded. For example, "us$1.00" will not parse in case-insensitive
jpayne@69 1760 * mode, even though "US$1.00" parses.
jpayne@69 1761 *
jpayne@69 1762 * @param value true to enable case-sensitive parsing (the default); false to force
jpayne@69 1763 * case-sensitive parsing behavior.
jpayne@69 1764 * @stable ICU 64
jpayne@69 1765 */
jpayne@69 1766 void setParseCaseSensitive(UBool value);
jpayne@69 1767
jpayne@69 1768 /**
jpayne@69 1769 * Returns whether truncation of high-order integer digits should result in an error.
jpayne@69 1770 * By default, setMaximumIntegerDigits truncates high-order digits silently.
jpayne@69 1771 *
jpayne@69 1772 * @return Whether an error code is set if high-order digits are truncated.
jpayne@69 1773 * @see setFormatFailIfMoreThanMaxDigits
jpayne@69 1774 * @stable ICU 64
jpayne@69 1775 */
jpayne@69 1776 UBool isFormatFailIfMoreThanMaxDigits() const;
jpayne@69 1777
jpayne@69 1778 /**
jpayne@69 1779 * Sets whether truncation of high-order integer digits should result in an error.
jpayne@69 1780 * By default, setMaximumIntegerDigits truncates high-order digits silently.
jpayne@69 1781 *
jpayne@69 1782 * @param value Whether to set an error code if high-order digits are truncated.
jpayne@69 1783 * @stable ICU 64
jpayne@69 1784 */
jpayne@69 1785 void setFormatFailIfMoreThanMaxDigits(UBool value);
jpayne@69 1786
jpayne@69 1787 /**
jpayne@69 1788 * Synthesizes a pattern string that represents the current state
jpayne@69 1789 * of this Format object.
jpayne@69 1790 *
jpayne@69 1791 * @param result Output param which will receive the pattern.
jpayne@69 1792 * Previous contents are deleted.
jpayne@69 1793 * @return A reference to 'result'.
jpayne@69 1794 * @see applyPattern
jpayne@69 1795 * @stable ICU 2.0
jpayne@69 1796 */
jpayne@69 1797 virtual UnicodeString& toPattern(UnicodeString& result) const;
jpayne@69 1798
jpayne@69 1799 /**
jpayne@69 1800 * Synthesizes a localized pattern string that represents the current
jpayne@69 1801 * state of this Format object.
jpayne@69 1802 *
jpayne@69 1803 * @param result Output param which will receive the localized pattern.
jpayne@69 1804 * Previous contents are deleted.
jpayne@69 1805 * @return A reference to 'result'.
jpayne@69 1806 * @see applyPattern
jpayne@69 1807 * @stable ICU 2.0
jpayne@69 1808 */
jpayne@69 1809 virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
jpayne@69 1810
jpayne@69 1811 /**
jpayne@69 1812 * Apply the given pattern to this Format object. A pattern is a
jpayne@69 1813 * short-hand specification for the various formatting properties.
jpayne@69 1814 * These properties can also be changed individually through the
jpayne@69 1815 * various setter methods.
jpayne@69 1816 * <P>
jpayne@69 1817 * There is no limit to integer digits are set
jpayne@69 1818 * by this routine, since that is the typical end-user desire;
jpayne@69 1819 * use setMaximumInteger if you want to set a real value.
jpayne@69 1820 * For negative numbers, use a second pattern, separated by a semicolon
jpayne@69 1821 * <pre>
jpayne@69 1822 * . Example "#,#00.0#" -> 1,234.56
jpayne@69 1823 * </pre>
jpayne@69 1824 * This means a minimum of 2 integer digits, 1 fraction digit, and
jpayne@69 1825 * a maximum of 2 fraction digits.
jpayne@69 1826 * <pre>
jpayne@69 1827 * . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
jpayne@69 1828 * </pre>
jpayne@69 1829 * In negative patterns, the minimum and maximum counts are ignored;
jpayne@69 1830 * these are presumed to be set in the positive pattern.
jpayne@69 1831 *
jpayne@69 1832 * @param pattern The pattern to be applied.
jpayne@69 1833 * @param parseError Struct to recieve information on position
jpayne@69 1834 * of error if an error is encountered
jpayne@69 1835 * @param status Output param set to success/failure code on
jpayne@69 1836 * exit. If the pattern is invalid, this will be
jpayne@69 1837 * set to a failure result.
jpayne@69 1838 * @stable ICU 2.0
jpayne@69 1839 */
jpayne@69 1840 virtual void applyPattern(const UnicodeString& pattern, UParseError& parseError, UErrorCode& status);
jpayne@69 1841
jpayne@69 1842 /**
jpayne@69 1843 * Sets the pattern.
jpayne@69 1844 * @param pattern The pattern to be applied.
jpayne@69 1845 * @param status Output param set to success/failure code on
jpayne@69 1846 * exit. If the pattern is invalid, this will be
jpayne@69 1847 * set to a failure result.
jpayne@69 1848 * @stable ICU 2.0
jpayne@69 1849 */
jpayne@69 1850 virtual void applyPattern(const UnicodeString& pattern, UErrorCode& status);
jpayne@69 1851
jpayne@69 1852 /**
jpayne@69 1853 * Apply the given pattern to this Format object. The pattern
jpayne@69 1854 * is assumed to be in a localized notation. A pattern is a
jpayne@69 1855 * short-hand specification for the various formatting properties.
jpayne@69 1856 * These properties can also be changed individually through the
jpayne@69 1857 * various setter methods.
jpayne@69 1858 * <P>
jpayne@69 1859 * There is no limit to integer digits are set
jpayne@69 1860 * by this routine, since that is the typical end-user desire;
jpayne@69 1861 * use setMaximumInteger if you want to set a real value.
jpayne@69 1862 * For negative numbers, use a second pattern, separated by a semicolon
jpayne@69 1863 * <pre>
jpayne@69 1864 * . Example "#,#00.0#" -> 1,234.56
jpayne@69 1865 * </pre>
jpayne@69 1866 * This means a minimum of 2 integer digits, 1 fraction digit, and
jpayne@69 1867 * a maximum of 2 fraction digits.
jpayne@69 1868 *
jpayne@69 1869 * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
jpayne@69 1870 *
jpayne@69 1871 * In negative patterns, the minimum and maximum counts are ignored;
jpayne@69 1872 * these are presumed to be set in the positive pattern.
jpayne@69 1873 *
jpayne@69 1874 * @param pattern The localized pattern to be applied.
jpayne@69 1875 * @param parseError Struct to recieve information on position
jpayne@69 1876 * of error if an error is encountered
jpayne@69 1877 * @param status Output param set to success/failure code on
jpayne@69 1878 * exit. If the pattern is invalid, this will be
jpayne@69 1879 * set to a failure result.
jpayne@69 1880 * @stable ICU 2.0
jpayne@69 1881 */
jpayne@69 1882 virtual void applyLocalizedPattern(const UnicodeString& pattern, UParseError& parseError,
jpayne@69 1883 UErrorCode& status);
jpayne@69 1884
jpayne@69 1885 /**
jpayne@69 1886 * Apply the given pattern to this Format object.
jpayne@69 1887 *
jpayne@69 1888 * @param pattern The localized pattern to be applied.
jpayne@69 1889 * @param status Output param set to success/failure code on
jpayne@69 1890 * exit. If the pattern is invalid, this will be
jpayne@69 1891 * set to a failure result.
jpayne@69 1892 * @stable ICU 2.0
jpayne@69 1893 */
jpayne@69 1894 virtual void applyLocalizedPattern(const UnicodeString& pattern, UErrorCode& status);
jpayne@69 1895
jpayne@69 1896
jpayne@69 1897 /**
jpayne@69 1898 * Sets the maximum number of digits allowed in the integer portion of a
jpayne@69 1899 * number. This override limits the integer digit count to 309.
jpayne@69 1900 *
jpayne@69 1901 * @param newValue the new value of the maximum number of digits
jpayne@69 1902 * allowed in the integer portion of a number.
jpayne@69 1903 * @see NumberFormat#setMaximumIntegerDigits
jpayne@69 1904 * @stable ICU 2.0
jpayne@69 1905 */
jpayne@69 1906 void setMaximumIntegerDigits(int32_t newValue) U_OVERRIDE;
jpayne@69 1907
jpayne@69 1908 /**
jpayne@69 1909 * Sets the minimum number of digits allowed in the integer portion of a
jpayne@69 1910 * number. This override limits the integer digit count to 309.
jpayne@69 1911 *
jpayne@69 1912 * @param newValue the new value of the minimum number of digits
jpayne@69 1913 * allowed in the integer portion of a number.
jpayne@69 1914 * @see NumberFormat#setMinimumIntegerDigits
jpayne@69 1915 * @stable ICU 2.0
jpayne@69 1916 */
jpayne@69 1917 void setMinimumIntegerDigits(int32_t newValue) U_OVERRIDE;
jpayne@69 1918
jpayne@69 1919 /**
jpayne@69 1920 * Sets the maximum number of digits allowed in the fraction portion of a
jpayne@69 1921 * number. This override limits the fraction digit count to 340.
jpayne@69 1922 *
jpayne@69 1923 * @param newValue the new value of the maximum number of digits
jpayne@69 1924 * allowed in the fraction portion of a number.
jpayne@69 1925 * @see NumberFormat#setMaximumFractionDigits
jpayne@69 1926 * @stable ICU 2.0
jpayne@69 1927 */
jpayne@69 1928 void setMaximumFractionDigits(int32_t newValue) U_OVERRIDE;
jpayne@69 1929
jpayne@69 1930 /**
jpayne@69 1931 * Sets the minimum number of digits allowed in the fraction portion of a
jpayne@69 1932 * number. This override limits the fraction digit count to 340.
jpayne@69 1933 *
jpayne@69 1934 * @param newValue the new value of the minimum number of digits
jpayne@69 1935 * allowed in the fraction portion of a number.
jpayne@69 1936 * @see NumberFormat#setMinimumFractionDigits
jpayne@69 1937 * @stable ICU 2.0
jpayne@69 1938 */
jpayne@69 1939 void setMinimumFractionDigits(int32_t newValue) U_OVERRIDE;
jpayne@69 1940
jpayne@69 1941 /**
jpayne@69 1942 * Returns the minimum number of significant digits that will be
jpayne@69 1943 * displayed. This value has no effect unless areSignificantDigitsUsed()
jpayne@69 1944 * returns true.
jpayne@69 1945 * @return the fewest significant digits that will be shown
jpayne@69 1946 * @stable ICU 3.0
jpayne@69 1947 */
jpayne@69 1948 int32_t getMinimumSignificantDigits() const;
jpayne@69 1949
jpayne@69 1950 /**
jpayne@69 1951 * Returns the maximum number of significant digits that will be
jpayne@69 1952 * displayed. This value has no effect unless areSignificantDigitsUsed()
jpayne@69 1953 * returns true.
jpayne@69 1954 * @return the most significant digits that will be shown
jpayne@69 1955 * @stable ICU 3.0
jpayne@69 1956 */
jpayne@69 1957 int32_t getMaximumSignificantDigits() const;
jpayne@69 1958
jpayne@69 1959 /**
jpayne@69 1960 * Sets the minimum number of significant digits that will be
jpayne@69 1961 * displayed. If <code>min</code> is less than one then it is set
jpayne@69 1962 * to one. If the maximum significant digits count is less than
jpayne@69 1963 * <code>min</code>, then it is set to <code>min</code>.
jpayne@69 1964 * This function also enables the use of significant digits
jpayne@69 1965 * by this formatter - areSignificantDigitsUsed() will return TRUE.
jpayne@69 1966 * @see #areSignificantDigitsUsed
jpayne@69 1967 * @param min the fewest significant digits to be shown
jpayne@69 1968 * @stable ICU 3.0
jpayne@69 1969 */
jpayne@69 1970 void setMinimumSignificantDigits(int32_t min);
jpayne@69 1971
jpayne@69 1972 /**
jpayne@69 1973 * Sets the maximum number of significant digits that will be
jpayne@69 1974 * displayed. If <code>max</code> is less than one then it is set
jpayne@69 1975 * to one. If the minimum significant digits count is greater
jpayne@69 1976 * than <code>max</code>, then it is set to <code>max</code>.
jpayne@69 1977 * This function also enables the use of significant digits
jpayne@69 1978 * by this formatter - areSignificantDigitsUsed() will return TRUE.
jpayne@69 1979 * @see #areSignificantDigitsUsed
jpayne@69 1980 * @param max the most significant digits to be shown
jpayne@69 1981 * @stable ICU 3.0
jpayne@69 1982 */
jpayne@69 1983 void setMaximumSignificantDigits(int32_t max);
jpayne@69 1984
jpayne@69 1985 /**
jpayne@69 1986 * Returns true if significant digits are in use, or false if
jpayne@69 1987 * integer and fraction digit counts are in use.
jpayne@69 1988 * @return true if significant digits are in use
jpayne@69 1989 * @stable ICU 3.0
jpayne@69 1990 */
jpayne@69 1991 UBool areSignificantDigitsUsed() const;
jpayne@69 1992
jpayne@69 1993 /**
jpayne@69 1994 * Sets whether significant digits are in use, or integer and
jpayne@69 1995 * fraction digit counts are in use.
jpayne@69 1996 * @param useSignificantDigits true to use significant digits, or
jpayne@69 1997 * false to use integer and fraction digit counts
jpayne@69 1998 * @stable ICU 3.0
jpayne@69 1999 */
jpayne@69 2000 void setSignificantDigitsUsed(UBool useSignificantDigits);
jpayne@69 2001
jpayne@69 2002 /**
jpayne@69 2003 * Sets the currency used to display currency
jpayne@69 2004 * amounts. This takes effect immediately, if this format is a
jpayne@69 2005 * currency format. If this format is not a currency format, then
jpayne@69 2006 * the currency is used if and when this object becomes a
jpayne@69 2007 * currency format through the application of a new pattern.
jpayne@69 2008 * @param theCurrency a 3-letter ISO code indicating new currency
jpayne@69 2009 * to use. It need not be null-terminated. May be the empty
jpayne@69 2010 * string or NULL to indicate no currency.
jpayne@69 2011 * @param ec input-output error code
jpayne@69 2012 * @stable ICU 3.0
jpayne@69 2013 */
jpayne@69 2014 void setCurrency(const char16_t* theCurrency, UErrorCode& ec) U_OVERRIDE;
jpayne@69 2015
jpayne@69 2016 #ifndef U_FORCE_HIDE_DEPRECATED_API
jpayne@69 2017 /**
jpayne@69 2018 * Sets the currency used to display currency amounts. See
jpayne@69 2019 * setCurrency(const char16_t*, UErrorCode&).
jpayne@69 2020 * @deprecated ICU 3.0. Use setCurrency(const char16_t*, UErrorCode&).
jpayne@69 2021 */
jpayne@69 2022 virtual void setCurrency(const char16_t* theCurrency);
jpayne@69 2023 #endif // U_FORCE_HIDE_DEPRECATED_API
jpayne@69 2024
jpayne@69 2025 /**
jpayne@69 2026 * Sets the `Currency Usage` object used to display currency.
jpayne@69 2027 * This takes effect immediately, if this format is a
jpayne@69 2028 * currency format.
jpayne@69 2029 * @param newUsage new currency usage object to use.
jpayne@69 2030 * @param ec input-output error code
jpayne@69 2031 * @stable ICU 54
jpayne@69 2032 */
jpayne@69 2033 void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec);
jpayne@69 2034
jpayne@69 2035 /**
jpayne@69 2036 * Returns the `Currency Usage` object used to display currency
jpayne@69 2037 * @stable ICU 54
jpayne@69 2038 */
jpayne@69 2039 UCurrencyUsage getCurrencyUsage() const;
jpayne@69 2040
jpayne@69 2041 #ifndef U_HIDE_INTERNAL_API
jpayne@69 2042
jpayne@69 2043 /**
jpayne@69 2044 * Format a number and save it into the given DecimalQuantity.
jpayne@69 2045 * Internal, not intended for public use.
jpayne@69 2046 * @internal
jpayne@69 2047 */
jpayne@69 2048 void formatToDecimalQuantity(double number, number::impl::DecimalQuantity& output,
jpayne@69 2049 UErrorCode& status) const;
jpayne@69 2050
jpayne@69 2051 /**
jpayne@69 2052 * Get a DecimalQuantity corresponding to a formattable as it would be
jpayne@69 2053 * formatted by this DecimalFormat.
jpayne@69 2054 * Internal, not intended for public use.
jpayne@69 2055 * @internal
jpayne@69 2056 */
jpayne@69 2057 void formatToDecimalQuantity(const Formattable& number, number::impl::DecimalQuantity& output,
jpayne@69 2058 UErrorCode& status) const;
jpayne@69 2059
jpayne@69 2060 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 2061
jpayne@69 2062 /**
jpayne@69 2063 * Converts this DecimalFormat to a (Localized)NumberFormatter. Starting
jpayne@69 2064 * in ICU 60, NumberFormatter is the recommended way to format numbers.
jpayne@69 2065 * You can use the returned LocalizedNumberFormatter to format numbers and
jpayne@69 2066 * get a FormattedNumber, which contains a string as well as additional
jpayne@69 2067 * annotations about the formatted value.
jpayne@69 2068 *
jpayne@69 2069 * If a memory allocation failure occurs, the return value of this method
jpayne@69 2070 * might be null. If you are concerned about correct recovery from
jpayne@69 2071 * out-of-memory situations, use this pattern:
jpayne@69 2072 *
jpayne@69 2073 * <pre>
jpayne@69 2074 * FormattedNumber result;
jpayne@69 2075 * if (auto* ptr = df->toNumberFormatter(status)) {
jpayne@69 2076 * result = ptr->formatDouble(123, status);
jpayne@69 2077 * }
jpayne@69 2078 * </pre>
jpayne@69 2079 *
jpayne@69 2080 * If you are not concerned about out-of-memory situations, or if your
jpayne@69 2081 * environment throws exceptions when memory allocation failure occurs,
jpayne@69 2082 * you can chain the methods, like this:
jpayne@69 2083 *
jpayne@69 2084 * <pre>
jpayne@69 2085 * FormattedNumber result = df
jpayne@69 2086 * ->toNumberFormatter(status)
jpayne@69 2087 * ->formatDouble(123, status);
jpayne@69 2088 * </pre>
jpayne@69 2089 *
jpayne@69 2090 * NOTE: The returned LocalizedNumberFormatter is owned by this DecimalFormat.
jpayne@69 2091 * If a non-const method is called on the DecimalFormat, or if the DecimalFormat
jpayne@69 2092 * is deleted, the object becomes invalid. If you plan to keep the return value
jpayne@69 2093 * beyond the lifetime of the DecimalFormat, copy it to a local variable:
jpayne@69 2094 *
jpayne@69 2095 * <pre>
jpayne@69 2096 * LocalizedNumberFormatter lnf;
jpayne@69 2097 * if (auto* ptr = df->toNumberFormatter(status)) {
jpayne@69 2098 * lnf = *ptr;
jpayne@69 2099 * }
jpayne@69 2100 * </pre>
jpayne@69 2101 *
jpayne@69 2102 * @param status Set on failure, like U_MEMORY_ALLOCATION_ERROR.
jpayne@69 2103 * @return A pointer to an internal object, or nullptr on failure.
jpayne@69 2104 * Do not delete the return value!
jpayne@69 2105 * @stable ICU 64
jpayne@69 2106 */
jpayne@69 2107 const number::LocalizedNumberFormatter* toNumberFormatter(UErrorCode& status) const;
jpayne@69 2108
jpayne@69 2109 /**
jpayne@69 2110 * Return the class ID for this class. This is useful only for
jpayne@69 2111 * comparing to a return value from getDynamicClassID(). For example:
jpayne@69 2112 * <pre>
jpayne@69 2113 * . Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69 2114 * . if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69 2115 * . Derived::getStaticClassID()) ...
jpayne@69 2116 * </pre>
jpayne@69 2117 * @return The class ID for all objects of this class.
jpayne@69 2118 * @stable ICU 2.0
jpayne@69 2119 */
jpayne@69 2120 static UClassID U_EXPORT2 getStaticClassID(void);
jpayne@69 2121
jpayne@69 2122 /**
jpayne@69 2123 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
jpayne@69 2124 * This method is to implement a simple version of RTTI, since not all
jpayne@69 2125 * C++ compilers support genuine RTTI. Polymorphic operator==() and
jpayne@69 2126 * clone() methods call this method.
jpayne@69 2127 *
jpayne@69 2128 * @return The class ID for this object. All objects of a
jpayne@69 2129 * given class have the same class ID. Objects of
jpayne@69 2130 * other classes have different class IDs.
jpayne@69 2131 * @stable ICU 2.0
jpayne@69 2132 */
jpayne@69 2133 UClassID getDynamicClassID(void) const U_OVERRIDE;
jpayne@69 2134
jpayne@69 2135 private:
jpayne@69 2136
jpayne@69 2137 /** Rebuilds the formatter object from the property bag. */
jpayne@69 2138 void touch(UErrorCode& status);
jpayne@69 2139
jpayne@69 2140 /** Rebuilds the formatter object, ignoring any error code. */
jpayne@69 2141 void touchNoError();
jpayne@69 2142
jpayne@69 2143 /**
jpayne@69 2144 * Updates the property bag with settings from the given pattern.
jpayne@69 2145 *
jpayne@69 2146 * @param pattern The pattern string to parse.
jpayne@69 2147 * @param ignoreRounding Whether to leave out rounding information (minFrac, maxFrac, and rounding
jpayne@69 2148 * increment) when parsing the pattern. This may be desirable if a custom rounding mode, such
jpayne@69 2149 * as CurrencyUsage, is to be used instead. One of {@link
jpayne@69 2150 * PatternStringParser#IGNORE_ROUNDING_ALWAYS}, {@link PatternStringParser#IGNORE_ROUNDING_IF_CURRENCY},
jpayne@69 2151 * or {@link PatternStringParser#IGNORE_ROUNDING_NEVER}.
jpayne@69 2152 * @see PatternAndPropertyUtils#parseToExistingProperties
jpayne@69 2153 */
jpayne@69 2154 void setPropertiesFromPattern(const UnicodeString& pattern, int32_t ignoreRounding,
jpayne@69 2155 UErrorCode& status);
jpayne@69 2156
jpayne@69 2157 const numparse::impl::NumberParserImpl* getParser(UErrorCode& status) const;
jpayne@69 2158
jpayne@69 2159 const numparse::impl::NumberParserImpl* getCurrencyParser(UErrorCode& status) const;
jpayne@69 2160
jpayne@69 2161 static void fieldPositionHelper(
jpayne@69 2162 const number::impl::UFormattedNumberData& formatted,
jpayne@69 2163 FieldPosition& fieldPosition,
jpayne@69 2164 int32_t offset,
jpayne@69 2165 UErrorCode& status);
jpayne@69 2166
jpayne@69 2167 static void fieldPositionIteratorHelper(
jpayne@69 2168 const number::impl::UFormattedNumberData& formatted,
jpayne@69 2169 FieldPositionIterator* fpi,
jpayne@69 2170 int32_t offset,
jpayne@69 2171 UErrorCode& status);
jpayne@69 2172
jpayne@69 2173 void setupFastFormat();
jpayne@69 2174
jpayne@69 2175 bool fastFormatDouble(double input, UnicodeString& output) const;
jpayne@69 2176
jpayne@69 2177 bool fastFormatInt64(int64_t input, UnicodeString& output) const;
jpayne@69 2178
jpayne@69 2179 void doFastFormatInt32(int32_t input, bool isNegative, UnicodeString& output) const;
jpayne@69 2180
jpayne@69 2181 //=====================================================================================//
jpayne@69 2182 // INSTANCE FIELDS //
jpayne@69 2183 //=====================================================================================//
jpayne@69 2184
jpayne@69 2185
jpayne@69 2186 // One instance field for the implementation, keep all fields inside of an implementation
jpayne@69 2187 // class defined in number_mapper.h
jpayne@69 2188 number::impl::DecimalFormatFields* fields = nullptr;
jpayne@69 2189
jpayne@69 2190 // Allow child class CompactDecimalFormat to access fProperties:
jpayne@69 2191 friend class CompactDecimalFormat;
jpayne@69 2192
jpayne@69 2193 // Allow MeasureFormat to use fieldPositionHelper:
jpayne@69 2194 friend class MeasureFormat;
jpayne@69 2195
jpayne@69 2196 };
jpayne@69 2197
jpayne@69 2198 U_NAMESPACE_END
jpayne@69 2199
jpayne@69 2200 #endif /* #if !UCONFIG_NO_FORMATTING */
jpayne@69 2201
jpayne@69 2202 #endif /* U_SHOW_CPLUSPLUS_API */
jpayne@69 2203
jpayne@69 2204 #endif // _DECIMFMT
jpayne@69 2205 //eof