ICU 64.2  64.2
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. */
346 };
355 typedef enum UNumberFormatFields {
378 #ifndef U_HIDE_DRAFT_API
379 
383 #endif /* U_HIDE_DRAFT_API */
384 
385 #ifndef U_HIDE_DEPRECATED_API
386 
391 #endif /* U_HIDE_DEPRECATED_API */
393 
394 
432 U_STABLE UNumberFormat* U_EXPORT2
434  const UChar* pattern,
435  int32_t patternLength,
436  const char* locale,
437  UParseError* parseErr,
438  UErrorCode* status);
439 
440 
447 U_STABLE void U_EXPORT2
449 
450 #if U_SHOW_CPLUSPLUS_API
451 
453 
464 
466 
467 #endif
468 
477 U_STABLE UNumberFormat* U_EXPORT2
478 unum_clone(const UNumberFormat *fmt,
479  UErrorCode *status);
480 
505 U_STABLE int32_t U_EXPORT2
506 unum_format( const UNumberFormat* fmt,
507  int32_t number,
508  UChar* result,
509  int32_t resultLength,
510  UFieldPosition *pos,
511  UErrorCode* status);
512 
537 U_STABLE int32_t U_EXPORT2
539  int64_t number,
540  UChar* result,
541  int32_t resultLength,
542  UFieldPosition *pos,
543  UErrorCode* status);
544 
569 U_STABLE int32_t U_EXPORT2
570 unum_formatDouble( const UNumberFormat* fmt,
571  double number,
572  UChar* result,
573  int32_t resultLength,
574  UFieldPosition *pos, /* 0 if ignore */
575  UErrorCode* status);
576 
619 U_STABLE int32_t U_EXPORT2
621  double number,
622  UChar* result,
623  int32_t resultLength,
624  UFieldPositionIterator* fpositer,
625  UErrorCode* status);
626 
627 
656 U_STABLE int32_t U_EXPORT2
658  const char * number,
659  int32_t length,
660  UChar* result,
661  int32_t resultLength,
662  UFieldPosition *pos, /* 0 if ignore */
663  UErrorCode* status);
664 
689 U_STABLE int32_t U_EXPORT2
691  double number,
692  UChar* currency,
693  UChar* result,
694  int32_t resultLength,
695  UFieldPosition* pos,
696  UErrorCode* status);
697 
718 U_STABLE int32_t U_EXPORT2
720  const UFormattable *number,
721  UChar *result,
722  int32_t resultLength,
723  UFieldPosition *pos,
724  UErrorCode *status);
725 
745 U_STABLE int32_t U_EXPORT2
746 unum_parse( const UNumberFormat* fmt,
747  const UChar* text,
748  int32_t textLength,
749  int32_t *parsePos /* 0 = start */,
750  UErrorCode *status);
751 
771 U_STABLE int64_t U_EXPORT2
772 unum_parseInt64(const UNumberFormat* fmt,
773  const UChar* text,
774  int32_t textLength,
775  int32_t *parsePos /* 0 = start */,
776  UErrorCode *status);
777 
797 U_STABLE double U_EXPORT2
798 unum_parseDouble( const UNumberFormat* fmt,
799  const UChar* text,
800  int32_t textLength,
801  int32_t *parsePos /* 0 = start */,
802  UErrorCode *status);
803 
804 
832 U_STABLE int32_t U_EXPORT2
834  const UChar* text,
835  int32_t textLength,
836  int32_t *parsePos /* 0 = start */,
837  char *outBuf,
838  int32_t outBufLength,
839  UErrorCode *status);
840 
860 U_STABLE double U_EXPORT2
862  const UChar* text,
863  int32_t textLength,
864  int32_t* parsePos, /* 0 = start */
865  UChar* currency,
866  UErrorCode* status);
867 
888 U_STABLE UFormattable* U_EXPORT2
890  UFormattable *result,
891  const UChar* text,
892  int32_t textLength,
893  int32_t* parsePos, /* 0 = start */
894  UErrorCode* status);
895 
912 U_STABLE void U_EXPORT2
914  UBool localized,
915  const UChar *pattern,
916  int32_t patternLength,
917  UParseError *parseError,
918  UErrorCode *status
919  );
920 
931 U_STABLE const char* U_EXPORT2
932 unum_getAvailable(int32_t localeIndex);
933 
943 U_STABLE int32_t U_EXPORT2
944 unum_countAvailable(void);
945 
946 #if UCONFIG_HAVE_PARSEALLINPUT
947 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
951 typedef enum UNumberFormatAttributeValue {
952 #ifndef U_HIDE_INTERNAL_API
953 
954  UNUM_NO = 0,
956  UNUM_YES = 1,
958  UNUM_MAYBE = 2
959 #else
960 
961  UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
962 #endif /* U_HIDE_INTERNAL_API */
963 } UNumberFormatAttributeValue;
964 #endif
965 
1013 #if UCONFIG_HAVE_PARSEALLINPUT
1014 
1018  UNUM_PARSE_ALL_INPUT = 20,
1019 #endif
1020 
1032 
1033 #ifndef U_HIDE_DRAFT_API
1034 
1043 #endif /* U_HIDE_DRAFT_API */
1044 
1052 
1053 #ifndef U_HIDE_INTERNAL_API
1054 
1058 #endif /* U_HIDE_INTERNAL_API */
1059 
1073 
1083 
1084 #ifndef U_HIDE_DRAFT_API
1085 
1092 
1101 
1102 #endif /* U_HIDE_DRAFT_API */
1103 
1104 #ifndef U_HIDE_INTERNAL_API
1105 
1109 #endif /* U_HIDE_INTERNAL_API */
1110 
1112 
1130 U_STABLE int32_t U_EXPORT2
1131 unum_getAttribute(const UNumberFormat* fmt,
1132  UNumberFormatAttribute attr);
1133 
1153 U_STABLE void U_EXPORT2
1156  int32_t newValue);
1157 
1158 
1173 U_STABLE double U_EXPORT2
1175  UNumberFormatAttribute attr);
1176 
1191 U_STABLE void U_EXPORT2
1194  double newValue);
1195 
1229 
1248 U_STABLE int32_t U_EXPORT2
1251  UChar* result,
1252  int32_t resultLength,
1253  UErrorCode* status);
1254 
1271 U_STABLE void U_EXPORT2
1274  const UChar* newValue,
1275  int32_t newValueLength,
1276  UErrorCode *status);
1277 
1294 U_STABLE int32_t U_EXPORT2
1295 unum_toPattern( const UNumberFormat* fmt,
1296  UBool isPatternLocalized,
1297  UChar* result,
1298  int32_t resultLength,
1299  UErrorCode* status);
1300 
1301 
1306 typedef enum UNumberFormatSymbol {
1382 
1387 
1388 #ifndef U_HIDE_DEPRECATED_API
1389 
1394 #endif /* U_HIDE_DEPRECATED_API */
1396 
1413 U_STABLE int32_t U_EXPORT2
1414 unum_getSymbol(const UNumberFormat *fmt,
1415  UNumberFormatSymbol symbol,
1416  UChar *buffer,
1417  int32_t size,
1418  UErrorCode *status);
1419 
1433 U_STABLE void U_EXPORT2
1435  UNumberFormatSymbol symbol,
1436  const UChar *value,
1437  int32_t length,
1438  UErrorCode *status);
1439 
1440 
1450 U_STABLE const char* U_EXPORT2
1452  ULocDataLocaleType type,
1453  UErrorCode* status);
1454 
1463 U_STABLE void U_EXPORT2
1465 
1475 U_STABLE UDisplayContext U_EXPORT2
1476 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1477 
1478 #endif /* #if !UCONFIG_NO_FORMATTING */
1479 
1480 #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:1330
The monetary grouping separator.
Definition: unum.h:1345
One more than the highest normal UNumberFormatStyle value.
Definition: unum.h:256
Negative prefix.
Definition: unum.h:1203
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:1072
UDisplayContext
Display context settings.
Significant digit symbol.
Definition: unum.h:1341
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:1100
Lenient parse mode used by rule-based formats.
Definition: unum.h:1012
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:1310
Limit of boolean attributes.
Definition: unum.h:1108
Integer digits.
Definition: unum.h:979
Fraction digits.
Definition: unum.h:985
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1306
Half-even rounding, misspelled name.
Definition: unum.h:294
Positive prefix.
Definition: unum.h:1199
The ISO currency code.
Definition: unum.h:1209
Multiplication sign.
Definition: unum.h:1386
C API: Display context types (enum values)
The minus sign.
Definition: unum.h:1320
Nan symbol.
Definition: unum.h:1338
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:1002
Percent format.
Definition: unum.h:170
Half-even rounding.
Definition: unum.h:288
The position at which padding will take place.
Definition: unum.h:997
Decimal format expressed using compact notation (long form, corresponds to UNumberCompactStyle=UNUM_L...
Definition: unum.h:242
#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: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:1314
Infinity symbol.
Definition: unum.h:1336
#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:983
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:355
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:1008
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:1393
Parse integers only.
Definition: unum.h:969
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:1031
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1197
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:1091
Maximum fraction digits.
Definition: unum.h:981
Secondary grouping size.
Definition: unum.h:999
The width to which the output of format() is padded.
Definition: unum.h:995
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:1057
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:308
Per mill symbol.
Definition: unum.h:1332
The pattern separator.
Definition: unum.h:1312
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:971
Minimum grouping digits; most commonly set to 2 to print "1000" instead of "1,000".
Definition: unum.h:1042
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:1065
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:342
Positive suffix.
Definition: unum.h:1201
Multiplier.
Definition: unum.h:987
Minimum integer digits.
Definition: unum.h:977
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: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:1334
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:1207
if this attribute is set to 1, specifies that, if the pattern contains a decimal mark the input is re...
Definition: unum.h:1082
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:991
The decimal separator.
Definition: unum.h:1308
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:401
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:993
C API: UFieldPositionIterator for use with format APIs.
Minimum significant digits.
Definition: unum.h:1005
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:1326
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:1218
The monetary separator.
Definition: unum.h:1328
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:1051
The currency symbol.
Definition: unum.h:1324
The plus sign.
Definition: unum.h:1322
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:967
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1205
One more than the highest normal UNumberFormatFields value.
Definition: unum.h:390
Grouping size.
Definition: unum.h:989
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:345
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:1227
#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:225
Maximum integer digits.
Definition: unum.h:975
Character representing a digit in the pattern.
Definition: unum.h:1318
C API: Locale.
Always show decimal point.
Definition: unum.h:973
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.