ICU 61.1  61.1
unum.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
6 * All Rights Reserved.
7 * Modification History:
8 *
9 * Date Name Description
10 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
11 *******************************************************************************
12 */
13 
14 #ifndef _UNUM
15 #define _UNUM
16 
17 #include "unicode/utypes.h"
18 
19 #if !UCONFIG_NO_FORMATTING
20 
21 #include "unicode/localpointer.h"
22 #include "unicode/uloc.h"
23 #include "unicode/ucurr.h"
24 #include "unicode/umisc.h"
25 #include "unicode/parseerr.h"
26 #include "unicode/uformattable.h"
28 #include "unicode/ufieldpositer.h"
29 
140 typedef void* UNumberFormat;
141 
145 typedef enum UNumberFormatStyle {
249 
250 #ifndef U_HIDE_DEPRECATED_API
251 
256 #endif /* U_HIDE_DEPRECATED_API */
257 
269 
279  UNUM_ROUND_CEILING,
280  UNUM_ROUND_FLOOR,
281  UNUM_ROUND_DOWN,
282  UNUM_ROUND_UP,
288 #ifndef U_HIDE_DEPRECATED_API
289 
294 #endif /* U_HIDE_DEPRECATED_API */
295  UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
296  UNUM_ROUND_HALFUP,
303 
308  UNUM_PAD_BEFORE_PREFIX,
309  UNUM_PAD_AFTER_PREFIX,
310  UNUM_PAD_BEFORE_SUFFIX,
311  UNUM_PAD_AFTER_SUFFIX
313 
318 typedef enum UNumberCompactStyle {
325 
337 
338  /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
339  * it is needed for layout of DecimalFormatSymbols object. */
345 };
354 typedef enum UNumberFormatFields {
377 #ifndef U_HIDE_DEPRECATED_API
378 
383 #endif /* U_HIDE_DEPRECATED_API */
385 
386 
420 U_STABLE UNumberFormat* U_EXPORT2
422  const UChar* pattern,
423  int32_t patternLength,
424  const char* locale,
425  UParseError* parseErr,
426  UErrorCode* status);
427 
428 
435 U_STABLE void U_EXPORT2
437 
438 #if U_SHOW_CPLUSPLUS_API
439 
441 
452 
454 
455 #endif
456 
465 U_STABLE UNumberFormat* U_EXPORT2
466 unum_clone(const UNumberFormat *fmt,
467  UErrorCode *status);
468 
493 U_STABLE int32_t U_EXPORT2
494 unum_format( const UNumberFormat* fmt,
495  int32_t number,
496  UChar* result,
497  int32_t resultLength,
498  UFieldPosition *pos,
499  UErrorCode* status);
500 
525 U_STABLE int32_t U_EXPORT2
527  int64_t number,
528  UChar* result,
529  int32_t resultLength,
530  UFieldPosition *pos,
531  UErrorCode* status);
532 
557 U_STABLE int32_t U_EXPORT2
558 unum_formatDouble( const UNumberFormat* fmt,
559  double number,
560  UChar* result,
561  int32_t resultLength,
562  UFieldPosition *pos, /* 0 if ignore */
563  UErrorCode* status);
564 
607 U_STABLE int32_t U_EXPORT2
609  double number,
610  UChar* result,
611  int32_t resultLength,
612  UFieldPositionIterator* fpositer,
613  UErrorCode* status);
614 
615 
644 U_STABLE int32_t U_EXPORT2
646  const char * number,
647  int32_t length,
648  UChar* result,
649  int32_t resultLength,
650  UFieldPosition *pos, /* 0 if ignore */
651  UErrorCode* status);
652 
677 U_STABLE int32_t U_EXPORT2
679  double number,
680  UChar* currency,
681  UChar* result,
682  int32_t resultLength,
683  UFieldPosition* pos,
684  UErrorCode* status);
685 
706 U_STABLE int32_t U_EXPORT2
708  const UFormattable *number,
709  UChar *result,
710  int32_t resultLength,
711  UFieldPosition *pos,
712  UErrorCode *status);
713 
733 U_STABLE int32_t U_EXPORT2
734 unum_parse( const UNumberFormat* fmt,
735  const UChar* text,
736  int32_t textLength,
737  int32_t *parsePos /* 0 = start */,
738  UErrorCode *status);
739 
759 U_STABLE int64_t U_EXPORT2
760 unum_parseInt64(const UNumberFormat* fmt,
761  const UChar* text,
762  int32_t textLength,
763  int32_t *parsePos /* 0 = start */,
764  UErrorCode *status);
765 
785 U_STABLE double U_EXPORT2
786 unum_parseDouble( const UNumberFormat* fmt,
787  const UChar* text,
788  int32_t textLength,
789  int32_t *parsePos /* 0 = start */,
790  UErrorCode *status);
791 
792 
820 U_STABLE int32_t U_EXPORT2
822  const UChar* text,
823  int32_t textLength,
824  int32_t *parsePos /* 0 = start */,
825  char *outBuf,
826  int32_t outBufLength,
827  UErrorCode *status);
828 
848 U_STABLE double U_EXPORT2
850  const UChar* text,
851  int32_t textLength,
852  int32_t* parsePos, /* 0 = start */
853  UChar* currency,
854  UErrorCode* status);
855 
876 U_STABLE UFormattable* U_EXPORT2
878  UFormattable *result,
879  const UChar* text,
880  int32_t textLength,
881  int32_t* parsePos, /* 0 = start */
882  UErrorCode* status);
883 
900 U_STABLE void U_EXPORT2
902  UBool localized,
903  const UChar *pattern,
904  int32_t patternLength,
905  UParseError *parseError,
906  UErrorCode *status
907  );
908 
919 U_STABLE const char* U_EXPORT2
920 unum_getAvailable(int32_t localeIndex);
921 
931 U_STABLE int32_t U_EXPORT2
932 unum_countAvailable(void);
933 
934 #if UCONFIG_HAVE_PARSEALLINPUT
935 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
939 typedef enum UNumberFormatAttributeValue {
940 #ifndef U_HIDE_INTERNAL_API
941 
942  UNUM_NO = 0,
944  UNUM_YES = 1,
946  UNUM_MAYBE = 2
947 #else
948 
949  UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
950 #endif /* U_HIDE_INTERNAL_API */
951 } UNumberFormatAttributeValue;
952 #endif
953 
1001 #if UCONFIG_HAVE_PARSEALLINPUT
1002 
1006  UNUM_PARSE_ALL_INPUT = 20,
1007 #endif
1008 
1018 #ifndef U_HIDE_INTERNAL_API
1019 
1026  /* TODO: test C API when it becomes @draft */
1027 #endif /* U_HIDE_INTERNAL_API */
1028 
1036 
1037  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
1042 
1056 
1066 
1067  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
1072 
1090 U_STABLE int32_t U_EXPORT2
1091 unum_getAttribute(const UNumberFormat* fmt,
1092  UNumberFormatAttribute attr);
1093 
1113 U_STABLE void U_EXPORT2
1116  int32_t newValue);
1117 
1118 
1133 U_STABLE double U_EXPORT2
1135  UNumberFormatAttribute attr);
1136 
1151 U_STABLE void U_EXPORT2
1154  double newValue);
1155 
1189 
1208 U_STABLE int32_t U_EXPORT2
1211  UChar* result,
1212  int32_t resultLength,
1213  UErrorCode* status);
1214 
1231 U_STABLE void U_EXPORT2
1234  const UChar* newValue,
1235  int32_t newValueLength,
1236  UErrorCode *status);
1237 
1254 U_STABLE int32_t U_EXPORT2
1255 unum_toPattern( const UNumberFormat* fmt,
1256  UBool isPatternLocalized,
1257  UChar* result,
1258  int32_t resultLength,
1259  UErrorCode* status);
1260 
1261 
1266 typedef enum UNumberFormatSymbol {
1342 
1347 
1348 #ifndef U_HIDE_DEPRECATED_API
1349 
1354 #endif /* U_HIDE_DEPRECATED_API */
1356 
1373 U_STABLE int32_t U_EXPORT2
1374 unum_getSymbol(const UNumberFormat *fmt,
1375  UNumberFormatSymbol symbol,
1376  UChar *buffer,
1377  int32_t size,
1378  UErrorCode *status);
1379 
1393 U_STABLE void U_EXPORT2
1395  UNumberFormatSymbol symbol,
1396  const UChar *value,
1397  int32_t length,
1398  UErrorCode *status);
1399 
1400 
1410 U_STABLE const char* U_EXPORT2
1412  ULocDataLocaleType type,
1413  UErrorCode* status);
1414 
1423 U_STABLE void U_EXPORT2
1425 
1435 U_STABLE UDisplayContext U_EXPORT2
1436 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1437 
1438 #endif /* #if !UCONFIG_NO_FORMATTING */
1439 
1440 #endif
Default format.
Definition: unum.h:262
void unum_setDoubleAttribute(UNumberFormat *fmt, UNumberFormatAttribute attr, double newValue)
Set a numeric attribute associated with a UNumberFormat.
C API: UFormattable is a thin wrapper for primitive types used for formatting and parsing...
void unum_setSymbol(UNumberFormat *fmt, UNumberFormatSymbol symbol, const UChar *value, int32_t length, UErrorCode *status)
Set a symbol associated with a UNumberFormat.
UNumberFormatRoundingMode
The possible number format rounding modes.
Definition: unum.h:278
double unum_getDoubleAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The exponential symbol.
Definition: unum.h:1290
The monetary grouping separator.
Definition: unum.h:1305
One more than the highest normal UNumberFormatStyle value.
Definition: unum.h:255
Negative prefix.
Definition: unum.h:1163
void unum_setContext(UNumberFormat *fmt, UDisplayContext value, UErrorCode *status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
Numbering system rule-based format.
Definition: unum.h:198
const char * unum_getAvailable(int32_t localeIndex)
Get a locale for which decimal formatting patterns are available.
Currency format (generic).
Definition: unum.h:164
Decimal format ("normal" style).
Definition: unum.h:155
void unum_applyPattern(UNumberFormat *format, UBool localized, const UChar *pattern, int32_t patternLength, UParseError *parseError, UErrorCode *status)
Set the pattern used by a UNumberFormat.
if this attribute is set to 1, specifies that, if the pattern doesn't contain an exponent, the exponent will not be parsed.
Definition: unum.h:1055
UDisplayContext
Display context settings.
Significant digit symbol.
Definition: unum.h:1301
Currency format with a currency symbol, e.g., "$1.00", using non-accounting style for negative values...
Definition: unum.h:248
int32_t unum_parseDecimal(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, char *outBuf, int32_t outBufLength, UErrorCode *status)
Parse a number from a string into an unformatted numeric string using a UNumberFormat.
Rule-based format defined by a pattern string.
Definition: unum.h:203
Lenient parse mode used by rule-based formats.
Definition: unum.h:1000
Decimal format expressed using compact notation (short form, corresponds to UNumberCompactStyle=UNUM_...
Definition: unum.h:234
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:330
double unum_parseDoubleCurrency(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UChar *currency, UErrorCode *status)
Parse a string into a double and a currency using a UNumberFormat.
C API:misc definitions.
ROUND_UNNECESSARY reports an error if formatted result is not exact.
Definition: unum.h:301
struct UFieldPositionIterator UFieldPositionIterator
C typedef for struct UFieldPositionIterator.
Definition: ufieldpositer.h:44
int32_t unum_formatInt64(const UNumberFormat *fmt, int64_t number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format an int64 using a UNumberFormat.
int32_t unum_format(const UNumberFormat *fmt, int32_t number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format an integer using a UNumberFormat.
The grouping separator.
Definition: unum.h:1270
Limit of boolean attributes.
Definition: unum.h:1070
Integer digits.
Definition: unum.h:967
Fraction digits.
Definition: unum.h:973
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1266
Half-even rounding, misspelled name.
Definition: unum.h:293
Positive prefix.
Definition: unum.h:1159
The ISO currency code.
Definition: unum.h:1169
Multiplication sign.
Definition: unum.h:1346
C API: Display context types (enum values)
The minus sign.
Definition: unum.h:1280
Nan symbol.
Definition: unum.h:1298
Currency format with an ISO currency code, e.g., "USD1.00".
Definition: unum.h:208
int32_t unum_formatUFormattable(const UNumberFormat *fmt, const UFormattable *number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a UFormattable into a string.
Currency format with a currency symbol given CASH usage, e.g., "NT$3" instead of "NT$3.23".
Definition: unum.h:227
int64_t unum_parseInt64(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an int64 using a UNumberFormat.
Decimal format defined by a pattern string.
Definition: unum.h:150
Use significant digits.
Definition: unum.h:990
Percent format.
Definition: unum.h:169
Half-even rounding.
Definition: unum.h:287
The position at which padding will take place.
Definition: unum.h:985
Decimal format expressed using compact notation (long form, corresponds to UNumberCompactStyle=UNUM_L...
Definition: unum.h:241
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
Spellout rule-based format.
Definition: unum.h:181
int32_t unum_getTextAttribute(const UNumberFormat *fmt, UNumberFormatTextAttribute tag, UChar *result, int32_t resultLength, UErrorCode *status)
Get a text attribute associated with a UNumberFormat.
UNumberFormatStyle
The possible number format styles.
Definition: unum.h:145
int32_t unum_countAvailable(void)
Determine how many locales have decimal formatting patterns available.
The percent sign.
Definition: unum.h:1274
Infinity symbol.
Definition: unum.h:1296
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:487
void * UNumberFormat
A number formatter.
Definition: unum.h:140
Minimum fraction digits.
Definition: unum.h:971
A struct representing a range of text containing a specific field.
Definition: umisc.h:34
UNumberFormatFields
FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberForma...
Definition: unum.h:354
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
C API: Encapsulates information about a currency.
Maximum significant digits.
Definition: unum.h:996
Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"...
Definition: unum.h:214
One more than the highest normal UNumberFormatSymbol value.
Definition: unum.h:1353
Parse integers only.
Definition: unum.h:957
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:1017
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1157
UNumberFormat * unum_clone(const UNumberFormat *fmt, UErrorCode *status)
Open a copy of a UNumberFormat.
Maximum fraction digits.
Definition: unum.h:969
Secondary grouping size.
Definition: unum.h:987
The width to which the output of format() is padded.
Definition: unum.h:983
Alias for UNUM_PATTERN_DECIMAL.
Definition: unum.h:267
"Smart pointer" class, closes a UNumberFormat via unum_close().
One below the first bitfield-boolean item.
Definition: unum.h:1041
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:307
Per mill symbol.
Definition: unum.h:1292
The pattern separator.
Definition: unum.h:1272
UDisplayContext unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode *status)
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
Scientific format.
Definition: unum.h:174
Use grouping separator.
Definition: unum.h:959
Minimum grouping digits, technology preview.
Definition: unum.h:1025
int32_t unum_formatDouble(const UNumberFormat *fmt, double number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a double using a UNumberFormat.
If 1, specifies that if setting the "max integer digits" attribute would truncate a value...
Definition: unum.h:1048
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:353
Positive suffix.
Definition: unum.h:1161
Multiplier.
Definition: unum.h:975
Minimum integer digits.
Definition: unum.h:965
const char * unum_getLocaleByType(const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode *status)
Get the locale for this number format object.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:318
UDisplayContextType
Display context types, for getting values of a particular setting.
Ordinal rule-based format .
Definition: unum.h:188
Escape padding character.
Definition: unum.h:1294
C API: Parse Error Information.
void unum_setAttribute(UNumberFormat *fmt, UNumberFormatAttribute attr, int32_t newValue)
Set a numeric attribute associated with a UNumberFormat.
The character used to pad to the format width.
Definition: unum.h:1167
if this attribute is set to 1, specifies that, if the pattern contains a decimal mark the input is re...
Definition: unum.h:1065
UNumberFormat * unum_open(UNumberFormatStyle style, const UChar *pattern, int32_t patternLength, const char *locale, UParseError *parseErr, UErrorCode *status)
Create and return a new UNumberFormat for formatting and parsing numbers.
Rounding Mode.
Definition: unum.h:979
The decimal separator.
Definition: unum.h:1268
int32_t unum_formatDoubleForFields(const UNumberFormat *format, double number, UChar *result, int32_t resultLength, UFieldPositionIterator *fpositer, UErrorCode *status)
Format a double using a UNumberFormat according to the UNumberFormat's locale, and initialize a UFiel...
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:338
Currency format for accounting, e.g., "($3.00)" for negative currency amount instead of "-$3...
Definition: unum.h:221
double unum_parseDouble(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into a double using a UNumberFormat.
int32_t unum_getSymbol(const UNumberFormat *fmt, UNumberFormatSymbol symbol, UChar *buffer, int32_t size, UErrorCode *status)
Get a symbol associated with a UNumberFormat.
Rounding increment.
Definition: unum.h:981
C API: UFieldPositionIterator for use with format APIs.
Minimum significant digits.
Definition: unum.h:993
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
int32_t unum_formatDoubleCurrency(const UNumberFormat *fmt, double number, UChar *currency, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a double currency amount using a UNumberFormat.
Basic definitions for ICU, for both C and C++ APIs.
UFormattable * unum_parseToUFormattable(const UNumberFormat *fmt, UFormattable *result, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a UChar string into a UFormattable.
The international currency symbol.
Definition: unum.h:1286
int32_t unum_getAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The default rule set, such as "%spellout-numbering-year:", "%spellout-cardinal:", "%spellout-ordinal-...
Definition: unum.h:1178
The monetary separator.
Definition: unum.h:1288
int32_t unum_toPattern(const UNumberFormat *fmt, UBool isPatternLocalized, UChar *result, int32_t resultLength, UErrorCode *status)
Extract the pattern from a UNumberFormat.
int32_t unum_formatDecimal(const UNumberFormat *fmt, const char *number, int32_t length, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
Format a decimal number using a UNumberFormat.
if this attribute is set to 0, it is set to UNUM_CURRENCY_STANDARD purpose, otherwise it is UNUM_CURR...
Definition: unum.h:1035
The currency symbol.
Definition: unum.h:1284
The plus sign.
Definition: unum.h:1282
Duration rule-based format.
Definition: unum.h:193
void * UFormattable
Opaque type representing various types of data which may be used for formatting and parsing operation...
Definition: uformattable.h:70
UNumberFormatAttribute
The possible UNumberFormat numeric attributes.
Definition: unum.h:955
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1165
One more than the highest normal UNumberFormatFields value.
Definition: unum.h:382
Grouping size.
Definition: unum.h:977
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:344
int32_t unum_parse(const UNumberFormat *fmt, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an integer using a UNumberFormat.
The public rule sets.
Definition: unum.h:1187
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
Maximum integer digits.
Definition: unum.h:963
Character representing a digit in the pattern.
Definition: unum.h:1278
C API: Locale.
Always show decimal point.
Definition: unum.h:961
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.