ICU 50.2 50.2
decimfmt.h
Go to the documentation of this file.
1/*
2********************************************************************************
3* Copyright (C) 1997-2012, 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********************************************************************************
22*/
23
24#ifndef DECIMFMT_H
25#define DECIMFMT_H
26
27#include "unicode/utypes.h"
32
33#if !UCONFIG_NO_FORMATTING
34
35#include "unicode/dcfmtsym.h"
36#include "unicode/numfmt.h"
37#include "unicode/locid.h"
38#include "unicode/fpositer.h"
39#include "unicode/stringpiece.h"
40#include "unicode/curramt.h"
41#include "unicode/enumset.h"
42
47#if UCONFIG_FORMAT_FASTPATHS_49
48#define UNUM_DECIMALFORMAT_INTERNAL_SIZE 16
49#endif
50
52
53class DigitList;
54class ChoiceFormat;
56class Hashtable;
57class UnicodeSet;
58class FieldPositionHandler;
59
60// explicit template instantiation. see digitlst.h
61#if defined (_MSC_VER)
65#endif
66
661public:
683
689 kPadBeforePrefix,
690 kPadAfterPrefix,
691 kPadBeforeSuffix,
692 kPadAfterSuffix
693 };
694
709
725 UErrorCode& status);
726
746 DecimalFormatSymbols* symbolsToAdopt,
747 UErrorCode& status);
748
749#ifndef U_HIDE_INTERNAL_API
763 DecimalFormatSymbols* symbolsToAdopt,
764 UNumberFormatStyle style,
765 UErrorCode& status);
766
767
779 int32_t newvalue,
780 UErrorCode &status);
781
792 UErrorCode &status) const;
793
794#if UCONFIG_HAVE_PARSEALLINPUT
798 void setParseAllInput(UNumberFormatAttributeValue value);
799#endif
800
801#endif /* U_HIDE_INTERNAL_API */
802
823 DecimalFormatSymbols* symbolsToAdopt,
824 UParseError& parseError,
825 UErrorCode& status);
844 const DecimalFormatSymbols& symbols,
845 UErrorCode& status);
846
854
862
867 virtual ~DecimalFormat();
868
876 virtual Format* clone(void) const;
877
886 virtual UBool operator==(const Format& other) const;
887
888
890
902 virtual UnicodeString& format(double number,
903 UnicodeString& appendTo,
904 FieldPosition& pos) const;
905
906
919 virtual UnicodeString& format(double number,
920 UnicodeString& appendTo,
921 FieldPosition& pos,
922 UErrorCode &status) const;
923
937 virtual UnicodeString& format(double number,
938 UnicodeString& appendTo,
939 FieldPositionIterator* posIter,
940 UErrorCode& status) const;
941
953 virtual UnicodeString& format(int32_t number,
954 UnicodeString& appendTo,
955 FieldPosition& pos) const;
956
968 virtual UnicodeString& format(int32_t number,
969 UnicodeString& appendTo,
970 FieldPosition& pos,
971 UErrorCode &status) const;
972
986 virtual UnicodeString& format(int32_t number,
987 UnicodeString& appendTo,
988 FieldPositionIterator* posIter,
989 UErrorCode& status) const;
990
1002 virtual UnicodeString& format(int64_t number,
1003 UnicodeString& appendTo,
1004 FieldPosition& pos) const;
1005
1017 virtual UnicodeString& format(int64_t number,
1018 UnicodeString& appendTo,
1019 FieldPosition& pos,
1020 UErrorCode &status) const;
1021
1035 virtual UnicodeString& format(int64_t number,
1036 UnicodeString& appendTo,
1037 FieldPositionIterator* posIter,
1038 UErrorCode& status) const;
1039
1056 virtual UnicodeString& format(const StringPiece &number,
1057 UnicodeString& appendTo,
1058 FieldPositionIterator* posIter,
1059 UErrorCode& status) const;
1060
1061
1077 virtual UnicodeString& format(const DigitList &number,
1078 UnicodeString& appendTo,
1079 FieldPositionIterator* posIter,
1080 UErrorCode& status) const;
1081
1097 virtual UnicodeString& format(const DigitList &number,
1098 UnicodeString& appendTo,
1099 FieldPosition& pos,
1100 UErrorCode& status) const;
1101
1102
1115 virtual UnicodeString& format(const Formattable& obj,
1116 UnicodeString& appendTo,
1117 FieldPosition& pos,
1118 UErrorCode& status) const;
1119
1131 UnicodeString& format(const Formattable& obj,
1132 UnicodeString& appendTo,
1133 UErrorCode& status) const;
1134
1145 UnicodeString& format(double number,
1146 UnicodeString& appendTo) const;
1147
1159 UnicodeString& format(int32_t number,
1160 UnicodeString& appendTo) const;
1161
1173 UnicodeString& format(int64_t number,
1174 UnicodeString& appendTo) const;
1194 virtual void parse(const UnicodeString& text,
1195 Formattable& result,
1196 ParsePosition& parsePosition) const;
1197
1198 // Declare here again to get rid of function hiding problems.
1207 virtual void parse(const UnicodeString& text,
1208 Formattable& result,
1209 UErrorCode& status) const;
1210
1211/* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
1232 ParsePosition& pos) const;
1233
1242
1250
1257 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1258
1259
1266 virtual const CurrencyPluralInfo* getCurrencyPluralInfo(void) const;
1267
1275
1283
1284
1294
1302 virtual void setPositivePrefix(const UnicodeString& newValue);
1303
1313
1321 virtual void setNegativePrefix(const UnicodeString& newValue);
1322
1332
1340 virtual void setPositiveSuffix(const UnicodeString& newValue);
1341
1351
1359 virtual void setNegativeSuffix(const UnicodeString& newValue);
1360
1371 int32_t getMultiplier(void) const;
1372
1383 virtual void setMultiplier(int32_t newValue);
1384
1394 virtual double getRoundingIncrement(void) const;
1395
1406 virtual void setRoundingIncrement(double newValue);
1407
1416 virtual ERoundingMode getRoundingMode(void) const;
1417
1426 virtual void setRoundingMode(ERoundingMode roundingMode);
1427
1439 virtual int32_t getFormatWidth(void) const;
1440
1455 virtual void setFormatWidth(int32_t width);
1456
1470
1485 virtual void setPadCharacter(const UnicodeString &padChar);
1486
1502 virtual EPadPosition getPadPosition(void) const;
1503
1520 virtual void setPadPosition(EPadPosition padPos);
1521
1533
1549 virtual void setScientificNotation(UBool useScientific);
1550
1561 virtual int8_t getMinimumExponentDigits(void) const;
1562
1575 virtual void setMinimumExponentDigits(int8_t minExpDig);
1576
1590
1604 virtual void setExponentSignAlwaysShown(UBool expSignAlways);
1605
1617 int32_t getGroupingSize(void) const;
1618
1630 virtual void setGroupingSize(int32_t newValue);
1631
1650 int32_t getSecondaryGroupingSize(void) const;
1651
1663 virtual void setSecondaryGroupingSize(int32_t newValue);
1664
1674
1684
1695 virtual UnicodeString& toPattern(UnicodeString& result) const;
1696
1708
1738 virtual void applyPattern(const UnicodeString& pattern,
1739 UParseError& parseError,
1740 UErrorCode& status);
1749 virtual void applyPattern(const UnicodeString& pattern,
1750 UErrorCode& status);
1751
1782 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1783 UParseError& parseError,
1784 UErrorCode& status);
1785
1795 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1796 UErrorCode& status);
1797
1798
1808 virtual void setMaximumIntegerDigits(int32_t newValue);
1809
1819 virtual void setMinimumIntegerDigits(int32_t newValue);
1820
1830 virtual void setMaximumFractionDigits(int32_t newValue);
1831
1841 virtual void setMinimumFractionDigits(int32_t newValue);
1842
1851
1860
1871
1883
1891
1899 void setSignificantDigitsUsed(UBool useSignificantDigits);
1900
1901 public:
1914 virtual void setCurrency(const UChar* theCurrency, UErrorCode& ec);
1915
1921 virtual void setCurrency(const UChar* theCurrency);
1922
1928 static const char fgNumberPatterns[];
1929
1930public:
1931
1943 static UClassID U_EXPORT2 getStaticClassID(void);
1944
1956 virtual UClassID getDynamicClassID(void) const;
1957
1958private:
1959
1960 DecimalFormat(); // default constructor not implemented
1961
1962 int32_t precision() const;
1963
1968 void init(UErrorCode& status);
1969
1973 void construct(UErrorCode& status,
1974 UParseError& parseErr,
1975 const UnicodeString* pattern = 0,
1976 DecimalFormatSymbols* symbolsToAdopt = 0
1977 );
1978
1987 UnicodeString& toPattern(UnicodeString& result, UBool localized) const;
1988
1999 void applyPattern(const UnicodeString& pattern,
2000 UBool localized,
2001 UParseError& parseError,
2002 UErrorCode& status);
2003
2004 /*
2005 * similar to applyPattern, but without re-gen affix for currency
2006 */
2007 void applyPatternInternally(const UnicodeString& pluralCount,
2008 const UnicodeString& pattern,
2009 UBool localized,
2010 UParseError& parseError,
2011 UErrorCode& status);
2012
2013 /*
2014 * only apply pattern without expand affixes
2015 */
2016 void applyPatternWithoutExpandAffix(const UnicodeString& pattern,
2017 UBool localized,
2018 UParseError& parseError,
2019 UErrorCode& status);
2020
2021
2022 /*
2023 * expand affixes (after apply patter) and re-compute fFormatWidth
2024 */
2025 void expandAffixAdjustWidth(const UnicodeString* pluralCount);
2026
2027
2038 UnicodeString& subformat(UnicodeString& appendTo,
2039 FieldPositionHandler& handler,
2040 DigitList& digits,
2041 UBool isInteger,
2042 UErrorCode &status) const;
2043
2044
2045 void parse(const UnicodeString& text,
2046 Formattable& result,
2047 ParsePosition& pos,
2048 UChar* currency) const;
2049
2050 enum {
2051 fgStatusInfinite,
2052 fgStatusLength // Leave last in list.
2053 } StatusFlags;
2054
2055 UBool subparse(const UnicodeString& text,
2056 const UnicodeString* negPrefix,
2057 const UnicodeString* negSuffix,
2058 const UnicodeString* posPrefix,
2059 const UnicodeString* posSuffix,
2060 UBool currencyParsing,
2061 int8_t type,
2062 ParsePosition& parsePosition,
2063 DigitList& digits, UBool* status,
2064 UChar* currency) const;
2065
2066 // Mixed style parsing for currency.
2067 // It parses against the current currency pattern
2068 // using complex affix comparison
2069 // parses against the currency plural patterns using complex affix comparison,
2070 // and parses against the current pattern using simple affix comparison.
2071 UBool parseForCurrency(const UnicodeString& text,
2072 ParsePosition& parsePosition,
2073 DigitList& digits,
2074 UBool* status,
2075 UChar* currency) const;
2076
2077 int32_t skipPadding(const UnicodeString& text, int32_t position) const;
2078
2079 int32_t compareAffix(const UnicodeString& input,
2080 int32_t pos,
2081 UBool isNegative,
2082 UBool isPrefix,
2083 const UnicodeString* affixPat,
2084 UBool currencyParsing,
2085 int8_t type,
2086 UChar* currency) const;
2087
2088 static int32_t compareSimpleAffix(const UnicodeString& affix,
2089 const UnicodeString& input,
2090 int32_t pos,
2091 UBool lenient);
2092
2093 static int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos);
2094
2095 static int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos);
2096
2097 int32_t compareComplexAffix(const UnicodeString& affixPat,
2098 const UnicodeString& input,
2099 int32_t pos,
2100 int8_t type,
2101 UChar* currency) const;
2102
2103 static int32_t match(const UnicodeString& text, int32_t pos, UChar32 ch);
2104
2105 static int32_t match(const UnicodeString& text, int32_t pos, const UnicodeString& str);
2106
2107 static UBool matchSymbol(const UnicodeString &text, int32_t position, int32_t length, const UnicodeString &symbol,
2108 UnicodeSet *sset, UChar32 schar);
2109
2110 static UBool matchDecimal(UChar32 symbolChar,
2111 UBool sawDecimal, UChar32 sawDecimalChar,
2112 const UnicodeSet *sset, UChar32 schar);
2113
2114 static UBool matchGrouping(UChar32 groupingChar,
2115 UBool sawGrouping, UChar32 sawGroupingChar,
2116 const UnicodeSet *sset,
2117 UChar32 decimalChar, const UnicodeSet *decimalSet,
2118 UChar32 schar);
2119
2125 inline const UnicodeString &getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const;
2126
2127 int32_t appendAffix(UnicodeString& buf,
2128 double number,
2129 FieldPositionHandler& handler,
2130 UBool isNegative,
2131 UBool isPrefix) const;
2132
2138 void appendAffixPattern(UnicodeString& appendTo, const UnicodeString& affix,
2139 UBool localized) const;
2140
2141 void appendAffixPattern(UnicodeString& appendTo,
2142 const UnicodeString* affixPattern,
2143 const UnicodeString& expAffix, UBool localized) const;
2144
2145 void expandAffix(const UnicodeString& pattern,
2146 UnicodeString& affix,
2147 double number,
2148 FieldPositionHandler& handler,
2149 UBool doFormat,
2150 const UnicodeString* pluralCount) const;
2151
2152 void expandAffixes(const UnicodeString* pluralCount);
2153
2154 void addPadding(UnicodeString& appendTo,
2155 FieldPositionHandler& handler,
2156 int32_t prefixLen, int32_t suffixLen) const;
2157
2158 UBool isGroupingPosition(int32_t pos) const;
2159
2160 void setCurrencyForSymbols();
2161
2162 // similar to setCurrency without re-compute the affixes for currency.
2163 // If currency changes, the affix pattern for currency is not changed,
2164 // but the affix will be changed. So, affixes need to be
2165 // re-computed in setCurrency(), but not in setCurrencyInternally().
2166 virtual void setCurrencyInternally(const UChar* theCurrency, UErrorCode& ec);
2167
2168 // set up currency affix patterns for mix parsing.
2169 // The patterns saved here are the affix patterns of default currency
2170 // pattern and the unique affix patterns of the plural currency patterns.
2171 // Those patterns are used by parseForCurrency().
2172 void setupCurrencyAffixPatterns(UErrorCode& status);
2173
2174 // set up the currency affixes used in currency plural formatting.
2175 // It sets up both fAffixesForCurrency for currency pattern if the current
2176 // pattern contains 3 currency signs,
2177 // and it sets up fPluralAffixesForCurrency for currency plural patterns.
2178 void setupCurrencyAffixes(const UnicodeString& pattern,
2179 UBool setupForCurrentPattern,
2180 UBool setupForPluralPattern,
2181 UErrorCode& status);
2182
2183 // hashtable operations
2184 Hashtable* initHashForAffixPattern(UErrorCode& status);
2185 Hashtable* initHashForAffix(UErrorCode& status);
2186
2187 void deleteHashForAffixPattern();
2188 void deleteHashForAffix(Hashtable*& table);
2189
2190 void copyHashForAffixPattern(const Hashtable* source,
2191 Hashtable* target, UErrorCode& status);
2192 void copyHashForAffix(const Hashtable* source,
2193 Hashtable* target, UErrorCode& status);
2194
2195 UnicodeString& _format(int64_t number,
2196 UnicodeString& appendTo,
2197 FieldPositionHandler& handler,
2198 UErrorCode &status) const;
2199 UnicodeString& _format(double number,
2200 UnicodeString& appendTo,
2201 FieldPositionHandler& handler,
2202 UErrorCode &status) const;
2203 UnicodeString& _format(const DigitList &number,
2204 UnicodeString& appendTo,
2205 FieldPositionHandler& handler,
2206 UErrorCode &status) const;
2207
2208 // currency sign count
2209 enum {
2210 fgCurrencySignCountZero,
2211 fgCurrencySignCountInSymbolFormat,
2212 fgCurrencySignCountInISOFormat,
2213 fgCurrencySignCountInPluralFormat
2214 } CurrencySignCount;
2215
2219
2220 UnicodeString fPositivePrefix;
2221 UnicodeString fPositiveSuffix;
2222 UnicodeString fNegativePrefix;
2223 UnicodeString fNegativeSuffix;
2224 UnicodeString* fPosPrefixPattern;
2225 UnicodeString* fPosSuffixPattern;
2226 UnicodeString* fNegPrefixPattern;
2227 UnicodeString* fNegSuffixPattern;
2228
2234 ChoiceFormat* fCurrencyChoice;
2235
2236 DigitList * fMultiplier; // NULL for multiplier of one
2237 int32_t fGroupingSize;
2238 int32_t fGroupingSize2;
2239 UBool fDecimalSeparatorAlwaysShown;
2240 DecimalFormatSymbols* fSymbols;
2241
2242 UBool fUseSignificantDigits;
2243 int32_t fMinSignificantDigits;
2244 int32_t fMaxSignificantDigits;
2245
2246 UBool fUseExponentialNotation;
2247 int8_t fMinExponentDigits;
2248 UBool fExponentSignAlwaysShown;
2249
2250 EnumSet<UNumberFormatAttribute,
2253 fBoolFlags;
2254
2255 DigitList* fRoundingIncrement; // NULL if no rounding increment specified.
2256 ERoundingMode fRoundingMode;
2257
2258 UChar32 fPad;
2259 int32_t fFormatWidth;
2260 EPadPosition fPadPosition;
2261
2262 /*
2263 * Following are used for currency format
2264 */
2265 // pattern used in this formatter
2266 UnicodeString fFormatPattern;
2267 // style is only valid when decimal formatter is constructed by
2268 // DecimalFormat(pattern, decimalFormatSymbol, style)
2269 int fStyle;
2270 /*
2271 * Represents whether this is a currency format, and which
2272 * currency format style.
2273 * 0: not currency format type;
2274 * 1: currency style -- symbol name, such as "$" for US dollar.
2275 * 2: currency style -- ISO name, such as USD for US dollar.
2276 * 3: currency style -- plural long name, such as "US Dollar" for
2277 * "1.00 US Dollar", or "US Dollars" for
2278 * "3.00 US Dollars".
2279 */
2280 int fCurrencySignCount;
2281
2282
2283 /* For currency parsing purose,
2284 * Need to remember all prefix patterns and suffix patterns of
2285 * every currency format pattern,
2286 * including the pattern of default currecny style
2287 * and plural currency style. And the patterns are set through applyPattern.
2288 */
2289 // TODO: innerclass?
2290 /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2291 struct AffixPatternsForCurrency : public UMemory {
2292 // negative prefix pattern
2293 UnicodeString negPrefixPatternForCurrency;
2294 // negative suffix pattern
2295 UnicodeString negSuffixPatternForCurrency;
2296 // positive prefix pattern
2297 UnicodeString posPrefixPatternForCurrency;
2298 // positive suffix pattern
2299 UnicodeString posSuffixPatternForCurrency;
2300 int8_t patternType;
2301
2302 AffixPatternsForCurrency(const UnicodeString& negPrefix,
2303 const UnicodeString& negSuffix,
2304 const UnicodeString& posPrefix,
2305 const UnicodeString& posSuffix,
2306 int8_t type) {
2307 negPrefixPatternForCurrency = negPrefix;
2308 negSuffixPatternForCurrency = negSuffix;
2309 posPrefixPatternForCurrency = posPrefix;
2310 posSuffixPatternForCurrency = posSuffix;
2311 patternType = type;
2312 }
2313 };
2314 */
2315
2316 /* affix for currency formatting when the currency sign in the pattern
2317 * equals to 3, such as the pattern contains 3 currency sign or
2318 * the formatter style is currency plural format style.
2319 */
2320 /* This is not needed in the class declaration, so it is moved into decimfmp.cpp
2321 struct AffixesForCurrency : public UMemory {
2322 // negative prefix
2323 UnicodeString negPrefixForCurrency;
2324 // negative suffix
2325 UnicodeString negSuffixForCurrency;
2326 // positive prefix
2327 UnicodeString posPrefixForCurrency;
2328 // positive suffix
2329 UnicodeString posSuffixForCurrency;
2330
2331 int32_t formatWidth;
2332
2333 AffixesForCurrency(const UnicodeString& negPrefix,
2334 const UnicodeString& negSuffix,
2335 const UnicodeString& posPrefix,
2336 const UnicodeString& posSuffix) {
2337 negPrefixForCurrency = negPrefix;
2338 negSuffixForCurrency = negSuffix;
2339 posPrefixForCurrency = posPrefix;
2340 posSuffixForCurrency = posSuffix;
2341 }
2342 };
2343 */
2344
2345 // Affix pattern set for currency.
2346 // It is a set of AffixPatternsForCurrency,
2347 // each element of the set saves the negative prefix pattern,
2348 // negative suffix pattern, positive prefix pattern,
2349 // and positive suffix pattern of a pattern.
2350 // It is used for currency mixed style parsing.
2351 // It is actually is a set.
2352 // The set contains the default currency pattern from the locale,
2353 // and the currency plural patterns.
2354 // Since it is a set, it does not contain duplicated items.
2355 // For example, if 2 currency plural patterns are the same, only one pattern
2356 // is included in the set. When parsing, we do not check whether the plural
2357 // count match or not.
2358 Hashtable* fAffixPatternsForCurrency;
2359
2360 // Following 2 are affixes for currency.
2361 // It is a hash map from plural count to AffixesForCurrency.
2362 // AffixesForCurrency saves the negative prefix,
2363 // negative suffix, positive prefix, and positive suffix of a pattern.
2364 // It is used during currency formatting only when the currency sign count
2365 // is 3. In which case, the affixes are getting from here, not
2366 // from the fNegativePrefix etc.
2367 Hashtable* fAffixesForCurrency; // for current pattern
2368 Hashtable* fPluralAffixesForCurrency; // for plural pattern
2369
2370 // Information needed for DecimalFormat to format/parse currency plural.
2371 CurrencyPluralInfo* fCurrencyPluralInfo;
2372
2373#if UCONFIG_HAVE_PARSEALLINPUT
2374 UNumberFormatAttributeValue fParseAllInput;
2375#endif
2376
2377
2378protected:
2379
2388 virtual void getEffectiveCurrency(UChar* result, UErrorCode& ec) const;
2389
2393 static const int32_t kDoubleIntegerDigits;
2397 static const int32_t kDoubleFractionDigits;
2398
2409 static const int32_t kMaxScientificIntegerDigits;
2410
2411#if UCONFIG_FORMAT_FASTPATHS_49
2412 private:
2417 uint8_t fReserved[UNUM_DECIMALFORMAT_INTERNAL_SIZE];
2418
2419
2423 void handleChanged();
2424#endif
2425};
2426
2427inline UnicodeString&
2429 UnicodeString& appendTo,
2430 UErrorCode& status) const {
2431 // Don't use Format:: - use immediate base class only,
2432 // in case immediate base modifies behavior later.
2433 return NumberFormat::format(obj, appendTo, status);
2434}
2435
2436inline UnicodeString&
2438 UnicodeString& appendTo) const {
2439 FieldPosition pos(0);
2440 return format(number, appendTo, pos);
2441}
2442
2443inline UnicodeString&
2445 UnicodeString& appendTo) const {
2446 FieldPosition pos(0);
2447 return format((int64_t)number, appendTo, pos);
2448}
2449
2450#ifndef U_HIDE_INTERNAL_API
2451inline const UnicodeString &
2452DecimalFormat::getConstSymbol(DecimalFormatSymbols::ENumberFormatSymbol symbol) const {
2453 return fSymbols->getConstSymbol(symbol);
2454}
2455
2456#endif
2457
2459
2460#endif /* #if !UCONFIG_NO_FORMATTING */
2461
2462#endif // _DECIMFMT
2463//eof
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition choicfmt.h:171
A currency together with a numeric amount, such as 200 USD.
Definition curramt.h:35
This class represents the information needed by DecimalFormat to format currency plural,...
Definition currpinf.h:44
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition dcfmtsym.h:84
const UnicodeString & getConstSymbol(ENumberFormatSymbol symbol) const
Internal function - more efficient version of getSymbol, returning a const reference to one of the sy...
Definition dcfmtsym.h:406
ENumberFormatSymbol
Constants for specifying a number format symbol.
Definition dcfmtsym.h:90
ERoundingMode
Rounding mode.
Definition decimfmt.h:666
@ kRoundDown
Round towards zero.
Definition decimfmt.h:669
@ kRoundHalfEven
Round towards the nearest integer, or towards the nearest even integer if equidistant.
Definition decimfmt.h:671
@ kRoundUp
Round away from zero.
Definition decimfmt.h:670
@ kRoundUnnecessary
Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
Definition decimfmt.h:681
@ kRoundHalfDown
Round towards the nearest integer, or towards zero if equidistant.
Definition decimfmt.h:673
@ kRoundHalfUp
Round towards the nearest integer, or away from zero if equidistant.
Definition decimfmt.h:675
@ kRoundFloor
Round towards negative infinity.
Definition decimfmt.h:668
@ kRoundCeiling
Round towards positive infinity.
Definition decimfmt.h:667
virtual CurrencyAmount * parseCurrency(const UnicodeString &text, ParsePosition &pos) const
Parses text from the given string as a currency amount.
virtual void parse(const UnicodeString &text, Formattable &result, UErrorCode &status) const
Parse the given string using this object's choices.
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols *symbolsToAdopt)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
virtual void setFormatWidth(int32_t width)
Set the width to which the output of format() is padded.
virtual void adoptCurrencyPluralInfo(CurrencyPluralInfo *toAdopt)
Sets the currency plural format information, which is generally not changed by the programmer or user...
virtual ~DecimalFormat()
Destructor.
virtual void setDecimalSeparatorAlwaysShown(UBool newValue)
Allows you to set the behavior of the decimal separator with integers.
virtual void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern.
virtual void getEffectiveCurrency(UChar *result, UErrorCode &ec) const
Returns the currency in effect for this formatter.
UBool areSignificantDigitsUsed() const
Returns true if significant digits are in use, or false if integer and fraction digit counts are in u...
virtual void setPadCharacter(const UnicodeString &padChar)
Set the character used to pad to the format width.
int32_t getMultiplier(void) const
Get the multiplier for use in percent, permill, etc.
virtual void setScientificNotation(UBool useScientific)
Set whether or not scientific notation is used.
virtual void setCurrency(const UChar *theCurrency)
Sets the currency used to display currency amounts.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const
Format a double or long number using base-10 representation.
static UClassID getStaticClassID(void)
Return the class ID for this class.
virtual void setMaximumFractionDigits(int32_t newValue)
Sets the maximum number of digits allowed in the fraction portion of a number.
virtual void applyLocalizedPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Apply the given pattern to this Format object.
virtual void setCurrencyPluralInfo(const CurrencyPluralInfo &info)
Sets the currency plural format information, which is generally not changed by the programmer or user...
virtual UBool isExponentSignAlwaysShown(void)
Return whether the exponent sign is always shown.
virtual void setPadPosition(EPadPosition padPos)
Set the position at which padding will take place.
virtual void setSecondaryGroupingSize(int32_t newValue)
Set the secondary grouping size.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a long number using base-10 representation.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual void setExponentSignAlwaysShown(UBool expSignAlways)
Set whether the exponent sign is always shown.
virtual void setRoundingMode(ERoundingMode roundingMode)
Set the rounding mode.
virtual void setCurrency(const UChar *theCurrency, UErrorCode &ec)
Sets the currency used to display currency amounts.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos) const
Format an int64 number using base-10 representation.
UnicodeString & format(int64_t number, UnicodeString &appendTo) const
Redeclared NumberFormat method.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos) const
Format a long number using base-10 representation.
DecimalFormat(const UnicodeString &pattern, const DecimalFormatSymbols &symbols, UErrorCode &status)
Create a DecimalFormat from the given pattern and symbols.
virtual int32_t getFormatWidth(void) const
Get the width to which the output of format() is padded.
virtual int32_t getAttribute(UNumberFormatAttribute attr, UErrorCode &status) const
Get an integer May return U_UNSUPPORTED_ERROR if this instance does not support the specified attribu...
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
int32_t getMinimumSignificantDigits() const
Returns the minimum number of significant digits that will be displayed.
virtual Format * clone(void) const
Clone this Format object polymorphically.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a long number using base-10 representation.
virtual UnicodeString & toPattern(UnicodeString &result) const
Synthesizes a pattern string that represents the current state of this Format object.
virtual void setRoundingIncrement(double newValue)
Set the rounding increment.
DecimalFormat(UErrorCode &status)
Create a DecimalFormat using the default pattern and symbols for the default locale.
UnicodeString & getNegativeSuffix(UnicodeString &result) const
Get the negative suffix.
static const int32_t kDoubleIntegerDigits
number of integer digits
Definition decimfmt.h:2393
UnicodeString & getPositiveSuffix(UnicodeString &result) const
Get the positive suffix.
virtual void setNegativePrefix(const UnicodeString &newValue)
Set the negative prefix.
virtual void setPositivePrefix(const UnicodeString &newValue)
Set the positive prefix.
virtual void setDecimalFormatSymbols(const DecimalFormatSymbols &symbols)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
void setMaximumSignificantDigits(int32_t max)
Sets the maximum number of significant digits that will be displayed.
virtual const CurrencyPluralInfo * getCurrencyPluralInfo(void) const
Returns the currency plural format information, which is generally not changed by the programmer or u...
UnicodeString & getPositivePrefix(UnicodeString &result) const
Get the positive prefix.
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const
Parse the given string using this object's choices.
virtual ERoundingMode getRoundingMode(void) const
Get the rounding mode.
virtual UnicodeString & toLocalizedPattern(UnicodeString &result) const
Synthesizes a localized pattern string that represents the current state of this Format object.
DecimalFormat & operator=(const DecimalFormat &rhs)
Assignment operator.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a double or long number using base-10 representation.
virtual void setMinimumExponentDigits(int8_t minExpDig)
Set the minimum exponent digits that will be shown.
DecimalFormat(const UnicodeString &pattern, UErrorCode &status)
Create a DecimalFormat from the given pattern and the symbols for the default locale.
UBool isDecimalSeparatorAlwaysShown(void) const
Allows you to get the behavior of the decimal separator with integers.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an int64 number using base-10 representation.
virtual int8_t getMinimumExponentDigits(void) const
Return the minimum exponent digits that will be shown.
virtual void setMaximumIntegerDigits(int32_t newValue)
Sets the maximum number of digits allowed in the integer portion of a number.
virtual DecimalFormat & setAttribute(UNumberFormatAttribute attr, int32_t newvalue, UErrorCode &status)
Set an integer attribute on this DecimalFormat.
virtual const DecimalFormatSymbols * getDecimalFormatSymbols(void) const
Returns the decimal format symbols, which is generally not changed by the programmer or user.
static const int32_t kDoubleFractionDigits
number of fraction digits
Definition decimfmt.h:2397
DecimalFormat(const DecimalFormat &source)
Copy constructor.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a double or long number using base-10 representation.
virtual UnicodeString getPadCharacterString() const
Get the pad character used to pad to the format width.
virtual void setMinimumFractionDigits(int32_t newValue)
Sets the minimum number of digits allowed in the fraction portion of a number.
virtual void setPositiveSuffix(const UnicodeString &newValue)
Set the positive suffix.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a Formattable using base-10 representation.
virtual void setMinimumIntegerDigits(int32_t newValue)
Sets the minimum number of digits allowed in the integer portion of a number.
virtual double getRoundingIncrement(void) const
Get the rounding increment.
virtual EPadPosition getPadPosition(void) const
Get the position at which padding will take place.
virtual void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given pattern to this Format object.
EPadPosition
Pad position.
Definition decimfmt.h:688
virtual UnicodeString & format(const DigitList &number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a decimal number.
virtual UnicodeString & format(const StringPiece &number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a decimal number.
virtual UBool isScientificNotation(void)
Return whether or not scientific notation is used.
int32_t getGroupingSize(void) const
Return the grouping size.
UnicodeString & getNegativePrefix(UnicodeString &result) const
Get the negative prefix.
void setSignificantDigitsUsed(UBool useSignificantDigits)
Sets whether significant digits are in use, or integer and fraction digit counts are in use.
virtual void setMultiplier(int32_t newValue)
Set the multiplier for use in percent, permill, etc.
DecimalFormat(const UnicodeString &pattern, DecimalFormatSymbols *symbolsToAdopt, UErrorCode &status)
Create a DecimalFormat from the given pattern and symbols.
virtual void setNegativeSuffix(const UnicodeString &newValue)
Set the negative suffix.
DecimalFormat(const UnicodeString &pattern, DecimalFormatSymbols *symbolsToAdopt, UNumberFormatStyle style, UErrorCode &status)
This API is for ICU use only.
static const int32_t kMaxScientificIntegerDigits
When someone turns on scientific mode, we assume that more than this number of digits is due to flipp...
Definition decimfmt.h:2409
virtual void setGroupingSize(int32_t newValue)
Set the grouping size.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format an int64 number using base-10 representation.
int32_t getSecondaryGroupingSize(void) const
Return the secondary grouping size.
virtual void applyPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Apply the given pattern to this Format object.
virtual UnicodeString & format(const DigitList &number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a decimal number.
static const char fgNumberPatterns[]
The resource tags we use to retrieve decimal format data from locale resource bundles.
Definition decimfmt.h:1928
DecimalFormat(const UnicodeString &pattern, DecimalFormatSymbols *symbolsToAdopt, UParseError &parseError, UErrorCode &status)
Create a DecimalFormat from the given pattern and symbols.
int32_t getMaximumSignificantDigits() const
Returns the maximum number of significant digits that will be displayed.
void setMinimumSignificantDigits(int32_t min)
Sets the minimum number of significant digits that will be displayed.
enum bitset for boolean fields.
Definition enumset.h:30
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:53
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
Format()
Default constructor for subclass use only.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
NumberFormat()
Default constructor for subclass use only.
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:52
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:273
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
C++ API: Currency Amount Object.
C++ API: Symbols for formatting numbers.
C++: internal template EnumSet<>
C++ API: FieldPosition Iterator.
C++ API: Locale ID object.
C++ API: Abstract base class for all number formats.
C++ API: StringPiece: Read-only byte string wrapper class.
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:56
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:298
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition umachine.h:278
UNumberFormatAttribute
The possible UNumberFormat numeric attributes.
Definition unum.h:733
@ UNUM_LIMIT_BOOLEAN_ATTRIBUTE
Limit of boolean attributes.
Definition unum.h:812
@ UNUM_MAX_NONBOOLEAN_ATTRIBUTE
One below the first bitfield-boolean item.
Definition unum.h:794
UNumberFormatStyle
The possible number format styles.
Definition unum.h:135
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129