ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

numberformatter.h
Go to the documentation of this file.
1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include "unicode/utypes.h"
5
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMBERFORMATTER_H__
8 #define __NUMBERFORMATTER_H__
9
10 #include "unicode/appendable.h"
11 #include "unicode/dcfmtsym.h"
12 #include "unicode/currunit.h"
13 #include "unicode/fieldpos.h"
14 #include "unicode/fpositer.h"
15 #include "unicode/measunit.h"
16 #include "unicode/nounit.h"
17 #include "unicode/plurrule.h"
18 #include "unicode/ucurr.h"
19 #include "unicode/unum.h"
20
21 #ifndef U_HIDE_DRAFT_API
22
99 typedef enum UNumberUnitWidth {
111 UNUM_UNIT_WIDTH_NARROW,
112
127 UNUM_UNIT_WIDTH_SHORT,
128
138 UNUM_UNIT_WIDTH_FULL_NAME,
139
149 UNUM_UNIT_WIDTH_ISO_CODE,
150
158 UNUM_UNIT_WIDTH_HIDDEN,
159
165 UNUM_UNIT_WIDTH_COUNT
166 } UNumberUnitWidth;
167
186 typedef enum UNumberSignDisplay {
193 UNUM_SIGN_AUTO,
194
200 UNUM_SIGN_ALWAYS,
201
207 UNUM_SIGN_NEVER,
208
223 UNUM_SIGN_ACCOUNTING,
224
231 UNUM_SIGN_ACCOUNTING_ALWAYS,
232
238 UNUM_SIGN_COUNT
239 } UNumberSignDisplay;
240
250 typedef enum UNumberDecimalSeparatorDisplay {
257 UNUM_DECIMAL_SEPARATOR_AUTO,
258
264 UNUM_DECIMAL_SEPARATOR_ALWAYS,
265
271 UNUM_DECIMAL_SEPARATOR_COUNT
272 } UNumberDecimalMarkDisplay;
273
274 U_NAMESPACE_BEGIN namespace number { // icu::number
275
276 // Forward declarations:
277 class UnlocalizedNumberFormatter;
278 class LocalizedNumberFormatter;
279 class FormattedNumber;
280 class Notation;
281 class ScientificNotation;
282 class Rounder;
283 class FractionRounder;
284 class CurrencyRounder;
285 class IncrementRounder;
286 class Grouper;
287 class IntegerWidth;
288
289 namespace impl {
290
291 // Forward declarations:
292 class Padder;
293 struct MacroProps;
294 struct MicroProps;
295 class DecimalQuantity;
296 struct NumberFormatterResults;
297 class NumberFormatterImpl;
298 struct ParsedPatternInfo;
299 class ScientificModifier;
300 class MultiplierProducer;
301 class MutablePatternModifier;
302 class LongNameHandler;
303 class ScientificHandler;
304 class CompactHandler;
305 class Modifier;
306 class NumberStringBuilder;
307
308 } // namespace impl
309
310 // Reserve extra names in case they are added as classes in the future:
311 typedef Notation CompactNotation;
312 typedef Notation SimpleNotation;
313
319 class U_I18N_API Notation : public UMemory {
320 public:
345 static ScientificNotation scientific();
346
369 static ScientificNotation engineering();
370
412 static CompactNotation compactShort();
413
436 static CompactNotation compactLong();
437
462 static SimpleNotation simple();
463
464 private:
465 enum NotationType {
466 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
467 } fType;
468
469 union NotationUnion {
470 // For NTN_SCIENTIFIC
471 struct ScientificSettings {
472 int8_t fEngineeringInterval;
473 bool fRequireMinInt;
474 int8_t fMinExponentDigits;
475 UNumberSignDisplay fExponentSignDisplay;
476 } scientific;
477
478 // For NTN_COMPACT
479 UNumberCompactStyle compactStyle;
480
481 // For NTN_ERROR
482 UErrorCode errorCode;
483 } fUnion;
484
485 typedef NotationUnion::ScientificSettings ScientificSettings;
486
487 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
488
489 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
490 fUnion.errorCode = errorCode;
491 }
492
493 Notation() : fType(NTN_SIMPLE), fUnion() {}
494
495 UBool copyErrorTo(UErrorCode &status) const {
496 if (fType == NTN_ERROR) {
497 status = fUnion.errorCode;
498 return TRUE;
499 }
500 return FALSE;
501 }
502
503 // To allow MacroProps to initialize empty instances:
504 friend struct impl::MacroProps;
505 friend class ScientificNotation;
506
507 // To allow implementation to access internal types:
508 friend class impl::NumberFormatterImpl;
509 friend class impl::ScientificModifier;
510 friend class impl::ScientificHandler;
511 };
512
521 class U_I18N_API ScientificNotation : public Notation {
522 public:
536 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
537
551 ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
552
553 private:
554 // Inherit constructor
555 using Notation::Notation;
556
557 friend class Notation;
558 };
559
560 // Reserve extra names in case they are added as classes in the future:
561 typedef Rounder DigitRounder;
562
571 class U_I18N_API Rounder : public UMemory {
572
573 public:
590 static Rounder unlimited();
591
598 static FractionRounder integer();
599
627 static FractionRounder fixedFraction(int32_t minMaxFractionPlaces);
628
642 static FractionRounder minFraction(int32_t minFractionPlaces);
643
654 static FractionRounder maxFraction(int32_t maxFractionPlaces);
655
669 static FractionRounder minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
670
684 static DigitRounder fixedDigits(int32_t minMaxSignificantDigits);
685
698 static DigitRounder minDigits(int32_t minSignificantDigits);
699
708 static DigitRounder maxDigits(int32_t maxSignificantDigits);
709
721 static DigitRounder minMaxDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits);
722
742 static IncrementRounder increment(double roundingIncrement);
743
760 static CurrencyRounder currency(UCurrencyUsage currencyUsage);
761
771 Rounder withMode(UNumberFormatRoundingMode roundingMode) const;
772
773 private:
774 enum RounderType {
775 RND_BOGUS,
776 RND_NONE,
777 RND_FRACTION,
778 RND_SIGNIFICANT,
779 RND_FRACTION_SIGNIFICANT,
780 RND_INCREMENT,
781 RND_CURRENCY,
782 RND_PASS_THROUGH,
783 RND_ERROR
784 } fType;
785
786 union RounderUnion {
787 struct FractionSignificantSettings {
788 // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
789 int8_t fMinFrac;
790 int8_t fMaxFrac;
791 int8_t fMinSig;
792 int8_t fMaxSig;
793 } fracSig;
794 struct IncrementSettings {
795 double fIncrement;
796 int32_t fMinFrac;
797 } increment; // For RND_INCREMENT
798 UCurrencyUsage currencyUsage; // For RND_CURRENCY
799 UErrorCode errorCode; // For RND_ERROR
800 } fUnion;
801
802 typedef RounderUnion::FractionSignificantSettings FractionSignificantSettings;
803 typedef RounderUnion::IncrementSettings IncrementSettings;
804
805 UNumberFormatRoundingMode fRoundingMode;
806
807 Rounder(const RounderType &type, const RounderUnion &union_, UNumberFormatRoundingMode roundingMode)
808 : fType(type), fUnion(union_), fRoundingMode(roundingMode) {}
809
810 Rounder(UErrorCode errorCode) : fType(RND_ERROR) {
811 fUnion.errorCode = errorCode;
812 }
813
814 Rounder() : fType(RND_BOGUS) {}
815
816 bool isBogus() const {
817 return fType == RND_BOGUS;
818 }
819
820 UBool copyErrorTo(UErrorCode &status) const {
821 if (fType == RND_ERROR) {
822 status = fUnion.errorCode;
823 return TRUE;
824 }
825 return FALSE;
826 }
827
828 // On the parent type so that this method can be called internally on Rounder instances.
829 Rounder withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
830
832 void setLocaleData(const CurrencyUnit &currency, UErrorCode &status);
833
834 void apply(impl::DecimalQuantity &value, UErrorCode &status) const;
835
837 void apply(impl::DecimalQuantity &value, int32_t minInt, UErrorCode status);
838
839 int32_t
840 chooseMultiplierAndApply(impl::DecimalQuantity &input, const impl::MultiplierProducer &producer,
841 UErrorCode &status);
842
843 static FractionRounder constructFraction(int32_t minFrac, int32_t maxFrac);
844
845 static Rounder constructSignificant(int32_t minSig, int32_t maxSig);
846
847 static Rounder
848 constructFractionSignificant(const FractionRounder &base, int32_t minSig, int32_t maxSig);
849
850 static IncrementRounder constructIncrement(double increment, int32_t minFrac);
851
852 static CurrencyRounder constructCurrency(UCurrencyUsage usage);
853
854 static Rounder constructPassThrough();
855
856 // To allow MacroProps/MicroProps to initialize bogus instances:
857 friend struct impl::MacroProps;
858 friend struct impl::MicroProps;
859
860 // To allow NumberFormatterImpl to access isBogus() and other internal methods:
861 friend class impl::NumberFormatterImpl;
862
863 // To give access to apply() and chooseMultiplierAndApply():
864 friend class impl::MutablePatternModifier;
865 friend class impl::LongNameHandler;
866 friend class impl::ScientificHandler;
867 friend class impl::CompactHandler;
868
869 // To allow child classes to call private methods:
870 friend class FractionRounder;
871 friend class CurrencyRounder;
872 friend class IncrementRounder;
873 };
874
884 class U_I18N_API FractionRounder : public Rounder {
885 public:
902 Rounder withMinDigits(int32_t minSignificantDigits) const;
903
921 Rounder withMaxDigits(int32_t maxSignificantDigits) const;
922
923 private:
924 // Inherit constructor
925 using Rounder::Rounder;
926
927 // To allow parent class to call this class's constructor:
928 friend class Rounder;
929 };
930
940 class U_I18N_API CurrencyRounder : public Rounder {
941 public:
959 Rounder withCurrency(const CurrencyUnit &currency) const;
960
961 private:
962 // Inherit constructor
963 using Rounder::Rounder;
964
965 // To allow parent class to call this class's constructor:
966 friend class Rounder;
967 };
968
978 class U_I18N_API IncrementRounder : public Rounder {
979 public:
995 Rounder withMinFraction(int32_t minFrac) const;
996
997 private:
998 // Inherit constructor
999 using Rounder::Rounder;
1000
1001 // To allow parent class to call this class's constructor:
1002 friend class Rounder;
1003 };
1004
1008 class U_I18N_API Grouper : public UMemory {
1009 public:
1013 static Grouper defaults();
1014
1018 static Grouper minTwoDigits();
1019
1023 static Grouper none();
1024
1025 private:
1026 int8_t fGrouping1; // -3 means "bogus"; -2 means "needs locale data"; -1 means "no grouping"
1027 int8_t fGrouping2;
1028 bool fMin2;
1029
1030 Grouper(int8_t grouping1, int8_t grouping2, bool min2)
1031 : fGrouping1(grouping1), fGrouping2(grouping2), fMin2(min2) {}
1032
1033 Grouper() : fGrouping1(-3) {};
1034
1035 bool isBogus() const {
1036 return fGrouping1 == -3;
1037 }
1038
1040 void setLocaleData(const impl::ParsedPatternInfo &patternInfo);
1041
1042 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
1043
1044 // To allow MacroProps/MicroProps to initialize empty instances:
1045 friend struct impl::MacroProps;
1046 friend struct impl::MicroProps;
1047
1048 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1049 friend class impl::NumberFormatterImpl;
1050 };
1051
1061 class U_I18N_API IntegerWidth : public UMemory {
1062 public:
1075 static IntegerWidth zeroFillTo(int32_t minInt);
1076
1088 IntegerWidth truncateAt(int32_t maxInt);
1089
1090 private:
1091 union {
1092 struct {
1093 int8_t fMinInt;
1094 int8_t fMaxInt;
1095 } minMaxInt;
1096 UErrorCode errorCode;
1097 } fUnion;
1098 bool fHasError = false;
1099
1100 IntegerWidth(int8_t minInt, int8_t maxInt);
1101
1102 IntegerWidth(UErrorCode errorCode) { // NOLINT
1103 fUnion.errorCode = errorCode;
1104 fHasError = true;
1105 }
1106
1107 IntegerWidth() { // NOLINT
1108 fUnion.minMaxInt.fMinInt = -1;
1109 }
1110
1111 bool isBogus() const {
1112 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1113 }
1114
1115 UBool copyErrorTo(UErrorCode &status) const {
1116 if (fHasError) {
1117 status = fUnion.errorCode;
1118 return TRUE;
1119 }
1120 return FALSE;
1121 }
1122
1123 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
1124
1125 // To allow MacroProps/MicroProps to initialize empty instances:
1126 friend struct impl::MacroProps;
1127 friend struct impl::MicroProps;
1128
1129 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1130 friend class impl::NumberFormatterImpl;
1131 };
1132
1133 namespace impl {
1134
1141 static constexpr int32_t DEFAULT_THRESHOLD = 3;
1142
1144 class U_I18N_API SymbolsWrapper : public UMemory {
1145 public:
1147 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
1148
1150 SymbolsWrapper(const SymbolsWrapper &other);
1151
1153 ~SymbolsWrapper();
1154
1156 SymbolsWrapper &operator=(const SymbolsWrapper &other);
1157
1162 void setTo(const DecimalFormatSymbols &dfs);
1163
1168 void setTo(const NumberingSystem *ns);
1169
1174 bool isDecimalFormatSymbols() const;
1175
1180 bool isNumberingSystem() const;
1181
1186 const DecimalFormatSymbols *getDecimalFormatSymbols() const;
1187
1192 const NumberingSystem *getNumberingSystem() const;
1193
1195 UBool copyErrorTo(UErrorCode &status) const {
1196 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
1197 status = U_MEMORY_ALLOCATION_ERROR;
1198 return TRUE;
1199 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
1200 status = U_MEMORY_ALLOCATION_ERROR;
1201 return TRUE;
1202 }
1203 return FALSE;
1204 }
1205
1206 private:
1207 enum SymbolsPointerType {
1208 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1209 } fType;
1210
1211 union {
1212 const DecimalFormatSymbols *dfs;
1213 const NumberingSystem *ns;
1214 } fPtr;
1215
1216 void doCopyFrom(const SymbolsWrapper &other);
1217
1218 void doCleanup();
1219 };
1220
1222 class U_I18N_API Padder : public UMemory {
1223 public:
1225 static Padder none();
1226
1228 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
1229
1230 private:
1231 UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
1232 union {
1233 struct {
1234 int32_t fCp;
1235 UNumberFormatPadPosition fPosition;
1236 } padding;
1237 UErrorCode errorCode;
1238 } fUnion;
1239
1240 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
1241
1242 Padder(int32_t width);
1243
1244 Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
1245 fUnion.errorCode = errorCode;
1246 }
1247
1248 Padder() : fWidth(-2) {} // NOLINT
1249
1250 bool isBogus() const {
1251 return fWidth == -2;
1252 }
1253
1254 UBool copyErrorTo(UErrorCode &status) const {
1255 if (fWidth == -3) {
1256 status = fUnion.errorCode;
1257 return TRUE;
1258 }
1259 return FALSE;
1260 }
1261
1262 bool isValid() const {
1263 return fWidth > 0;
1264 }
1265
1266 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
1267 impl::NumberStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
1268 UErrorCode &status) const;
1269
1270 // To allow MacroProps/MicroProps to initialize empty instances:
1271 friend struct MacroProps;
1272 friend struct MicroProps;
1273
1274 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1275 friend class impl::NumberFormatterImpl;
1276 };
1277
1279 struct U_I18N_API MacroProps : public UMemory {
1281 Notation notation;
1282
1284 MeasureUnit unit; // = NoUnit::base();
1285
1287 Rounder rounder; // = Rounder(); (bogus)
1288
1290 Grouper grouper; // = Grouper(); (bogus)
1291
1293 Padder padder; // = Padder(); (bogus)
1294
1296 IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
1297
1299 SymbolsWrapper symbols;
1300
1301 // UNUM_XYZ_COUNT denotes null (bogus) values.
1302
1304 UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
1305
1307 UNumberSignDisplay sign = UNUM_SIGN_COUNT;
1308
1310 UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
1311
1313 PluralRules *rules = nullptr; // no ownership
1314
1316 int32_t threshold = DEFAULT_THRESHOLD;
1317 Locale locale;
1318
1323 bool copyErrorTo(UErrorCode &status) const {
1324 return notation.copyErrorTo(status) || rounder.copyErrorTo(status) ||
1325 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1326 symbols.copyErrorTo(status);
1327 }
1328 };
1329
1330 } // namespace impl
1331
1336 template<typename Derived>
1337 class U_I18N_API NumberFormatterSettings {
1338 public:
1367 Derived notation(const Notation &notation) const;
1368
1411 Derived unit(const icu::MeasureUnit &unit) const;
1412
1424 Derived adoptUnit(const icu::MeasureUnit *unit) const;
1425
1457 Derived rounding(const Rounder &rounder) const;
1458
1459 #ifndef U_HIDE_INTERNAL_API
1460
1490 Derived grouping(const Grouper &grouper) const;
1491
1492 #endif /* U_HIDE_INTERNAL_API */
1493
1518 Derived integerWidth(const IntegerWidth &style) const;
1519
1560 Derived symbols(const DecimalFormatSymbols &symbols) const;
1561
1595 Derived adoptSymbols(const NumberingSystem *symbols) const;
1596
1622 Derived unitWidth(const UNumberUnitWidth &width) const;
1623
1650 Derived sign(const UNumberSignDisplay &width) const;
1651
1678 Derived decimal(const UNumberDecimalSeparatorDisplay &width) const;
1679
1680 #ifndef U_HIDE_INTERNAL_API
1681
1687 Derived padding(const impl::Padder &padder) const;
1688
1695 Derived threshold(int32_t threshold) const;
1696
1697 #endif /* U_HIDE_INTERNAL_API */
1698
1705 UBool copyErrorTo(UErrorCode &outErrorCode) const {
1706 if (U_FAILURE(outErrorCode)) {
1707 // Do not overwrite the older error code
1708 return TRUE;
1709 }
1710 fMacros.copyErrorTo(outErrorCode);
1711 return U_FAILURE(outErrorCode);
1712 }
1713
1714 protected:
1715 impl::MacroProps fMacros;
1716
1717 private:
1718 // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
1719 NumberFormatterSettings() = default;
1720
1721 friend class LocalizedNumberFormatter;
1722 friend class UnlocalizedNumberFormatter;
1723 };
1724
1731 class U_I18N_API UnlocalizedNumberFormatter
1732 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
1733
1734 public:
1751 LocalizedNumberFormatter locale(const icu::Locale &locale) const;
1752
1753 // Make default copy constructor call the NumberFormatterSettings copy constructor.
1758 UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other) : UnlocalizedNumberFormatter(
1759 static_cast<const NumberFormatterSettings<UnlocalizedNumberFormatter> &>(other)) {}
1760
1761 private:
1762 UnlocalizedNumberFormatter() = default;
1763
1764 explicit UnlocalizedNumberFormatter(
1765 const NumberFormatterSettings<UnlocalizedNumberFormatter> &other);
1766
1767 // To give the fluent setters access to this class's constructor:
1768 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
1769
1770 // To give NumberFormatter::with() access to this class's constructor:
1771 friend class NumberFormatter;
1772 };
1773
1780 class U_I18N_API LocalizedNumberFormatter
1781 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
1782 public:
1794 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
1795
1807 FormattedNumber formatDouble(double value, UErrorCode &status) const;
1808
1823 FormattedNumber formatDecimal(StringPiece value, UErrorCode &status) const;
1824
1825 // Make default copy constructor call the NumberFormatterSettings copy constructor.
1830 LocalizedNumberFormatter(const LocalizedNumberFormatter &other) : LocalizedNumberFormatter(
1831 static_cast<const NumberFormatterSettings<LocalizedNumberFormatter> &>(other)) {}
1832
1837 ~LocalizedNumberFormatter();
1838
1839 private:
1840 const impl::NumberFormatterImpl* fCompiled {nullptr};
1841 char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
1842
1843 LocalizedNumberFormatter() = default;
1844
1845 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter> &other);
1846
1847 LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
1848
1860 FormattedNumber formatImpl(impl::NumberFormatterResults *results, UErrorCode &status) const;
1861
1862 // To give the fluent setters access to this class's constructor:
1863 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
1864 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
1865
1866 // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
1867 friend class UnlocalizedNumberFormatter;
1868 };
1869
1876 class U_I18N_API FormattedNumber : public UMemory {
1877 public:
1884 UnicodeString toString() const;
1885
1895 Appendable &appendTo(Appendable &appendable);
1896
1916 void populateFieldPosition(FieldPosition &fieldPosition, UErrorCode &status);
1917
1932 void populateFieldPositionIterator(FieldPositionIterator &iterator, UErrorCode &status);
1933
1938 ~FormattedNumber();
1939
1940 private:
1941 // Can't use LocalPointer because NumberFormatterResults is forward-declared
1942 const impl::NumberFormatterResults *fResults;
1943
1944 // Error code for the terminal methods
1945 UErrorCode fErrorCode;
1946
1947 explicit FormattedNumber(impl::NumberFormatterResults *results)
1948 : fResults(results), fErrorCode(U_ZERO_ERROR) {};
1949
1950 explicit FormattedNumber(UErrorCode errorCode)
1951 : fResults(nullptr), fErrorCode(errorCode) {};
1952
1953 // To give LocalizedNumberFormatter format methods access to this class's constructor:
1954 friend class LocalizedNumberFormatter;
1955 };
1956
1962 class U_I18N_API NumberFormatter final {
1963 public:
1971 static UnlocalizedNumberFormatter with();
1972
1982 static LocalizedNumberFormatter withLocale(const Locale &locale);
1983
1988 NumberFormatter() = delete;
1989 };
1990
1991 } // namespace number
1992 U_NAMESPACE_END
1993
1994 #endif // U_HIDE_DRAFT_API
1995
1996 #endif // __NUMBERFORMATTER_H__
1997
1998 #endif /* #if !UCONFIG_NO_FORMATTING */
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:88
UNUM_DECIMAL_SEPARATOR_ALWAYS
Always show the decimal separator, even if there are no digits to display after the separator...
Definition: numberformatter.h:264
UNumberFormatRoundingMode
UNumberFormatRoundingMode
The possible number format rounding modes.
Definition: unum.h:275
UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: numberformatter.h:238
icu::number::IncrementRounder
A class that defines a rounding strategy parameterized by a rounding increment to be used when format...
Definition: numberformatter.h:978
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:38
currunit.h
C++ API: Currency Unit Information.
icu::number::impl::MacroProps::padder
Padder padder
Definition: numberformatter.h:1293
icu::number::impl::MacroProps::rounder
Rounder rounder
Definition: numberformatter.h:1287
icu::number::impl::MacroProps::copyErrorTo
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
Definition: numberformatter.h:1323
UNUM_UNIT_WIDTH_ISO_CODE
Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
Definition: numberformatter.h:149
icu::number::NumberFormatter
See the main description in numberformatter.h for documentation and examples.
Definition: numberformatter.h:1962
icu::number::FractionRounder
A class that defines a rounding strategy based on a number of fraction places and optionally signific...
Definition: numberformatter.h:884
UNUM_SIGN_ACCOUNTING
Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive ...
Definition: numberformatter.h:223
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:688
icu::number::IntegerWidth
A class that defines the strategy for padding and truncating integers before the decimal separator...
Definition: numberformatter.h:1061
UNumberDecimalMarkDisplay
enum UNumberDecimalSeparatorDisplay UNumberDecimalMarkDisplay
An enum declaring how to render the decimal separator.
fpositer.h
C++ API: FieldPosition Iterator.
icu::number::Rounder
A class that defines the rounding strategy to be used when formatting numbers in NumberFormatter.
Definition: numberformatter.h:571
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter(const LocalizedNumberFormatter &other)
Returns a copy of this LocalizedNumberFormatter.
Definition: numberformatter.h:1830
icu::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
appendable.h
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
nounit.h
C++ API: units for percent and permille.
U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:430
plurrule.h
C++ API: PluralRules object.
UNUM_SIGN_NEVER
Do not show the sign on positive or negative numbers.
Definition: numberformatter.h:207
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:197
U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition: utypes.h:438
icu::number::Notation::NotationUnion::ScientificSettings
Definition: numberformatter.h:471
icu::number::impl::MacroProps
Definition: numberformatter.h:1279
icu::number::NumberFormatterSettings
An abstract base class for specifying settings related to number formatting.
Definition: numberformatter.h:1337
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
UNUM_UNIT_WIDTH_HIDDEN
Format the number according to the specified unit, but do not display the unit.
Definition: numberformatter.h:158
fieldpos.h
C++ API: FieldPosition identifies the fields in a formatted output.
icu::number::impl::MacroProps::grouper
Grouper grouper
Definition: numberformatter.h:1290
icu::number::Notation
A class that defines the notation style to be used when formatting numbers in NumberFormatter.
Definition: numberformatter.h:319
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: numberformatter.h:250
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:62
icu::number::impl::MacroProps::integerWidth
IntegerWidth integerWidth
Definition: numberformatter.h:1296
UNUM_DECIMAL_SEPARATOR_AUTO
Show the decimal separator when there are one or more digits to display after the separator...
Definition: numberformatter.h:257
measunit.h
C++ API: A unit for measuring a quantity.
ucurr.h
C API: Encapsulates information about a currency.
UNUM_UNIT_WIDTH_NARROW
Print an abbreviated version of the unit name.
Definition: numberformatter.h:111
UCurrencyUsage
UCurrencyUsage
Currency Usage used for Decimal Format.
Definition: ucurr.h:41
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:396
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper()
Definition: numberformatter.h:1147
icu::number::impl::MacroProps::notation
Notation notation
Definition: numberformatter.h:1281
icu::number::impl::MacroProps::symbols
SymbolsWrapper symbols
Definition: numberformatter.h:1299
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: numberformatter.h:99
TRUE
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:240
icu::CurrencyUnit
A unit of currency, such as USD (U.S.
Definition: currunit.h:37
UNUM_SIGN_ACCOUNTING_ALWAYS
Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive nu...
Definition: numberformatter.h:231
UNumberFormatPadPosition
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:304
icu::number::Rounder::RounderUnion::IncrementSettings
Definition: numberformatter.h:794
icu::number::impl::MacroProps::unit
MeasureUnit unit
Definition: numberformatter.h:1284
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: numberformatter.h:186
UNUM_UNIT_WIDTH_FULL_NAME
Print the full name of the unit, without any abbreviations.
Definition: numberformatter.h:138
icu::number::UnlocalizedNumberFormatter
A NumberFormatter that does not yet have a locale.
Definition: numberformatter.h:1731
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UNumberCompactStyle
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:315
icu::number::CurrencyRounder
A class that defines a rounding strategy parameterized by a currency to be used when formatting numbe...
Definition: numberformatter.h:940
icu::number::LocalizedNumberFormatter
A NumberFormatter that has a locale associated with it; this means .format() methods are available...
Definition: numberformatter.h:1780
icu::number::NumberFormatterSettings::copyErrorTo
UBool copyErrorTo(UErrorCode &outErrorCode) const
Sets the UErrorCode if an error occurred in the fluent chain.
Definition: numberformatter.h:1705
UNUM_UNIT_WIDTH_SHORT
Print an abbreviated version of the unit name.
Definition: numberformatter.h:127
UNUM_SIGN_ALWAYS
Show the minus sign on negative numbers and the plus sign on positive numbers.
Definition: numberformatter.h:200
icu::number::impl::SymbolsWrapper::copyErrorTo
UBool copyErrorTo(UErrorCode &status) const
Definition: numberformatter.h:1195
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::number::impl::SymbolsWrapper
Definition: numberformatter.h:1144
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
dcfmtsym.h
C++ API: Symbols for formatting numbers.
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other)
Returns a copy of this UnlocalizedNumberFormatter.
Definition: numberformatter.h:1758
UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
Definition: numberformatter.h:165
icu::number::ScientificNotation
A class that defines the scientific notation style to be used when formatting numbers in NumberFormat...
Definition: numberformatter.h:521
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::number::impl::Padder
Definition: numberformatter.h:1222
UNUM_SIGN_AUTO
Show the minus sign on negative numbers, and do not show the sign on positive numbers.
Definition: numberformatter.h:193
FALSE
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:244
UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: numberformatter.h:271
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::number::Rounder::RounderUnion::FractionSignificantSettings
Definition: numberformatter.h:787
icu::number::FormattedNumber
The result of a number formatting operation.
Definition: numberformatter.h:1876
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:54
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:112
icu::number::Grouper
Definition: numberformatter.h:1008
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:51
unum.h
C API: NumberFormat.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188