decimfmt.h 90 KB

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