ICU 65.1  65.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 
141 typedef void* UNumberFormat;
142 
146 typedef enum UNumberFormatStyle {
250 
251 #ifndef U_HIDE_DEPRECATED_API
252 
257 #endif /* U_HIDE_DEPRECATED_API */
258 
270 
280  UNUM_ROUND_CEILING,
281  UNUM_ROUND_FLOOR,
282  UNUM_ROUND_DOWN,
283  UNUM_ROUND_UP,
289 #ifndef U_HIDE_DEPRECATED_API
290 
295 #endif /* U_HIDE_DEPRECATED_API */
296  UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
297  UNUM_ROUND_HALFUP,
304 
309  UNUM_PAD_BEFORE_PREFIX,
310  UNUM_PAD_AFTER_PREFIX,
311  UNUM_PAD_BEFORE_SUFFIX,
312  UNUM_PAD_AFTER_SUFFIX
314 
319 typedef enum UNumberCompactStyle {
326 
338 
339  /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
340  * it is needed for layout of DecimalFormatSymbols object. */
341 #ifndef U_FORCE_HIDE_DEPRECATED_API
342 
347 #endif // U_FORCE_HIDE_DEPRECATED_API
348 };
357 typedef enum UNumberFormatFields {
380 #ifndef U_HIDE_DRAFT_API
381 
385 #endif /* U_HIDE_DRAFT_API */
386 
387 #ifndef U_HIDE_DEPRECATED_API
388 
393 #endif /* U_HIDE_DEPRECATED_API */
395 
396 
434 U_STABLE UNumberFormat* U_EXPORT2
436  const UChar* pattern,
437  int32_t patternLength,
438  const char* locale,
439  UParseError* parseErr,
440  UErrorCode* status);
441 
442 
449 U_STABLE void U_EXPORT2
451 
452 #if U_SHOW_CPLUSPLUS_API
453 
454 U_NAMESPACE_BEGIN
455 
466 
467 U_NAMESPACE_END
468 
469 #endif
470 
479 U_STABLE UNumberFormat* U_EXPORT2
480 unum_clone(const UNumberFormat *fmt,
481  UErrorCode *status);
482 
507 U_STABLE int32_t U_EXPORT2
508 unum_format( const UNumberFormat* fmt,
509  int32_t number,
510  UChar* result,
511  int32_t resultLength,
512  UFieldPosition *pos,
513  UErrorCode* status);
514 
539 U_STABLE int32_t U_EXPORT2
541  int64_t number,
542  UChar* result,
543  int32_t resultLength,
544  UFieldPosition *pos,
545  UErrorCode* status);
546 
571 U_STABLE int32_t U_EXPORT2
572 unum_formatDouble( const UNumberFormat* fmt,
573  double number,
574  UChar* result,
575  int32_t resultLength,
576  UFieldPosition *pos, /* 0 if ignore */
577  UErrorCode* status);
578 
621 U_STABLE int32_t U_EXPORT2
623  double number,
624  UChar* result,
625  int32_t resultLength,
626  UFieldPositionIterator* fpositer,
627  UErrorCode* status);
628 
629 
658 U_STABLE int32_t U_EXPORT2
660  const char * number,
661  int32_t length,
662  UChar* result,
663  int32_t resultLength,
664  UFieldPosition *pos, /* 0 if ignore */
665  UErrorCode* status);
666 
691 U_STABLE int32_t U_EXPORT2
693  double number,
694  UChar* currency,
695  UChar* result,
696  int32_t resultLength,
697  UFieldPosition* pos,
698  UErrorCode* status);
699 
720 U_STABLE int32_t U_EXPORT2
722  const UFormattable *number,
723  UChar *result,
724  int32_t resultLength,
725  UFieldPosition *pos,
726  UErrorCode *status);
727 
747 U_STABLE int32_t U_EXPORT2
748 unum_parse( const UNumberFormat* fmt,
749  const UChar* text,
750  int32_t textLength,
751  int32_t *parsePos /* 0 = start */,
752  UErrorCode *status);
753 
773 U_STABLE int64_t U_EXPORT2
774 unum_parseInt64(const UNumberFormat* fmt,
775  const UChar* text,
776  int32_t textLength,
777  int32_t *parsePos /* 0 = start */,
778  UErrorCode *status);
779 
799 U_STABLE double U_EXPORT2
800 unum_parseDouble( const UNumberFormat* fmt,
801  const UChar* text,
802  int32_t textLength,
803  int32_t *parsePos /* 0 = start */,
804  UErrorCode *status);
805 
806 
834 U_STABLE int32_t U_EXPORT2
836  const UChar* text,
837  int32_t textLength,
838  int32_t *parsePos /* 0 = start */,
839  char *outBuf,
840  int32_t outBufLength,
841  UErrorCode *status);
842 
862 U_STABLE double U_EXPORT2
864  const UChar* text,
865  int32_t textLength,
866  int32_t* parsePos, /* 0 = start */
867  UChar* currency,
868  UErrorCode* status);
869 
890 U_STABLE UFormattable* U_EXPORT2
892  UFormattable *result,
893  const UChar* text,
894  int32_t textLength,
895  int32_t* parsePos, /* 0 = start */
896  UErrorCode* status);
897 
914 U_STABLE void U_EXPORT2
916  UBool localized,
917  const UChar *pattern,
918  int32_t patternLength,
919  UParseError *parseError,
920  UErrorCode *status
921  );
922 
933 U_STABLE const char* U_EXPORT2
934 unum_getAvailable(int32_t localeIndex);
935 
945 U_STABLE int32_t U_EXPORT2
946 unum_countAvailable(void);
947 
948 #if UCONFIG_HAVE_PARSEALLINPUT
949 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
953 typedef enum UNumberFormatAttributeValue {
954 #ifndef U_HIDE_INTERNAL_API
955 
956  UNUM_NO = 0,
958  UNUM_YES = 1,
960  UNUM_MAYBE = 2
961 #else
962 
963  UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
964 #endif /* U_HIDE_INTERNAL_API */
965 } UNumberFormatAttributeValue;
966 #endif
967 
1015 #if UCONFIG_HAVE_PARSEALLINPUT
1016 
1020  UNUM_PARSE_ALL_INPUT = 20,
1021 #endif
1022 
1034 
1035 #ifndef U_HIDE_DRAFT_API
1036 
1045 #endif /* U_HIDE_DRAFT_API */
1046 
1054 
1055 #ifndef U_HIDE_INTERNAL_API
1056 
1060 #endif /* U_HIDE_INTERNAL_API */
1061 
1075 
1085 
1086 #ifndef U_HIDE_DRAFT_API
1087 
1094 
1103 
1104 #endif /* U_HIDE_DRAFT_API */
1105 
1106 #ifndef U_HIDE_INTERNAL_API
1107 
1111 #endif /* U_HIDE_INTERNAL_API */
1112 
1114 
1132 U_STABLE int32_t U_EXPORT2
1133 unum_getAttribute(const UNumberFormat* fmt,
1134  UNumberFormatAttribute attr);
1135 
1155 U_STABLE void U_EXPORT2
1158  int32_t newValue);
1159 
1160 
1175 U_STABLE double U_EXPORT2
1177  UNumberFormatAttribute attr);
1178 
1193 U_STABLE void U_EXPORT2
1196  double newValue);
1197 
1231 
1250 U_STABLE int32_t U_EXPORT2
1253  UChar* result,
1254  int32_t resultLength,
1255  UErrorCode* status);
1256 
1273 U_STABLE void U_EXPORT2
1276  const UChar* newValue,
1277  int32_t newValueLength,
1278  UErrorCode *status);
1279 
1296 U_STABLE int32_t U_EXPORT2
1297 unum_toPattern( const UNumberFormat* fmt,
1298  UBool isPatternLocalized,
1299  UChar* result,
1300  int32_t resultLength,
1301  UErrorCode* status);
1302 
1303 
1308 typedef enum UNumberFormatSymbol {
1384 
1389 
1390 #ifndef U_HIDE_DEPRECATED_API
1391 
1396 #endif /* U_HIDE_DEPRECATED_API */
1398 
1415 U_STABLE int32_t U_EXPORT2
1416 unum_getSymbol(const UNumberFormat *fmt,
1417  UNumberFormatSymbol symbol,
1418  UChar *buffer,
1419  int32_t size,
1420  UErrorCode *status);
1421 
1435 U_STABLE void U_EXPORT2
1437  UNumberFormatSymbol symbol,
1438  const UChar *value,
1439  int32_t length,
1440  UErrorCode *status);
1441 
1442 
1452 U_STABLE const char* U_EXPORT2
1454  ULocDataLocaleType type,
1455  UErrorCode* status);
1456 
1465 U_STABLE void U_EXPORT2
1467 
1477 U_STABLE UDisplayContext U_EXPORT2
1478 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1479 
1480 #endif /* #if !UCONFIG_NO_FORMATTING */
1481 
1482 #endif
Default format.
Definition: unum.h:263
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:279
double unum_getDoubleAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The exponential symbol.
Definition: unum.h:1332
The monetary grouping separator.
Definition: unum.h:1347
One more than the highest normal UNumberFormatStyle value.
Definition: unum.h:256
Negative prefix.
Definition: unum.h:1205
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:199
const char * unum_getAvailable(int32_t localeIndex)
Get a locale for which decimal formatting patterns are available.
Currency format (generic).
Definition: unum.h:165
Decimal format ("normal" style).
Definition: unum.h:156
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:1074
UDisplayContext
Display context settings.
Significant digit symbol.
Definition: unum.h:1343
Currency format with a currency symbol, e.g., "$1.00", using non-accounting style for negative values...
Definition: unum.h:249
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:204
Formatting: if set to 1, whether to show the plus sign on non-negative numbers.
Definition: unum.h:1102
Lenient parse mode used by rule-based formats.
Definition: unum.h:1014
Decimal format expressed using compact notation (short form, corresponds to UNumberCompactStyle=UNUM_...
Definition: unum.h:235
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:331
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:302
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:1312
Limit of boolean attributes.
Definition: unum.h:1110
Integer digits.
Definition: unum.h:981
Fraction digits.
Definition: unum.h:987
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1308
Half-even rounding, misspelled name.
Definition: unum.h:294
Positive prefix.
Definition: unum.h:1201
The ISO currency code.
Definition: unum.h:1211
Multiplication sign.
Definition: unum.h:1388
C API: Display context types (enum values)
The minus sign.
Definition: unum.h:1322
Nan symbol.
Definition: unum.h:1340
Currency format with an ISO currency code, e.g., "USD1.00".
Definition: unum.h:209
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:228
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:151
Use significant digits.
Definition: unum.h:1004
Percent format.
Definition: unum.h:170
Half-even rounding.
Definition: unum.h:288
The position at which padding will take place.
Definition: unum.h:999
Decimal format expressed using compact notation (long form, corresponds to UNumberCompactStyle=UNUM_L...
Definition: unum.h:242
Spellout rule-based format.
Definition: unum.h:182
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:146
int32_t unum_countAvailable(void)
Determine how many locales have decimal formatting patterns available.
The percent sign.
Definition: unum.h:1316
Infinity symbol.
Definition: unum.h:1338
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:562
void * UNumberFormat
A number formatter.
Definition: unum.h:141
Minimum fraction digits.
Definition: unum.h:985
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:357
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:1010
Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"...
Definition: unum.h:215
One more than the highest normal UNumberFormatSymbol value.
Definition: unum.h:1395
Parse integers only.
Definition: unum.h:971
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:1033
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1199
UNumberFormat * unum_clone(const UNumberFormat *fmt, UErrorCode *status)
Open a copy of a UNumberFormat.
Parsing: if set to 1, parsing is sensitive to case (lowercase/uppercase).
Definition: unum.h:1093
Maximum fraction digits.
Definition: unum.h:983
Secondary grouping size.
Definition: unum.h:1001
The width to which the output of format() is padded.
Definition: unum.h:997
Alias for UNUM_PATTERN_DECIMAL.
Definition: unum.h:268
"Smart pointer" class, closes a UNumberFormat via unum_close().
One below the first bitfield-boolean item.
Definition: unum.h:1059
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:308
Per mill symbol.
Definition: unum.h:1334
The pattern separator.
Definition: unum.h:1314
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:175
Use grouping separator.
Definition: unum.h:973
Minimum grouping digits; most commonly set to 2 to print "1000" instead of "1,000".
Definition: unum.h:1044
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:1067
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
Positive suffix.
Definition: unum.h:1203
Multiplier.
Definition: unum.h:989
Minimum integer digits.
Definition: unum.h:979
const char * unum_getLocaleByType(const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode *status)
Get the locale for this number format object.
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:319
UDisplayContextType
Display context types, for getting values of a particular setting.
Ordinal rule-based format .
Definition: unum.h:189
Escape padding character.
Definition: unum.h:1336
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:1209
if this attribute is set to 1, specifies that, if the pattern contains a decimal mark the input is re...
Definition: unum.h:1084
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:993
The decimal separator.
Definition: unum.h:1310
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
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
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:222
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:995
C API: UFieldPositionIterator for use with format APIs.
Minimum significant digits.
Definition: unum.h:1007
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:1328
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:1220
The monetary separator.
Definition: unum.h:1330
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:1053
The currency symbol.
Definition: unum.h:1326
The plus sign.
Definition: unum.h:1324
Duration rule-based format.
Definition: unum.h:194
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:969
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1207
One more than the highest normal UNumberFormatFields value.
Definition: unum.h:392
Grouping size.
Definition: unum.h:991
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:346
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:1229
#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:261
Maximum integer digits.
Definition: unum.h:977
Character representing a digit in the pattern.
Definition: unum.h:1320
C API: Locale.
Always show decimal point.
Definition: unum.h:975
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.