jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************** jpayne@69: * Copyright (C) 1997-2016, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ******************************************************************************** jpayne@69: * jpayne@69: * File DECIMFMT.H jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 02/19/97 aliu Converted from java. jpayne@69: * 03/20/97 clhuang Updated per C++ implementation. jpayne@69: * 04/03/97 aliu Rewrote parsing and formatting completely, and jpayne@69: * cleaned up and debugged. Actually works now. jpayne@69: * 04/17/97 aliu Changed DigitCount to int per code review. jpayne@69: * 07/10/97 helena Made ParsePosition a class and get rid of the function jpayne@69: * hiding problems. jpayne@69: * 09/09/97 aliu Ported over support for exponential formats. jpayne@69: * 07/20/98 stephen Changed documentation jpayne@69: * 01/30/13 emmons Added Scaling methods jpayne@69: ******************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef DECIMFMT_H jpayne@69: #define DECIMFMT_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Compatibility APIs for decimal formatting. jpayne@69: */ jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/dcfmtsym.h" jpayne@69: #include "unicode/numfmt.h" jpayne@69: #include "unicode/locid.h" jpayne@69: #include "unicode/fpositer.h" jpayne@69: #include "unicode/stringpiece.h" jpayne@69: #include "unicode/curramt.h" jpayne@69: #include "unicode/enumset.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class CurrencyPluralInfo; jpayne@69: class CompactDecimalFormat; jpayne@69: jpayne@69: namespace number { jpayne@69: class LocalizedNumberFormatter; jpayne@69: namespace impl { jpayne@69: class DecimalQuantity; jpayne@69: struct DecimalFormatFields; jpayne@69: class UFormattedNumberData; jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: namespace numparse { jpayne@69: namespace impl { jpayne@69: class NumberParserImpl; jpayne@69: } jpayne@69: } jpayne@69: jpayne@69: /** jpayne@69: * **IMPORTANT:** New users are strongly encouraged to see if jpayne@69: * numberformatter.h fits their use case. Although not deprecated, this header jpayne@69: * is provided for backwards compatibility only. jpayne@69: * jpayne@69: * DecimalFormat is a concrete subclass of NumberFormat that formats decimal jpayne@69: * numbers. It has a variety of features designed to make it possible to parse jpayne@69: * and format numbers in any locale, including support for Western, Arabic, or jpayne@69: * Indic digits. It also supports different flavors of numbers, including jpayne@69: * integers ("123"), fixed-point numbers ("123.4"), scientific notation jpayne@69: * ("1.23E4"), percentages ("12%"), and currency amounts ("$123", "USD123", jpayne@69: * "123 US dollars"). All of these flavors can be easily localized. jpayne@69: * jpayne@69: * To obtain a NumberFormat for a specific locale (including the default jpayne@69: * locale) call one of NumberFormat's factory methods such as jpayne@69: * createInstance(). Do not call the DecimalFormat constructors directly, unless jpayne@69: * you know what you are doing, since the NumberFormat factory methods may jpayne@69: * return subclasses other than DecimalFormat. jpayne@69: * jpayne@69: * **Example Usage** jpayne@69: * jpayne@69: * \code jpayne@69: * // Normally we would have a GUI with a menu for this jpayne@69: * int32_t locCount; jpayne@69: * const Locale* locales = NumberFormat::getAvailableLocales(locCount); jpayne@69: * jpayne@69: * double myNumber = -1234.56; jpayne@69: * UErrorCode success = U_ZERO_ERROR; jpayne@69: * NumberFormat* form; jpayne@69: * jpayne@69: * // Print out a number with the localized number, currency and percent jpayne@69: * // format for each locale. jpayne@69: * UnicodeString countryName; jpayne@69: * UnicodeString displayName; jpayne@69: * UnicodeString str; jpayne@69: * UnicodeString pattern; jpayne@69: * Formattable fmtable; jpayne@69: * for (int32_t j = 0; j < 3; ++j) { jpayne@69: * cout << endl << "FORMAT " << j << endl; jpayne@69: * for (int32_t i = 0; i < locCount; ++i) { jpayne@69: * if (locales[i].getCountry(countryName).size() == 0) { jpayne@69: * // skip language-only jpayne@69: * continue; jpayne@69: * } jpayne@69: * switch (j) { jpayne@69: * case 0: jpayne@69: * form = NumberFormat::createInstance(locales[i], success ); break; jpayne@69: * case 1: jpayne@69: * form = NumberFormat::createCurrencyInstance(locales[i], success ); break; jpayne@69: * default: jpayne@69: * form = NumberFormat::createPercentInstance(locales[i], success ); break; jpayne@69: * } jpayne@69: * if (form) { jpayne@69: * str.remove(); jpayne@69: * pattern = ((DecimalFormat*)form)->toPattern(pattern); jpayne@69: * cout << locales[i].getDisplayName(displayName) << ": " << pattern; jpayne@69: * cout << " -> " << form->format(myNumber,str) << endl; jpayne@69: * form->parse(form->format(myNumber,str), fmtable, success); jpayne@69: * delete form; jpayne@69: * } jpayne@69: * } jpayne@69: * } jpayne@69: * \endcode jpayne@69: * jpayne@69: * **Another example use createInstance(style)** jpayne@69: * jpayne@69: * \code jpayne@69: * // Print out a number using the localized number, currency, jpayne@69: * // percent, scientific, integer, iso currency, and plural currency jpayne@69: * // format for each locale jpayne@69: * Locale* locale = new Locale("en", "US"); jpayne@69: * double myNumber = 1234.56; jpayne@69: * UErrorCode success = U_ZERO_ERROR; jpayne@69: * UnicodeString str; jpayne@69: * Formattable fmtable; jpayne@69: * for (int j=NumberFormat::kNumberStyle; jpayne@69: * j<=NumberFormat::kPluralCurrencyStyle; jpayne@69: * ++j) { jpayne@69: * NumberFormat* form = NumberFormat::createInstance(locale, j, success); jpayne@69: * str.remove(); jpayne@69: * cout << "format result " << form->format(myNumber, str) << endl; jpayne@69: * format->parse(form->format(myNumber, str), fmtable, success); jpayne@69: * delete form; jpayne@69: * } jpayne@69: * \endcode jpayne@69: * jpayne@69: * jpayne@69: *

Patterns jpayne@69: * jpayne@69: *

A DecimalFormat consists of a pattern and a set of jpayne@69: * symbols. The pattern may be set directly using jpayne@69: * applyPattern(), or indirectly using other API methods which jpayne@69: * manipulate aspects of the pattern, such as the minimum number of integer jpayne@69: * digits. The symbols are stored in a DecimalFormatSymbols jpayne@69: * object. When using the NumberFormat factory methods, the jpayne@69: * pattern and symbols are read from ICU's locale data. jpayne@69: * jpayne@69: *

Special Pattern Characters jpayne@69: * jpayne@69: *

Many characters in a pattern are taken literally; they are matched during jpayne@69: * parsing and output unchanged during formatting. Special characters, on the jpayne@69: * other hand, stand for other characters, strings, or classes of characters. jpayne@69: * For example, the '#' character is replaced by a localized digit. Often the jpayne@69: * replacement character is the same as the pattern character; in the U.S. locale, jpayne@69: * the ',' grouping character is replaced by ','. However, the replacement is jpayne@69: * still happening, and if the symbols are modified, the grouping character jpayne@69: * changes. Some special characters affect the behavior of the formatter by jpayne@69: * their presence; for example, if the percent character is seen, then the jpayne@69: * value is multiplied by 100 before being displayed. jpayne@69: * jpayne@69: *

To insert a special character in a pattern as a literal, that is, without jpayne@69: * any special meaning, the character must be quoted. There are some exceptions to jpayne@69: * this which are noted below. jpayne@69: * jpayne@69: *

The characters listed here are used in non-localized patterns. Localized jpayne@69: * patterns use the corresponding characters taken from this formatter's jpayne@69: * DecimalFormatSymbols object instead, and these characters lose jpayne@69: * their special status. Two exceptions are the currency sign and quote, which jpayne@69: * are not localized. jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: *
Symbol jpayne@69: * Location jpayne@69: * Localized? jpayne@69: * Meaning jpayne@69: *
0 jpayne@69: * Number jpayne@69: * Yes jpayne@69: * Digit jpayne@69: *
1-9 jpayne@69: * Number jpayne@69: * Yes jpayne@69: * '1' through '9' indicate rounding. jpayne@69: *
\htmlonly@\endhtmlonly jpayne@69: * Number jpayne@69: * No jpayne@69: * Significant digit jpayne@69: *
# jpayne@69: * Number jpayne@69: * Yes jpayne@69: * Digit, zero shows as absent jpayne@69: *
. jpayne@69: * Number jpayne@69: * Yes jpayne@69: * Decimal separator or monetary decimal separator jpayne@69: *
- jpayne@69: * Number jpayne@69: * Yes jpayne@69: * Minus sign jpayne@69: *
, jpayne@69: * Number jpayne@69: * Yes jpayne@69: * Grouping separator jpayne@69: *
E jpayne@69: * Number jpayne@69: * Yes jpayne@69: * Separates mantissa and exponent in scientific notation. jpayne@69: * Need not be quoted in prefix or suffix. jpayne@69: *
+ jpayne@69: * Exponent jpayne@69: * Yes jpayne@69: * Prefix positive exponents with localized plus sign. jpayne@69: * Need not be quoted in prefix or suffix. jpayne@69: *
; jpayne@69: * Subpattern boundary jpayne@69: * Yes jpayne@69: * Separates positive and negative subpatterns jpayne@69: *
\% jpayne@69: * Prefix or suffix jpayne@69: * Yes jpayne@69: * Multiply by 100 and show as percentage jpayne@69: *
\\u2030 jpayne@69: * Prefix or suffix jpayne@69: * Yes jpayne@69: * Multiply by 1000 and show as per mille jpayne@69: *
\htmlonly¤\endhtmlonly (\\u00A4) jpayne@69: * Prefix or suffix jpayne@69: * No jpayne@69: * Currency sign, replaced by currency symbol. If jpayne@69: * doubled, replaced by international currency symbol. jpayne@69: * If tripled, replaced by currency plural names, for example, jpayne@69: * "US dollar" or "US dollars" for America. jpayne@69: * If present in a pattern, the monetary decimal separator jpayne@69: * is used instead of the decimal separator. jpayne@69: *
' jpayne@69: * Prefix or suffix jpayne@69: * No jpayne@69: * Used to quote special characters in a prefix or suffix, jpayne@69: * for example, "'#'#" formats 123 to jpayne@69: * "#123". To create a single quote jpayne@69: * itself, use two in a row: "# o''clock". jpayne@69: *
* jpayne@69: * Prefix or suffix boundary jpayne@69: * Yes jpayne@69: * Pad escape, precedes pad character jpayne@69: *
jpayne@69: * jpayne@69: *

A DecimalFormat pattern contains a positive and negative jpayne@69: * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a jpayne@69: * prefix, a numeric part, and a suffix. If there is no explicit negative jpayne@69: * subpattern, the negative subpattern is the localized minus sign prefixed to the jpayne@69: * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there jpayne@69: * is an explicit negative subpattern, it serves only to specify the negative jpayne@69: * prefix and suffix; the number of digits, minimal digits, and other jpayne@69: * characteristics are ignored in the negative subpattern. That means that jpayne@69: * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)". jpayne@69: * jpayne@69: *

The prefixes, suffixes, and various symbols used for infinity, digits, jpayne@69: * thousands separators, decimal separators, etc. may be set to arbitrary jpayne@69: * values, and they will appear properly during formatting. However, care must jpayne@69: * be taken that the symbols and strings do not conflict, or parsing will be jpayne@69: * unreliable. For example, either the positive and negative prefixes or the jpayne@69: * suffixes must be distinct for parse() to be able jpayne@69: * to distinguish positive from negative values. Another example is that the jpayne@69: * decimal separator and thousands separator should be distinct characters, or jpayne@69: * parsing will be impossible. jpayne@69: * jpayne@69: *

The grouping separator is a character that separates clusters of jpayne@69: * integer digits to make large numbers more legible. It commonly used for jpayne@69: * thousands, but in some locales it separates ten-thousands. The grouping jpayne@69: * size is the number of digits between the grouping separators, such as 3 jpayne@69: * for "100,000,000" or 4 for "1 0000 0000". There are actually two different jpayne@69: * grouping sizes: One used for the least significant integer digits, the jpayne@69: * primary grouping size, and one used for all others, the jpayne@69: * secondary grouping size. In most locales these are the same, but jpayne@69: * sometimes they are different. For example, if the primary grouping interval jpayne@69: * is 3, and the secondary is 2, then this corresponds to the pattern jpayne@69: * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a jpayne@69: * pattern contains multiple grouping separators, the interval between the last jpayne@69: * one and the end of the integer defines the primary grouping size, and the jpayne@69: * interval between the last two defines the secondary grouping size. All others jpayne@69: * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####". jpayne@69: * jpayne@69: *

Illegal patterns, such as "#.#.#" or "#.###,###", will cause jpayne@69: * DecimalFormat to set a failing UErrorCode. jpayne@69: * jpayne@69: *

Pattern BNF jpayne@69: * jpayne@69: *

jpayne@69:  * pattern    := subpattern (';' subpattern)?
jpayne@69:  * subpattern := prefix? number exponent? suffix?
jpayne@69:  * number     := (integer ('.' fraction)?) | sigDigits
jpayne@69:  * prefix     := '\\u0000'..'\\uFFFD' - specialCharacters
jpayne@69:  * suffix     := '\\u0000'..'\\uFFFD' - specialCharacters
jpayne@69:  * integer    := '#'* '0'* '0'
jpayne@69:  * fraction   := '0'* '#'*
jpayne@69:  * sigDigits  := '#'* '@' '@'* '#'*
jpayne@69:  * exponent   := 'E' '+'? '0'* '0'
jpayne@69:  * padSpec    := '*' padChar
jpayne@69:  * padChar    := '\\u0000'..'\\uFFFD' - quote
jpayne@69:  *  
jpayne@69:  * Notation:
jpayne@69:  *   X*       0 or more instances of X
jpayne@69:  *   X?       0 or 1 instances of X
jpayne@69:  *   X|Y      either X or Y
jpayne@69:  *   C..D     any character from C up to D, inclusive
jpayne@69:  *   S-T      characters in S, except those in T
jpayne@69:  * 
jpayne@69: * The first subpattern is for positive numbers. The second (optional) jpayne@69: * subpattern is for negative numbers. jpayne@69: * jpayne@69: *

Not indicated in the BNF syntax above: jpayne@69: * jpayne@69: *

jpayne@69: * jpayne@69: *

Parsing jpayne@69: * jpayne@69: *

DecimalFormat parses all Unicode characters that represent jpayne@69: * decimal digits, as defined by u_charDigitValue(). In addition, jpayne@69: * DecimalFormat also recognizes as digits the ten consecutive jpayne@69: * characters starting with the localized zero digit defined in the jpayne@69: * DecimalFormatSymbols object. During formatting, the jpayne@69: * DecimalFormatSymbols-based digits are output. jpayne@69: * jpayne@69: *

During parsing, grouping separators are ignored if in lenient mode; jpayne@69: * otherwise, if present, they must be in appropriate positions. jpayne@69: * jpayne@69: *

For currency parsing, the formatter is able to parse every currency jpayne@69: * style formats no matter which style the formatter is constructed with. jpayne@69: * For example, a formatter instance gotten from jpayne@69: * NumberFormat.getInstance(ULocale, NumberFormat.CURRENCYSTYLE) can parse jpayne@69: * formats such as "USD1.00" and "3.00 US dollars". jpayne@69: * jpayne@69: *

If parse(UnicodeString&,Formattable&,ParsePosition&) jpayne@69: * fails to parse a string, it leaves the parse position unchanged. jpayne@69: * The convenience method parse(UnicodeString&,Formattable&,UErrorCode&) jpayne@69: * indicates parse failure by setting a failing jpayne@69: * UErrorCode. jpayne@69: * jpayne@69: *

Formatting jpayne@69: * jpayne@69: *

Formatting is guided by several parameters, all of which can be jpayne@69: * specified either using a pattern or using the API. The following jpayne@69: * description applies to formats that do not use scientific jpayne@69: * notation or significant digits. jpayne@69: * jpayne@69: *

jpayne@69: * jpayne@69: *

Special Values jpayne@69: * jpayne@69: *

NaN is represented as a single character, typically jpayne@69: * \\uFFFD. This character is determined by the jpayne@69: * DecimalFormatSymbols object. This is the only value for which jpayne@69: * the prefixes and suffixes are not used. jpayne@69: * jpayne@69: *

Infinity is represented as a single character, typically jpayne@69: * \\u221E, with the positive or negative prefixes and suffixes jpayne@69: * applied. The infinity character is determined by the jpayne@69: * DecimalFormatSymbols object. jpayne@69: * jpayne@69: * Scientific Notation jpayne@69: * jpayne@69: *

Numbers in scientific notation are expressed as the product of a mantissa jpayne@69: * and a power of ten, for example, 1234 can be expressed as 1.234 x 103. The jpayne@69: * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0), jpayne@69: * but it need not be. DecimalFormat supports arbitrary mantissas. jpayne@69: * DecimalFormat can be instructed to use scientific jpayne@69: * notation through the API or through the pattern. In a pattern, the exponent jpayne@69: * character immediately followed by one or more digit characters indicates jpayne@69: * scientific notation. Example: "0.###E0" formats the number 1234 as jpayne@69: * "1.234E3". jpayne@69: * jpayne@69: *

jpayne@69: * jpayne@69: * Significant Digits jpayne@69: * jpayne@69: * DecimalFormat has two ways of controlling how many jpayne@69: * digits are shows: (a) significant digits counts, or (b) integer and jpayne@69: * fraction digit counts. Integer and fraction digit counts are jpayne@69: * described above. When a formatter is using significant digits jpayne@69: * counts, the number of integer and fraction digits is not specified jpayne@69: * directly, and the formatter settings for these counts are ignored. jpayne@69: * Instead, the formatter uses however many integer and fraction jpayne@69: * digits are required to display the specified number of significant jpayne@69: * digits. Examples: jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: *
Pattern jpayne@69: * Minimum significant digits jpayne@69: * Maximum significant digits jpayne@69: * Number jpayne@69: * Output of format() jpayne@69: *
\@\@\@ jpayne@69: * 3 jpayne@69: * 3 jpayne@69: * 12345 jpayne@69: * 12300 jpayne@69: *
\@\@\@ jpayne@69: * 3 jpayne@69: * 3 jpayne@69: * 0.12345 jpayne@69: * 0.123 jpayne@69: *
\@\@## jpayne@69: * 2 jpayne@69: * 4 jpayne@69: * 3.14159 jpayne@69: * 3.142 jpayne@69: *
\@\@## jpayne@69: * 2 jpayne@69: * 4 jpayne@69: * 1.23004 jpayne@69: * 1.23 jpayne@69: *
jpayne@69: * jpayne@69: * jpayne@69: * jpayne@69: *

Padding jpayne@69: * jpayne@69: *

DecimalFormat supports padding the result of jpayne@69: * format() to a specific width. Padding may be specified either jpayne@69: * through the API or through the pattern syntax. In a pattern the pad escape jpayne@69: * character, followed by a single pad character, causes padding to be parsed jpayne@69: * and formatted. The pad escape character is '*' in unlocalized patterns, and jpayne@69: * can be localized using DecimalFormatSymbols::setSymbol() with a jpayne@69: * DecimalFormatSymbols::kPadEscapeSymbol jpayne@69: * selector. For example, "$*x#,##0.00" formats 123 to jpayne@69: * "$xx123.00", and 1234 to "$1,234.00". jpayne@69: * jpayne@69: *

jpayne@69: * jpayne@69: *

Rounding jpayne@69: * jpayne@69: *

DecimalFormat supports rounding to a specific increment. For jpayne@69: * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the jpayne@69: * nearest 0.65 is 1.3. The rounding increment may be specified through the API jpayne@69: * or in a pattern. To specify a rounding increment in a pattern, include the jpayne@69: * increment in the pattern itself. "#,#50" specifies a rounding increment of jpayne@69: * 50. "#,##0.05" specifies a rounding increment of 0.05. jpayne@69: * jpayne@69: *

In the absence of an explicit rounding increment numbers are jpayne@69: * rounded to their formatted width. jpayne@69: * jpayne@69: *

jpayne@69: * jpayne@69: *

Synchronization jpayne@69: * jpayne@69: *

DecimalFormat objects are not synchronized. Multiple jpayne@69: * threads should not access one formatter concurrently. jpayne@69: * jpayne@69: *

Subclassing jpayne@69: * jpayne@69: *

User subclasses are not supported. While clients may write jpayne@69: * subclasses, such code will not necessarily work and will not be jpayne@69: * guaranteed to work stably from release to release. jpayne@69: */ jpayne@69: class U_I18N_API DecimalFormat : public NumberFormat { jpayne@69: public: jpayne@69: /** jpayne@69: * Pad position. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: enum EPadPosition { jpayne@69: kPadBeforePrefix, kPadAfterPrefix, kPadBeforeSuffix, kPadAfterSuffix jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * Create a DecimalFormat using the default pattern and symbols jpayne@69: * for the default locale. This is a convenient way to obtain a jpayne@69: * DecimalFormat when internationalization is not the main concern. jpayne@69: *

jpayne@69: * To obtain standard formats for a given locale, use the factory methods jpayne@69: * on NumberFormat such as createInstance. These factories will jpayne@69: * return the most appropriate sub-class of NumberFormat for a given jpayne@69: * locale. jpayne@69: *

jpayne@69: * NOTE: New users are strongly encouraged to use jpayne@69: * #icu::number::NumberFormatter instead of DecimalFormat. jpayne@69: * @param status Output param set to success/failure code. If the jpayne@69: * pattern is invalid this will be set to a failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create a DecimalFormat from the given pattern and the symbols jpayne@69: * for the default locale. This is a convenient way to obtain a jpayne@69: * DecimalFormat when internationalization is not the main concern. jpayne@69: *

jpayne@69: * To obtain standard formats for a given locale, use the factory methods jpayne@69: * on NumberFormat such as createInstance. These factories will jpayne@69: * return the most appropriate sub-class of NumberFormat for a given jpayne@69: * locale. jpayne@69: *

jpayne@69: * NOTE: New users are strongly encouraged to use jpayne@69: * #icu::number::NumberFormatter instead of DecimalFormat. jpayne@69: * @param pattern A non-localized pattern string. jpayne@69: * @param status Output param set to success/failure code. If the jpayne@69: * pattern is invalid this will be set to a failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create a DecimalFormat from the given pattern and symbols. jpayne@69: * Use this constructor when you need to completely customize the jpayne@69: * behavior of the format. jpayne@69: *

jpayne@69: * To obtain standard formats for a given jpayne@69: * locale, use the factory methods on NumberFormat such as jpayne@69: * createInstance or createCurrencyInstance. If you need only minor adjustments jpayne@69: * to a standard format, you can modify the format returned by jpayne@69: * a NumberFormat factory method. jpayne@69: *

jpayne@69: * NOTE: New users are strongly encouraged to use jpayne@69: * #icu::number::NumberFormatter instead of DecimalFormat. jpayne@69: * jpayne@69: * @param pattern a non-localized pattern string jpayne@69: * @param symbolsToAdopt the set of symbols to be used. The caller should not jpayne@69: * delete this object after making this call. jpayne@69: * @param status Output param set to success/failure code. If the jpayne@69: * pattern is invalid this will be set to a failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: jpayne@69: /** jpayne@69: * This API is for ICU use only. jpayne@69: * Create a DecimalFormat from the given pattern, symbols, and style. jpayne@69: * jpayne@69: * @param pattern a non-localized pattern string jpayne@69: * @param symbolsToAdopt the set of symbols to be used. The caller should not jpayne@69: * delete this object after making this call. jpayne@69: * @param style style of decimal format jpayne@69: * @param status Output param set to success/failure code. If the jpayne@69: * pattern is invalid this will be set to a failure code. jpayne@69: * @internal jpayne@69: */ jpayne@69: DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, jpayne@69: UNumberFormatStyle style, UErrorCode& status); jpayne@69: jpayne@69: #if UCONFIG_HAVE_PARSEALLINPUT jpayne@69: jpayne@69: /** jpayne@69: * @internal jpayne@69: */ jpayne@69: void setParseAllInput(UNumberFormatAttributeValue value); jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: /** jpayne@69: * Internal constructor for DecimalFormat; sets up internal fields. All public constructors should jpayne@69: * call this constructor. jpayne@69: */ jpayne@69: DecimalFormat(const DecimalFormatSymbols* symbolsToAdopt, UErrorCode& status); jpayne@69: jpayne@69: public: jpayne@69: jpayne@69: /** jpayne@69: * Set an integer attribute on this DecimalFormat. jpayne@69: * May return U_UNSUPPORTED_ERROR if this instance does not support jpayne@69: * the specified attribute. jpayne@69: * @param attr the attribute to set jpayne@69: * @param newValue new value jpayne@69: * @param status the error type jpayne@69: * @return *this - for chaining (example: format.setAttribute(...).setAttribute(...) ) jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: virtual DecimalFormat& setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Get an integer jpayne@69: * May return U_UNSUPPORTED_ERROR if this instance does not support jpayne@69: * the specified attribute. jpayne@69: * @param attr the attribute to set jpayne@69: * @param status the error type jpayne@69: * @return the attribute value. Undefined if there is an error. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: virtual int32_t getAttribute(UNumberFormatAttribute attr, UErrorCode& status) const; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Set whether or not grouping will be used in this format. jpayne@69: * @param newValue True, grouping will be used in this format. jpayne@69: * @see getGroupingUsed jpayne@69: * @stable ICU 53 jpayne@69: */ jpayne@69: void setGroupingUsed(UBool newValue) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Sets whether or not numbers should be parsed as integers only. jpayne@69: * @param value set True, this format will parse numbers as integers jpayne@69: * only. jpayne@69: * @see isParseIntegerOnly jpayne@69: * @stable ICU 53 jpayne@69: */ jpayne@69: void setParseIntegerOnly(UBool value) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Sets whether lenient parsing should be enabled (it is off by default). jpayne@69: * jpayne@69: * @param enable \c TRUE if lenient parsing should be used, jpayne@69: * \c FALSE otherwise. jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: void setLenient(UBool enable) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Create a DecimalFormat from the given pattern and symbols. jpayne@69: * Use this constructor when you need to completely customize the jpayne@69: * behavior of the format. jpayne@69: *

jpayne@69: * To obtain standard formats for a given jpayne@69: * locale, use the factory methods on NumberFormat such as jpayne@69: * createInstance or createCurrencyInstance. If you need only minor adjustments jpayne@69: * to a standard format, you can modify the format returned by jpayne@69: * a NumberFormat factory method. jpayne@69: *

jpayne@69: * NOTE: New users are strongly encouraged to use jpayne@69: * #icu::number::NumberFormatter instead of DecimalFormat. jpayne@69: * jpayne@69: * @param pattern a non-localized pattern string jpayne@69: * @param symbolsToAdopt the set of symbols to be used. The caller should not jpayne@69: * delete this object after making this call. jpayne@69: * @param parseError Output param to receive errors occurred during parsing jpayne@69: * @param status Output param set to success/failure code. If the jpayne@69: * pattern is invalid this will be set to a failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat(const UnicodeString& pattern, DecimalFormatSymbols* symbolsToAdopt, jpayne@69: UParseError& parseError, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create a DecimalFormat from the given pattern and symbols. jpayne@69: * Use this constructor when you need to completely customize the jpayne@69: * behavior of the format. jpayne@69: *

jpayne@69: * To obtain standard formats for a given jpayne@69: * locale, use the factory methods on NumberFormat such as jpayne@69: * createInstance or createCurrencyInstance. If you need only minor adjustments jpayne@69: * to a standard format, you can modify the format returned by jpayne@69: * a NumberFormat factory method. jpayne@69: *

jpayne@69: * NOTE: New users are strongly encouraged to use jpayne@69: * #icu::number::NumberFormatter instead of DecimalFormat. jpayne@69: * jpayne@69: * @param pattern a non-localized pattern string jpayne@69: * @param symbols the set of symbols to be used jpayne@69: * @param status Output param set to success/failure code. If the jpayne@69: * pattern is invalid this will be set to a failure code. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat(const UnicodeString& pattern, const DecimalFormatSymbols& symbols, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * jpayne@69: * @param source the DecimalFormat object to be copied from. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat(const DecimalFormat& source); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * jpayne@69: * @param rhs the DecimalFormat object to be copied. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat& operator=(const DecimalFormat& rhs); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: ~DecimalFormat() U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Clone this Format object polymorphically. The caller owns the jpayne@69: * result and should delete it when done. jpayne@69: * jpayne@69: * @return a polymorphic copy of this DecimalFormat. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DecimalFormat* clone() const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given Format objects are semantically equal. jpayne@69: * Objects of different subclasses are considered unequal. jpayne@69: * jpayne@69: * @param other the object to be compared with. jpayne@69: * @return true if the given Format objects are semantically equal. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator==(const Format& other) const U_OVERRIDE; jpayne@69: jpayne@69: jpayne@69: using NumberFormat::format; jpayne@69: jpayne@69: /** jpayne@69: * Format a double or long number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Format a double or long number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @internal jpayne@69: */ jpayne@69: UnicodeString& format(double number, UnicodeString& appendTo, FieldPosition& pos, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Format a double or long number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param posIter On return, can be used to iterate over positions jpayne@69: * of fields generated by this format call. jpayne@69: * Can be NULL. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: UnicodeString& format(double number, UnicodeString& appendTo, FieldPositionIterator* posIter, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Format a long number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Format a long number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @internal jpayne@69: */ jpayne@69: UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPosition& pos, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Format a long number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param posIter On return, can be used to iterate over positions jpayne@69: * of fields generated by this format call. jpayne@69: * Can be NULL. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: UnicodeString& format(int32_t number, UnicodeString& appendTo, FieldPositionIterator* posIter, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Format an int64 number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos) const U_OVERRIDE; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Format an int64 number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @internal jpayne@69: */ jpayne@69: UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPosition& pos, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Format an int64 number using base-10 representation. jpayne@69: * jpayne@69: * @param number The value to be formatted. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param posIter On return, can be used to iterate over positions jpayne@69: * of fields generated by this format call. jpayne@69: * Can be NULL. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: UnicodeString& format(int64_t number, UnicodeString& appendTo, FieldPositionIterator* posIter, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Format a decimal number. jpayne@69: * The syntax of the unformatted number is a "numeric string" jpayne@69: * as defined in the Decimal Arithmetic Specification, available at jpayne@69: * http://speleotrove.com/decimal jpayne@69: * jpayne@69: * @param number The unformatted number, as a string. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param posIter On return, can be used to iterate over positions jpayne@69: * of fields generated by this format call. jpayne@69: * Can be NULL. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: UnicodeString& format(StringPiece number, UnicodeString& appendTo, FieldPositionIterator* posIter, jpayne@69: UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: jpayne@69: /** jpayne@69: * Format a decimal number. jpayne@69: * The number is a DecimalQuantity wrapper onto a floating point decimal number. jpayne@69: * The default implementation in NumberFormat converts the decimal number jpayne@69: * to a double and formats that. jpayne@69: * jpayne@69: * @param number The number, a DecimalQuantity format Decimal Floating Point. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param posIter On return, can be used to iterate over positions jpayne@69: * of fields generated by this format call. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @internal jpayne@69: */ jpayne@69: UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo, jpayne@69: FieldPositionIterator* posIter, UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Format a decimal number. jpayne@69: * The number is a DecimalQuantity wrapper onto a floating point decimal number. jpayne@69: * The default implementation in NumberFormat converts the decimal number jpayne@69: * to a double and formats that. jpayne@69: * jpayne@69: * @param number The number, a DecimalQuantity format Decimal Floating Point. jpayne@69: * @param appendTo Output parameter to receive result. jpayne@69: * Result is appended to existing contents. jpayne@69: * @param pos On input: an alignment field, if desired. jpayne@69: * On output: the offsets of the alignment field. jpayne@69: * @param status Output param filled with success/failure status. jpayne@69: * @return Reference to 'appendTo' parameter. jpayne@69: * @internal jpayne@69: */ jpayne@69: UnicodeString& format(const number::impl::DecimalQuantity& number, UnicodeString& appendTo, jpayne@69: FieldPosition& pos, UErrorCode& status) const U_OVERRIDE; jpayne@69: jpayne@69: #endif // U_HIDE_INTERNAL_API jpayne@69: jpayne@69: using NumberFormat::parse; jpayne@69: jpayne@69: /** jpayne@69: * Parse the given string using this object's choices. The method jpayne@69: * does string comparisons to try to find an optimal match. jpayne@69: * If no object can be parsed, index is unchanged, and NULL is jpayne@69: * returned. The result is returned as the most parsimonious jpayne@69: * type of Formattable that will accommodate all of the jpayne@69: * necessary precision. For example, if the result is exactly 12, jpayne@69: * it will be returned as a long. However, if it is 1.5, it will jpayne@69: * be returned as a double. jpayne@69: * jpayne@69: * @param text The text to be parsed. jpayne@69: * @param result Formattable to be set to the parse result. jpayne@69: * If parse fails, return contents are undefined. jpayne@69: * @param parsePosition The position to start parsing at on input. jpayne@69: * On output, moved to after the last successfully jpayne@69: * parse character. On parse failure, does not change. jpayne@69: * @see Formattable jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void parse(const UnicodeString& text, Formattable& result, jpayne@69: ParsePosition& parsePosition) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Parses text from the given string as a currency amount. Unlike jpayne@69: * the parse() method, this method will attempt to parse a generic jpayne@69: * currency name, searching for a match of this object's locale's jpayne@69: * currency display names, or for a 3-letter ISO currency code. jpayne@69: * This method will fail if this format is not a currency format, jpayne@69: * that is, if it does not contain the currency pattern symbol jpayne@69: * (U+00A4) in its prefix or suffix. jpayne@69: * jpayne@69: * @param text the string to parse jpayne@69: * @param pos input-output position; on input, the position within text jpayne@69: * to match; must have 0 <= pos.getIndex() < text.length(); jpayne@69: * on output, the position after the last matched character. jpayne@69: * If the parse fails, the position in unchanged upon output. jpayne@69: * @return if parse succeeds, a pointer to a newly-created CurrencyAmount jpayne@69: * object (owned by the caller) containing information about jpayne@69: * the parsed currency; if parse fails, this is NULL. jpayne@69: * @stable ICU 49 jpayne@69: */ jpayne@69: CurrencyAmount* parseCurrency(const UnicodeString& text, ParsePosition& pos) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Returns the decimal format symbols, which is generally not changed jpayne@69: * by the programmer or user. jpayne@69: * @return desired DecimalFormatSymbols jpayne@69: * @see DecimalFormatSymbols jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual const DecimalFormatSymbols* getDecimalFormatSymbols(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the decimal format symbols, which is generally not changed jpayne@69: * by the programmer or user. jpayne@69: * @param symbolsToAdopt DecimalFormatSymbols to be adopted. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt); jpayne@69: jpayne@69: /** jpayne@69: * Sets the decimal format symbols, which is generally not changed jpayne@69: * by the programmer or user. jpayne@69: * @param symbols DecimalFormatSymbols. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Returns the currency plural format information, jpayne@69: * which is generally not changed by the programmer or user. jpayne@69: * @return desired CurrencyPluralInfo jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the currency plural format information, jpayne@69: * which is generally not changed by the programmer or user. jpayne@69: * @param toAdopt CurrencyPluralInfo to be adopted. jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo* toAdopt); jpayne@69: jpayne@69: /** jpayne@69: * Sets the currency plural format information, jpayne@69: * which is generally not changed by the programmer or user. jpayne@69: * @param info Currency Plural Info. jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: virtual void setCurrencyPluralInfo(const CurrencyPluralInfo& info); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Get the positive prefix. jpayne@69: * jpayne@69: * @param result Output param which will receive the positive prefix. jpayne@69: * @return A reference to 'result'. jpayne@69: * Examples: +123, $123, sFr123 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getPositivePrefix(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the positive prefix. jpayne@69: * jpayne@69: * @param newValue the new value of the the positive prefix to be set. jpayne@69: * Examples: +123, $123, sFr123 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setPositivePrefix(const UnicodeString& newValue); jpayne@69: jpayne@69: /** jpayne@69: * Get the negative prefix. jpayne@69: * jpayne@69: * @param result Output param which will receive the negative prefix. jpayne@69: * @return A reference to 'result'. jpayne@69: * Examples: -123, ($123) (with negative suffix), sFr-123 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getNegativePrefix(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the negative prefix. jpayne@69: * jpayne@69: * @param newValue the new value of the the negative prefix to be set. jpayne@69: * Examples: -123, ($123) (with negative suffix), sFr-123 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setNegativePrefix(const UnicodeString& newValue); jpayne@69: jpayne@69: /** jpayne@69: * Get the positive suffix. jpayne@69: * jpayne@69: * @param result Output param which will receive the positive suffix. jpayne@69: * @return A reference to 'result'. jpayne@69: * Example: 123% jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getPositiveSuffix(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the positive suffix. jpayne@69: * jpayne@69: * @param newValue the new value of the positive suffix to be set. jpayne@69: * Example: 123% jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setPositiveSuffix(const UnicodeString& newValue); jpayne@69: jpayne@69: /** jpayne@69: * Get the negative suffix. jpayne@69: * jpayne@69: * @param result Output param which will receive the negative suffix. jpayne@69: * @return A reference to 'result'. jpayne@69: * Examples: -123%, ($123) (with positive suffixes) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getNegativeSuffix(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the negative suffix. jpayne@69: * jpayne@69: * @param newValue the new value of the negative suffix to be set. jpayne@69: * Examples: 123% jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setNegativeSuffix(const UnicodeString& newValue); jpayne@69: jpayne@69: /** jpayne@69: * Whether to show the plus sign on positive (non-negative) numbers; for example, "+12" jpayne@69: * jpayne@69: * For more control over sign display, use NumberFormatter. jpayne@69: * jpayne@69: * @return Whether the sign is shown on positive numbers and zero. jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: UBool isSignAlwaysShown() const; jpayne@69: jpayne@69: /** jpayne@69: * Set whether to show the plus sign on positive (non-negative) numbers; for example, "+12". jpayne@69: * jpayne@69: * For more control over sign display, use NumberFormatter. jpayne@69: * jpayne@69: * @param value true to always show a sign; false to hide the sign on positive numbers and zero. jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: void setSignAlwaysShown(UBool value); jpayne@69: jpayne@69: /** jpayne@69: * Get the multiplier for use in percent, permill, etc. jpayne@69: * For a percentage, set the suffixes to have "%" and the multiplier to be 100. jpayne@69: * (For Arabic, use arabic percent symbol). jpayne@69: * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000. jpayne@69: * jpayne@69: * The number may also be multiplied by a power of ten; see getMultiplierScale(). jpayne@69: * jpayne@69: * @return the multiplier for use in percent, permill, etc. jpayne@69: * Examples: with 100, 1.23 -> "123", and "123" -> 1.23 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: int32_t getMultiplier(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the multiplier for use in percent, permill, etc. jpayne@69: * For a percentage, set the suffixes to have "%" and the multiplier to be 100. jpayne@69: * (For Arabic, use arabic percent symbol). jpayne@69: * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000. jpayne@69: * jpayne@69: * This method only supports integer multipliers. To multiply by a non-integer, pair this jpayne@69: * method with setMultiplierScale(). jpayne@69: * jpayne@69: * @param newValue the new value of the multiplier for use in percent, permill, etc. jpayne@69: * Examples: with 100, 1.23 -> "123", and "123" -> 1.23 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setMultiplier(int32_t newValue); jpayne@69: jpayne@69: /** jpayne@69: * Gets the power of ten by which number should be multiplied before formatting, which jpayne@69: * can be combined with setMultiplier() to multiply by any arbitrary decimal value. jpayne@69: * jpayne@69: * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale jpayne@69: * of -2 corresponds to multiplication by 0.01. jpayne@69: * jpayne@69: * This method is analogous to UNUM_SCALE in getAttribute. jpayne@69: * jpayne@69: * @return the current value of the power-of-ten multiplier. jpayne@69: * @stable ICU 62 jpayne@69: */ jpayne@69: int32_t getMultiplierScale(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets a power of ten by which number should be multiplied before formatting, which jpayne@69: * can be combined with setMultiplier() to multiply by any arbitrary decimal value. jpayne@69: * jpayne@69: * A multiplier scale of 2 corresponds to multiplication by 100, and a multiplier scale jpayne@69: * of -2 corresponds to multiplication by 0.01. jpayne@69: * jpayne@69: * For example, to multiply numbers by 0.5 before formatting, you can do: jpayne@69: * jpayne@69: *

jpayne@69:      * df.setMultiplier(5);
jpayne@69:      * df.setMultiplierScale(-1);
jpayne@69:      * 
jpayne@69: * jpayne@69: * This method is analogous to UNUM_SCALE in setAttribute. jpayne@69: * jpayne@69: * @param newValue the new value of the power-of-ten multiplier. jpayne@69: * @stable ICU 62 jpayne@69: */ jpayne@69: void setMultiplierScale(int32_t newValue); jpayne@69: jpayne@69: /** jpayne@69: * Get the rounding increment. jpayne@69: * @return A positive rounding increment, or 0.0 if a custom rounding jpayne@69: * increment is not in effect. jpayne@69: * @see #setRoundingIncrement jpayne@69: * @see #getRoundingMode jpayne@69: * @see #setRoundingMode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual double getRoundingIncrement(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the rounding increment. In the absence of a rounding increment, jpayne@69: * numbers will be rounded to the number of digits displayed. jpayne@69: * @param newValue A positive rounding increment, or 0.0 to jpayne@69: * use the default rounding increment. jpayne@69: * Negative increments are equivalent to 0.0. jpayne@69: * @see #getRoundingIncrement jpayne@69: * @see #getRoundingMode jpayne@69: * @see #setRoundingMode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setRoundingIncrement(double newValue); jpayne@69: jpayne@69: /** jpayne@69: * Get the rounding mode. jpayne@69: * @return A rounding mode jpayne@69: * @see #setRoundingIncrement jpayne@69: * @see #getRoundingIncrement jpayne@69: * @see #setRoundingMode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ERoundingMode getRoundingMode(void) const U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Set the rounding mode. jpayne@69: * @param roundingMode A rounding mode jpayne@69: * @see #setRoundingIncrement jpayne@69: * @see #getRoundingIncrement jpayne@69: * @see #getRoundingMode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setRoundingMode(ERoundingMode roundingMode) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Get the width to which the output of format() is padded. jpayne@69: * The width is counted in 16-bit code units. jpayne@69: * @return the format width, or zero if no padding is in effect jpayne@69: * @see #setFormatWidth jpayne@69: * @see #getPadCharacterString jpayne@69: * @see #setPadCharacter jpayne@69: * @see #getPadPosition jpayne@69: * @see #setPadPosition jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getFormatWidth(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the width to which the output of format() is padded. jpayne@69: * The width is counted in 16-bit code units. jpayne@69: * This method also controls whether padding is enabled. jpayne@69: * @param width the width to which to pad the result of jpayne@69: * format(), or zero to disable padding. A negative jpayne@69: * width is equivalent to 0. jpayne@69: * @see #getFormatWidth jpayne@69: * @see #getPadCharacterString jpayne@69: * @see #setPadCharacter jpayne@69: * @see #getPadPosition jpayne@69: * @see #setPadPosition jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setFormatWidth(int32_t width); jpayne@69: jpayne@69: /** jpayne@69: * Get the pad character used to pad to the format width. The jpayne@69: * default is ' '. jpayne@69: * @return a string containing the pad character. This will always jpayne@69: * have a length of one 32-bit code point. jpayne@69: * @see #setFormatWidth jpayne@69: * @see #getFormatWidth jpayne@69: * @see #setPadCharacter jpayne@69: * @see #getPadPosition jpayne@69: * @see #setPadPosition jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UnicodeString getPadCharacterString() const; jpayne@69: jpayne@69: /** jpayne@69: * Set the character used to pad to the format width. If padding jpayne@69: * is not enabled, then this will take effect if padding is later jpayne@69: * enabled. jpayne@69: * @param padChar a string containing the pad character. If the string jpayne@69: * has length 0, then the pad character is set to ' '. Otherwise jpayne@69: * padChar.char32At(0) will be used as the pad character. jpayne@69: * @see #setFormatWidth jpayne@69: * @see #getFormatWidth jpayne@69: * @see #getPadCharacterString jpayne@69: * @see #getPadPosition jpayne@69: * @see #setPadPosition jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setPadCharacter(const UnicodeString& padChar); jpayne@69: jpayne@69: /** jpayne@69: * Get the position at which padding will take place. This is the location jpayne@69: * at which padding will be inserted if the result of format() jpayne@69: * is shorter than the format width. jpayne@69: * @return the pad position, one of kPadBeforePrefix, jpayne@69: * kPadAfterPrefix, kPadBeforeSuffix, or jpayne@69: * kPadAfterSuffix. jpayne@69: * @see #setFormatWidth jpayne@69: * @see #getFormatWidth jpayne@69: * @see #setPadCharacter jpayne@69: * @see #getPadCharacterString jpayne@69: * @see #setPadPosition jpayne@69: * @see #EPadPosition jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual EPadPosition getPadPosition(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the position at which padding will take place. This is the location jpayne@69: * at which padding will be inserted if the result of format() jpayne@69: * is shorter than the format width. This has no effect unless padding is jpayne@69: * enabled. jpayne@69: * @param padPos the pad position, one of kPadBeforePrefix, jpayne@69: * kPadAfterPrefix, kPadBeforeSuffix, or jpayne@69: * kPadAfterSuffix. jpayne@69: * @see #setFormatWidth jpayne@69: * @see #getFormatWidth jpayne@69: * @see #setPadCharacter jpayne@69: * @see #getPadCharacterString jpayne@69: * @see #getPadPosition jpayne@69: * @see #EPadPosition jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setPadPosition(EPadPosition padPos); jpayne@69: jpayne@69: /** jpayne@69: * Return whether or not scientific notation is used. jpayne@69: * @return TRUE if this object formats and parses scientific notation jpayne@69: * @see #setScientificNotation jpayne@69: * @see #getMinimumExponentDigits jpayne@69: * @see #setMinimumExponentDigits jpayne@69: * @see #isExponentSignAlwaysShown jpayne@69: * @see #setExponentSignAlwaysShown jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool isScientificNotation(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set whether or not scientific notation is used. When scientific notation jpayne@69: * is used, the effective maximum number of integer digits is <= 8. If the jpayne@69: * maximum number of integer digits is set to more than 8, the effective jpayne@69: * maximum will be 1. This allows this call to generate a 'default' scientific jpayne@69: * number format without additional changes. jpayne@69: * @param useScientific TRUE if this object formats and parses scientific jpayne@69: * notation jpayne@69: * @see #isScientificNotation jpayne@69: * @see #getMinimumExponentDigits jpayne@69: * @see #setMinimumExponentDigits jpayne@69: * @see #isExponentSignAlwaysShown jpayne@69: * @see #setExponentSignAlwaysShown jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setScientificNotation(UBool useScientific); jpayne@69: jpayne@69: /** jpayne@69: * Return the minimum exponent digits that will be shown. jpayne@69: * @return the minimum exponent digits that will be shown jpayne@69: * @see #setScientificNotation jpayne@69: * @see #isScientificNotation jpayne@69: * @see #setMinimumExponentDigits jpayne@69: * @see #isExponentSignAlwaysShown jpayne@69: * @see #setExponentSignAlwaysShown jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int8_t getMinimumExponentDigits(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the minimum exponent digits that will be shown. This has no jpayne@69: * effect unless scientific notation is in use. jpayne@69: * @param minExpDig a value >= 1 indicating the fewest exponent digits jpayne@69: * that will be shown. Values less than 1 will be treated as 1. jpayne@69: * @see #setScientificNotation jpayne@69: * @see #isScientificNotation jpayne@69: * @see #getMinimumExponentDigits jpayne@69: * @see #isExponentSignAlwaysShown jpayne@69: * @see #setExponentSignAlwaysShown jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setMinimumExponentDigits(int8_t minExpDig); jpayne@69: jpayne@69: /** jpayne@69: * Return whether the exponent sign is always shown. jpayne@69: * @return TRUE if the exponent is always prefixed with either the jpayne@69: * localized minus sign or the localized plus sign, false if only negative jpayne@69: * exponents are prefixed with the localized minus sign. jpayne@69: * @see #setScientificNotation jpayne@69: * @see #isScientificNotation jpayne@69: * @see #setMinimumExponentDigits jpayne@69: * @see #getMinimumExponentDigits jpayne@69: * @see #setExponentSignAlwaysShown jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool isExponentSignAlwaysShown(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set whether the exponent sign is always shown. This has no effect jpayne@69: * unless scientific notation is in use. jpayne@69: * @param expSignAlways TRUE if the exponent is always prefixed with either jpayne@69: * the localized minus sign or the localized plus sign, false if only jpayne@69: * negative exponents are prefixed with the localized minus sign. jpayne@69: * @see #setScientificNotation jpayne@69: * @see #isScientificNotation jpayne@69: * @see #setMinimumExponentDigits jpayne@69: * @see #getMinimumExponentDigits jpayne@69: * @see #isExponentSignAlwaysShown jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setExponentSignAlwaysShown(UBool expSignAlways); jpayne@69: jpayne@69: /** jpayne@69: * Return the grouping size. Grouping size is the number of digits between jpayne@69: * grouping separators in the integer portion of a number. For example, jpayne@69: * in the number "123,456.78", the grouping size is 3. jpayne@69: * jpayne@69: * @return the grouping size. jpayne@69: * @see setGroupingSize jpayne@69: * @see NumberFormat::isGroupingUsed jpayne@69: * @see DecimalFormatSymbols::getGroupingSeparator jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: int32_t getGroupingSize(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the grouping size. Grouping size is the number of digits between jpayne@69: * grouping separators in the integer portion of a number. For example, jpayne@69: * in the number "123,456.78", the grouping size is 3. jpayne@69: * jpayne@69: * @param newValue the new value of the grouping size. jpayne@69: * @see getGroupingSize jpayne@69: * @see NumberFormat::setGroupingUsed jpayne@69: * @see DecimalFormatSymbols::setGroupingSeparator jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setGroupingSize(int32_t newValue); jpayne@69: jpayne@69: /** jpayne@69: * Return the secondary grouping size. In some locales one jpayne@69: * grouping interval is used for the least significant integer jpayne@69: * digits (the primary grouping size), and another is used for all jpayne@69: * others (the secondary grouping size). A formatter supporting a jpayne@69: * secondary grouping size will return a positive integer unequal jpayne@69: * to the primary grouping size returned by jpayne@69: * getGroupingSize(). For example, if the primary jpayne@69: * grouping size is 4, and the secondary grouping size is 2, then jpayne@69: * the number 123456789 formats as "1,23,45,6789", and the pattern jpayne@69: * appears as "#,##,###0". jpayne@69: * @return the secondary grouping size, or a value less than jpayne@69: * one if there is none jpayne@69: * @see setSecondaryGroupingSize jpayne@69: * @see NumberFormat::isGroupingUsed jpayne@69: * @see DecimalFormatSymbols::getGroupingSeparator jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: int32_t getSecondaryGroupingSize(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Set the secondary grouping size. If set to a value less than 1, jpayne@69: * then secondary grouping is turned off, and the primary grouping jpayne@69: * size is used for all intervals, not just the least significant. jpayne@69: * jpayne@69: * @param newValue the new value of the secondary grouping size. jpayne@69: * @see getSecondaryGroupingSize jpayne@69: * @see NumberFormat#setGroupingUsed jpayne@69: * @see DecimalFormatSymbols::setGroupingSeparator jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual void setSecondaryGroupingSize(int32_t newValue); jpayne@69: jpayne@69: /** jpayne@69: * Returns the minimum number of grouping digits. jpayne@69: * Grouping separators are output if there are at least this many jpayne@69: * digits to the left of the first (rightmost) grouping separator, jpayne@69: * that is, there are at least (minimum grouping + grouping size) integer digits. jpayne@69: * (Subject to isGroupingUsed().) jpayne@69: * jpayne@69: * For example, if this value is 2, and the grouping size is 3, then jpayne@69: * 9999 -> "9999" and 10000 -> "10,000" jpayne@69: * jpayne@69: * The default value for this attribute is 0. jpayne@69: * A value of 1, 0, or lower, means that the use of grouping separators jpayne@69: * only depends on the grouping size (and on isGroupingUsed()). jpayne@69: * jpayne@69: * NOTE: The CLDR data is used in NumberFormatter but not in DecimalFormat. jpayne@69: * This is for backwards compatibility reasons. jpayne@69: * jpayne@69: * For more control over grouping strategies, use NumberFormatter. jpayne@69: * jpayne@69: * @see setMinimumGroupingDigits jpayne@69: * @see getGroupingSize jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: int32_t getMinimumGroupingDigits() const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the minimum grouping digits. Setting to a value less than or jpayne@69: * equal to 1 turns off minimum grouping digits. jpayne@69: * jpayne@69: * For more control over grouping strategies, use NumberFormatter. jpayne@69: * jpayne@69: * @param newValue the new value of minimum grouping digits. jpayne@69: * @see getMinimumGroupingDigits jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: void setMinimumGroupingDigits(int32_t newValue); jpayne@69: jpayne@69: /** jpayne@69: * Allows you to get the behavior of the decimal separator with integers. jpayne@69: * (The decimal separator will always appear with decimals.) jpayne@69: * jpayne@69: * @return TRUE if the decimal separator always appear with decimals. jpayne@69: * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool isDecimalSeparatorAlwaysShown(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Allows you to set the behavior of the decimal separator with integers. jpayne@69: * (The decimal separator will always appear with decimals.) jpayne@69: * jpayne@69: * @param newValue set TRUE if the decimal separator will always appear with decimals. jpayne@69: * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setDecimalSeparatorAlwaysShown(UBool newValue); jpayne@69: jpayne@69: /** jpayne@69: * Allows you to get the parse behavior of the pattern decimal mark. jpayne@69: * jpayne@69: * @return TRUE if input must contain a match to decimal mark in pattern jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: UBool isDecimalPatternMatchRequired(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Allows you to set the parse behavior of the pattern decimal mark. jpayne@69: * jpayne@69: * if TRUE, the input must have a decimal mark if one was specified in the pattern. When jpayne@69: * FALSE the decimal mark may be omitted from the input. jpayne@69: * jpayne@69: * @param newValue set TRUE if input must contain a match to decimal mark in pattern jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: virtual void setDecimalPatternMatchRequired(UBool newValue); jpayne@69: jpayne@69: /** jpayne@69: * Returns whether to ignore exponents when parsing. jpayne@69: * jpayne@69: * @return Whether to ignore exponents when parsing. jpayne@69: * @see #setParseNoExponent jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: UBool isParseNoExponent() const; jpayne@69: jpayne@69: /** jpayne@69: * Specifies whether to stop parsing when an exponent separator is encountered. For jpayne@69: * example, parses "123E4" to 123 (with parse position 3) instead of 1230000 (with parse position jpayne@69: * 5). jpayne@69: * jpayne@69: * @param value true to prevent exponents from being parsed; false to allow them to be parsed. jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: void setParseNoExponent(UBool value); jpayne@69: jpayne@69: /** jpayne@69: * Returns whether parsing is sensitive to case (lowercase/uppercase). jpayne@69: * jpayne@69: * @return Whether parsing is case-sensitive. jpayne@69: * @see #setParseCaseSensitive jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: UBool isParseCaseSensitive() const; jpayne@69: jpayne@69: /** jpayne@69: * Whether to pay attention to case when parsing; default is to ignore case (perform jpayne@69: * case-folding). For example, "A" == "a" in case-insensitive but not case-sensitive mode. jpayne@69: * jpayne@69: * Currency symbols are never case-folded. For example, "us$1.00" will not parse in case-insensitive jpayne@69: * mode, even though "US$1.00" parses. jpayne@69: * jpayne@69: * @param value true to enable case-sensitive parsing (the default); false to force jpayne@69: * case-sensitive parsing behavior. jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: void setParseCaseSensitive(UBool value); jpayne@69: jpayne@69: /** jpayne@69: * Returns whether truncation of high-order integer digits should result in an error. jpayne@69: * By default, setMaximumIntegerDigits truncates high-order digits silently. jpayne@69: * jpayne@69: * @return Whether an error code is set if high-order digits are truncated. jpayne@69: * @see setFormatFailIfMoreThanMaxDigits jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: UBool isFormatFailIfMoreThanMaxDigits() const; jpayne@69: jpayne@69: /** jpayne@69: * Sets whether truncation of high-order integer digits should result in an error. jpayne@69: * By default, setMaximumIntegerDigits truncates high-order digits silently. jpayne@69: * jpayne@69: * @param value Whether to set an error code if high-order digits are truncated. jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: void setFormatFailIfMoreThanMaxDigits(UBool value); jpayne@69: jpayne@69: /** jpayne@69: * Synthesizes a pattern string that represents the current state jpayne@69: * of this Format object. jpayne@69: * jpayne@69: * @param result Output param which will receive the pattern. jpayne@69: * Previous contents are deleted. jpayne@69: * @return A reference to 'result'. jpayne@69: * @see applyPattern jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UnicodeString& toPattern(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Synthesizes a localized pattern string that represents the current jpayne@69: * state of this Format object. jpayne@69: * jpayne@69: * @param result Output param which will receive the localized pattern. jpayne@69: * Previous contents are deleted. jpayne@69: * @return A reference to 'result'. jpayne@69: * @see applyPattern jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Apply the given pattern to this Format object. A pattern is a jpayne@69: * short-hand specification for the various formatting properties. jpayne@69: * These properties can also be changed individually through the jpayne@69: * various setter methods. jpayne@69: *

jpayne@69: * There is no limit to integer digits are set jpayne@69: * by this routine, since that is the typical end-user desire; jpayne@69: * use setMaximumInteger if you want to set a real value. jpayne@69: * For negative numbers, use a second pattern, separated by a semicolon jpayne@69: *

jpayne@69:      * .      Example "#,#00.0#" -> 1,234.56
jpayne@69:      * 
jpayne@69: * This means a minimum of 2 integer digits, 1 fraction digit, and jpayne@69: * a maximum of 2 fraction digits. jpayne@69: *
jpayne@69:      * .      Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
jpayne@69:      * 
jpayne@69: * In negative patterns, the minimum and maximum counts are ignored; jpayne@69: * these are presumed to be set in the positive pattern. jpayne@69: * jpayne@69: * @param pattern The pattern to be applied. jpayne@69: * @param parseError Struct to recieve information on position jpayne@69: * of error if an error is encountered jpayne@69: * @param status Output param set to success/failure code on jpayne@69: * exit. If the pattern is invalid, this will be jpayne@69: * set to a failure result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void applyPattern(const UnicodeString& pattern, UParseError& parseError, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the pattern. jpayne@69: * @param pattern The pattern to be applied. jpayne@69: * @param status Output param set to success/failure code on jpayne@69: * exit. If the pattern is invalid, this will be jpayne@69: * set to a failure result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void applyPattern(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Apply the given pattern to this Format object. The pattern jpayne@69: * is assumed to be in a localized notation. A pattern is a jpayne@69: * short-hand specification for the various formatting properties. jpayne@69: * These properties can also be changed individually through the jpayne@69: * various setter methods. jpayne@69: *

jpayne@69: * There is no limit to integer digits are set jpayne@69: * by this routine, since that is the typical end-user desire; jpayne@69: * use setMaximumInteger if you want to set a real value. jpayne@69: * For negative numbers, use a second pattern, separated by a semicolon jpayne@69: *

jpayne@69:      * .      Example "#,#00.0#" -> 1,234.56
jpayne@69:      * 
jpayne@69: * This means a minimum of 2 integer digits, 1 fraction digit, and jpayne@69: * a maximum of 2 fraction digits. jpayne@69: * jpayne@69: * Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses. jpayne@69: * jpayne@69: * In negative patterns, the minimum and maximum counts are ignored; jpayne@69: * these are presumed to be set in the positive pattern. jpayne@69: * jpayne@69: * @param pattern The localized pattern to be applied. jpayne@69: * @param parseError Struct to recieve information on position jpayne@69: * of error if an error is encountered jpayne@69: * @param status Output param set to success/failure code on jpayne@69: * exit. If the pattern is invalid, this will be jpayne@69: * set to a failure result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void applyLocalizedPattern(const UnicodeString& pattern, UParseError& parseError, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Apply the given pattern to this Format object. jpayne@69: * jpayne@69: * @param pattern The localized pattern to be applied. jpayne@69: * @param status Output param set to success/failure code on jpayne@69: * exit. If the pattern is invalid, this will be jpayne@69: * set to a failure result. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void applyLocalizedPattern(const UnicodeString& pattern, UErrorCode& status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Sets the maximum number of digits allowed in the integer portion of a jpayne@69: * number. This override limits the integer digit count to 309. jpayne@69: * jpayne@69: * @param newValue the new value of the maximum number of digits jpayne@69: * allowed in the integer portion of a number. jpayne@69: * @see NumberFormat#setMaximumIntegerDigits jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setMaximumIntegerDigits(int32_t newValue) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Sets the minimum number of digits allowed in the integer portion of a jpayne@69: * number. This override limits the integer digit count to 309. jpayne@69: * jpayne@69: * @param newValue the new value of the minimum number of digits jpayne@69: * allowed in the integer portion of a number. jpayne@69: * @see NumberFormat#setMinimumIntegerDigits jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setMinimumIntegerDigits(int32_t newValue) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Sets the maximum number of digits allowed in the fraction portion of a jpayne@69: * number. This override limits the fraction digit count to 340. jpayne@69: * jpayne@69: * @param newValue the new value of the maximum number of digits jpayne@69: * allowed in the fraction portion of a number. jpayne@69: * @see NumberFormat#setMaximumFractionDigits jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setMaximumFractionDigits(int32_t newValue) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Sets the minimum number of digits allowed in the fraction portion of a jpayne@69: * number. This override limits the fraction digit count to 340. jpayne@69: * jpayne@69: * @param newValue the new value of the minimum number of digits jpayne@69: * allowed in the fraction portion of a number. jpayne@69: * @see NumberFormat#setMinimumFractionDigits jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setMinimumFractionDigits(int32_t newValue) U_OVERRIDE; jpayne@69: jpayne@69: /** jpayne@69: * Returns the minimum number of significant digits that will be jpayne@69: * displayed. This value has no effect unless areSignificantDigitsUsed() jpayne@69: * returns true. jpayne@69: * @return the fewest significant digits that will be shown jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: int32_t getMinimumSignificantDigits() const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the maximum number of significant digits that will be jpayne@69: * displayed. This value has no effect unless areSignificantDigitsUsed() jpayne@69: * returns true. jpayne@69: * @return the most significant digits that will be shown jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: int32_t getMaximumSignificantDigits() const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the minimum number of significant digits that will be jpayne@69: * displayed. If min is less than one then it is set jpayne@69: * to one. If the maximum significant digits count is less than jpayne@69: * min, then it is set to min. jpayne@69: * This function also enables the use of significant digits jpayne@69: * by this formatter - areSignificantDigitsUsed() will return TRUE. jpayne@69: * @see #areSignificantDigitsUsed jpayne@69: * @param min the fewest significant digits to be shown jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: void setMinimumSignificantDigits(int32_t min); jpayne@69: jpayne@69: /** jpayne@69: * Sets the maximum number of significant digits that will be jpayne@69: * displayed. If max is less than one then it is set jpayne@69: * to one. If the minimum significant digits count is greater jpayne@69: * than max, then it is set to max. jpayne@69: * This function also enables the use of significant digits jpayne@69: * by this formatter - areSignificantDigitsUsed() will return TRUE. jpayne@69: * @see #areSignificantDigitsUsed jpayne@69: * @param max the most significant digits to be shown jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: void setMaximumSignificantDigits(int32_t max); jpayne@69: jpayne@69: /** jpayne@69: * Returns true if significant digits are in use, or false if jpayne@69: * integer and fraction digit counts are in use. jpayne@69: * @return true if significant digits are in use jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: UBool areSignificantDigitsUsed() const; jpayne@69: jpayne@69: /** jpayne@69: * Sets whether significant digits are in use, or integer and jpayne@69: * fraction digit counts are in use. jpayne@69: * @param useSignificantDigits true to use significant digits, or jpayne@69: * false to use integer and fraction digit counts jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: void setSignificantDigitsUsed(UBool useSignificantDigits); jpayne@69: jpayne@69: /** jpayne@69: * Sets the currency used to display currency jpayne@69: * amounts. This takes effect immediately, if this format is a jpayne@69: * currency format. If this format is not a currency format, then jpayne@69: * the currency is used if and when this object becomes a jpayne@69: * currency format through the application of a new pattern. jpayne@69: * @param theCurrency a 3-letter ISO code indicating new currency jpayne@69: * to use. It need not be null-terminated. May be the empty jpayne@69: * string or NULL to indicate no currency. jpayne@69: * @param ec input-output error code jpayne@69: * @stable ICU 3.0 jpayne@69: */ jpayne@69: void setCurrency(const char16_t* theCurrency, UErrorCode& ec) U_OVERRIDE; jpayne@69: jpayne@69: #ifndef U_FORCE_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Sets the currency used to display currency amounts. See jpayne@69: * setCurrency(const char16_t*, UErrorCode&). jpayne@69: * @deprecated ICU 3.0. Use setCurrency(const char16_t*, UErrorCode&). jpayne@69: */ jpayne@69: virtual void setCurrency(const char16_t* theCurrency); jpayne@69: #endif // U_FORCE_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Sets the `Currency Usage` object used to display currency. jpayne@69: * This takes effect immediately, if this format is a jpayne@69: * currency format. jpayne@69: * @param newUsage new currency usage object to use. jpayne@69: * @param ec input-output error code jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: void setCurrencyUsage(UCurrencyUsage newUsage, UErrorCode* ec); jpayne@69: jpayne@69: /** jpayne@69: * Returns the `Currency Usage` object used to display currency jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: UCurrencyUsage getCurrencyUsage() const; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: jpayne@69: /** jpayne@69: * Format a number and save it into the given DecimalQuantity. jpayne@69: * Internal, not intended for public use. jpayne@69: * @internal jpayne@69: */ jpayne@69: void formatToDecimalQuantity(double number, number::impl::DecimalQuantity& output, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Get a DecimalQuantity corresponding to a formattable as it would be jpayne@69: * formatted by this DecimalFormat. jpayne@69: * Internal, not intended for public use. jpayne@69: * @internal jpayne@69: */ jpayne@69: void formatToDecimalQuantity(const Formattable& number, number::impl::DecimalQuantity& output, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Converts this DecimalFormat to a (Localized)NumberFormatter. Starting jpayne@69: * in ICU 60, NumberFormatter is the recommended way to format numbers. jpayne@69: * You can use the returned LocalizedNumberFormatter to format numbers and jpayne@69: * get a FormattedNumber, which contains a string as well as additional jpayne@69: * annotations about the formatted value. jpayne@69: * jpayne@69: * If a memory allocation failure occurs, the return value of this method jpayne@69: * might be null. If you are concerned about correct recovery from jpayne@69: * out-of-memory situations, use this pattern: jpayne@69: * jpayne@69: *
jpayne@69:      * FormattedNumber result;
jpayne@69:      * if (auto* ptr = df->toNumberFormatter(status)) {
jpayne@69:      *     result = ptr->formatDouble(123, status);
jpayne@69:      * }
jpayne@69:      * 
jpayne@69: * jpayne@69: * If you are not concerned about out-of-memory situations, or if your jpayne@69: * environment throws exceptions when memory allocation failure occurs, jpayne@69: * you can chain the methods, like this: jpayne@69: * jpayne@69: *
jpayne@69:      * FormattedNumber result = df
jpayne@69:      *     ->toNumberFormatter(status)
jpayne@69:      *     ->formatDouble(123, status);
jpayne@69:      * 
jpayne@69: * jpayne@69: * NOTE: The returned LocalizedNumberFormatter is owned by this DecimalFormat. jpayne@69: * If a non-const method is called on the DecimalFormat, or if the DecimalFormat jpayne@69: * is deleted, the object becomes invalid. If you plan to keep the return value jpayne@69: * beyond the lifetime of the DecimalFormat, copy it to a local variable: jpayne@69: * jpayne@69: *
jpayne@69:      * LocalizedNumberFormatter lnf;
jpayne@69:      * if (auto* ptr = df->toNumberFormatter(status)) {
jpayne@69:      *     lnf = *ptr;
jpayne@69:      * }
jpayne@69:      * 
jpayne@69: * jpayne@69: * @param status Set on failure, like U_MEMORY_ALLOCATION_ERROR. jpayne@69: * @return A pointer to an internal object, or nullptr on failure. jpayne@69: * Do not delete the return value! jpayne@69: * @stable ICU 64 jpayne@69: */ jpayne@69: const number::LocalizedNumberFormatter* toNumberFormatter(UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for jpayne@69: * comparing to a return value from getDynamicClassID(). For example: jpayne@69: *
jpayne@69:      * .      Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .      if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .          Derived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. jpayne@69: * This method is to implement a simple version of RTTI, since not all jpayne@69: * C++ compilers support genuine RTTI. Polymorphic operator==() and jpayne@69: * clone() methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UClassID getDynamicClassID(void) const U_OVERRIDE; jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: /** Rebuilds the formatter object from the property bag. */ jpayne@69: void touch(UErrorCode& status); jpayne@69: jpayne@69: /** Rebuilds the formatter object, ignoring any error code. */ jpayne@69: void touchNoError(); jpayne@69: jpayne@69: /** jpayne@69: * Updates the property bag with settings from the given pattern. jpayne@69: * jpayne@69: * @param pattern The pattern string to parse. jpayne@69: * @param ignoreRounding Whether to leave out rounding information (minFrac, maxFrac, and rounding jpayne@69: * increment) when parsing the pattern. This may be desirable if a custom rounding mode, such jpayne@69: * as CurrencyUsage, is to be used instead. One of {@link jpayne@69: * PatternStringParser#IGNORE_ROUNDING_ALWAYS}, {@link PatternStringParser#IGNORE_ROUNDING_IF_CURRENCY}, jpayne@69: * or {@link PatternStringParser#IGNORE_ROUNDING_NEVER}. jpayne@69: * @see PatternAndPropertyUtils#parseToExistingProperties jpayne@69: */ jpayne@69: void setPropertiesFromPattern(const UnicodeString& pattern, int32_t ignoreRounding, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: const numparse::impl::NumberParserImpl* getParser(UErrorCode& status) const; jpayne@69: jpayne@69: const numparse::impl::NumberParserImpl* getCurrencyParser(UErrorCode& status) const; jpayne@69: jpayne@69: static void fieldPositionHelper( jpayne@69: const number::impl::UFormattedNumberData& formatted, jpayne@69: FieldPosition& fieldPosition, jpayne@69: int32_t offset, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: static void fieldPositionIteratorHelper( jpayne@69: const number::impl::UFormattedNumberData& formatted, jpayne@69: FieldPositionIterator* fpi, jpayne@69: int32_t offset, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: void setupFastFormat(); jpayne@69: jpayne@69: bool fastFormatDouble(double input, UnicodeString& output) const; jpayne@69: jpayne@69: bool fastFormatInt64(int64_t input, UnicodeString& output) const; jpayne@69: jpayne@69: void doFastFormatInt32(int32_t input, bool isNegative, UnicodeString& output) const; jpayne@69: jpayne@69: //=====================================================================================// jpayne@69: // INSTANCE FIELDS // jpayne@69: //=====================================================================================// jpayne@69: jpayne@69: jpayne@69: // One instance field for the implementation, keep all fields inside of an implementation jpayne@69: // class defined in number_mapper.h jpayne@69: number::impl::DecimalFormatFields* fields = nullptr; jpayne@69: jpayne@69: // Allow child class CompactDecimalFormat to access fProperties: jpayne@69: friend class CompactDecimalFormat; jpayne@69: jpayne@69: // Allow MeasureFormat to use fieldPositionHelper: jpayne@69: friend class MeasureFormat; jpayne@69: jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // _DECIMFMT jpayne@69: //eof