decimfmt.h 91 KB

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