ICU 59.1  59.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 
137 typedef void* UNumberFormat;
138 
142 typedef enum UNumberFormatStyle {
246 
247 #ifndef U_HIDE_DEPRECATED_API
248 
253 #endif /* U_HIDE_DEPRECATED_API */
254 
266 
271  UNUM_ROUND_CEILING,
272  UNUM_ROUND_FLOOR,
273  UNUM_ROUND_DOWN,
274  UNUM_ROUND_UP,
280 #ifndef U_HIDE_DEPRECATED_API
281 
286 #endif /* U_HIDE_DEPRECATED_API */
287  UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
288  UNUM_ROUND_HALFUP,
295 
300  UNUM_PAD_BEFORE_PREFIX,
301  UNUM_PAD_AFTER_PREFIX,
302  UNUM_PAD_BEFORE_SUFFIX,
303  UNUM_PAD_AFTER_SUFFIX
305 
310 typedef enum UNumberCompactStyle {
317 
329 
330  /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
331  * it is needed for layout of DecimalFormatSymbols object. */
337 };
346 typedef enum UNumberFormatFields {
369 #ifndef U_HIDE_DEPRECATED_API
370 
375 #endif /* U_HIDE_DEPRECATED_API */
377 
378 
412 U_STABLE UNumberFormat* U_EXPORT2
414  const UChar* pattern,
415  int32_t patternLength,
416  const char* locale,
417  UParseError* parseErr,
418  UErrorCode* status);
419 
420 
427 U_STABLE void U_EXPORT2
429 
430 #if U_SHOW_CPLUSPLUS_API
431 
433 
444 
446 
447 #endif
448 
457 U_STABLE UNumberFormat* U_EXPORT2
458 unum_clone(const UNumberFormat *fmt,
459  UErrorCode *status);
460 
485 U_STABLE int32_t U_EXPORT2
486 unum_format( const UNumberFormat* fmt,
487  int32_t number,
488  UChar* result,
489  int32_t resultLength,
490  UFieldPosition *pos,
491  UErrorCode* status);
492 
517 U_STABLE int32_t U_EXPORT2
519  int64_t number,
520  UChar* result,
521  int32_t resultLength,
522  UFieldPosition *pos,
523  UErrorCode* status);
524 
549 U_STABLE int32_t U_EXPORT2
550 unum_formatDouble( const UNumberFormat* fmt,
551  double number,
552  UChar* result,
553  int32_t resultLength,
554  UFieldPosition *pos, /* 0 if ignore */
555  UErrorCode* status);
556 
557 #ifndef U_HIDE_DRAFT_API
558 
600 U_DRAFT int32_t U_EXPORT2
602  double number,
603  UChar* result,
604  int32_t resultLength,
605  UFieldPositionIterator* fpositer,
606  UErrorCode* status);
607 
608 #endif /* U_HIDE_DRAFT_API */
609 
638 U_STABLE int32_t U_EXPORT2
640  const char * number,
641  int32_t length,
642  UChar* result,
643  int32_t resultLength,
644  UFieldPosition *pos, /* 0 if ignore */
645  UErrorCode* status);
646 
671 U_STABLE int32_t U_EXPORT2
673  double number,
674  UChar* currency,
675  UChar* result,
676  int32_t resultLength,
677  UFieldPosition* pos,
678  UErrorCode* status);
679 
700 U_STABLE int32_t U_EXPORT2
702  const UFormattable *number,
703  UChar *result,
704  int32_t resultLength,
705  UFieldPosition *pos,
706  UErrorCode *status);
707 
727 U_STABLE int32_t U_EXPORT2
728 unum_parse( const UNumberFormat* fmt,
729  const UChar* text,
730  int32_t textLength,
731  int32_t *parsePos /* 0 = start */,
732  UErrorCode *status);
733 
753 U_STABLE int64_t U_EXPORT2
754 unum_parseInt64(const UNumberFormat* fmt,
755  const UChar* text,
756  int32_t textLength,
757  int32_t *parsePos /* 0 = start */,
758  UErrorCode *status);
759 
779 U_STABLE double U_EXPORT2
780 unum_parseDouble( const UNumberFormat* fmt,
781  const UChar* text,
782  int32_t textLength,
783  int32_t *parsePos /* 0 = start */,
784  UErrorCode *status);
785 
786 
814 U_STABLE int32_t U_EXPORT2
816  const UChar* text,
817  int32_t textLength,
818  int32_t *parsePos /* 0 = start */,
819  char *outBuf,
820  int32_t outBufLength,
821  UErrorCode *status);
822 
842 U_STABLE double U_EXPORT2
844  const UChar* text,
845  int32_t textLength,
846  int32_t* parsePos, /* 0 = start */
847  UChar* currency,
848  UErrorCode* status);
849 
870 U_STABLE UFormattable* U_EXPORT2
872  UFormattable *result,
873  const UChar* text,
874  int32_t textLength,
875  int32_t* parsePos, /* 0 = start */
876  UErrorCode* status);
877 
894 U_STABLE void U_EXPORT2
896  UBool localized,
897  const UChar *pattern,
898  int32_t patternLength,
899  UParseError *parseError,
900  UErrorCode *status
901  );
902 
913 U_STABLE const char* U_EXPORT2
914 unum_getAvailable(int32_t localeIndex);
915 
925 U_STABLE int32_t U_EXPORT2
926 unum_countAvailable(void);
927 
928 #if UCONFIG_HAVE_PARSEALLINPUT
929 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
933 typedef enum UNumberFormatAttributeValue {
934 #ifndef U_HIDE_INTERNAL_API
935 
936  UNUM_NO = 0,
938  UNUM_YES = 1,
940  UNUM_MAYBE = 2
941 #else
942 
943  UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
944 #endif /* U_HIDE_INTERNAL_API */
945 } UNumberFormatAttributeValue;
946 #endif
947 
995 #if UCONFIG_HAVE_PARSEALLINPUT
996 
1000  UNUM_PARSE_ALL_INPUT = 20,
1001 #endif
1002 
1012 #ifndef U_HIDE_INTERNAL_API
1013 
1020  /* TODO: test C API when it becomes @draft */
1021 #endif /* U_HIDE_INTERNAL_API */
1022 
1030 
1031  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
1036 
1050 
1060 
1061  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
1066 
1084 U_STABLE int32_t U_EXPORT2
1085 unum_getAttribute(const UNumberFormat* fmt,
1086  UNumberFormatAttribute attr);
1087 
1107 U_STABLE void U_EXPORT2
1110  int32_t newValue);
1111 
1112 
1127 U_STABLE double U_EXPORT2
1129  UNumberFormatAttribute attr);
1130 
1145 U_STABLE void U_EXPORT2
1148  double newValue);
1149 
1183 
1202 U_STABLE int32_t U_EXPORT2
1205  UChar* result,
1206  int32_t resultLength,
1207  UErrorCode* status);
1208 
1225 U_STABLE void U_EXPORT2
1228  const UChar* newValue,
1229  int32_t newValueLength,
1230  UErrorCode *status);
1231 
1248 U_STABLE int32_t U_EXPORT2
1249 unum_toPattern( const UNumberFormat* fmt,
1250  UBool isPatternLocalized,
1251  UChar* result,
1252  int32_t resultLength,
1253  UErrorCode* status);
1254 
1255 
1260 typedef enum UNumberFormatSymbol {
1336 
1341 
1342 #ifndef U_HIDE_DEPRECATED_API
1343 
1348 #endif /* U_HIDE_DEPRECATED_API */
1350 
1367 U_STABLE int32_t U_EXPORT2
1368 unum_getSymbol(const UNumberFormat *fmt,
1369  UNumberFormatSymbol symbol,
1370  UChar *buffer,
1371  int32_t size,
1372  UErrorCode *status);
1373 
1387 U_STABLE void U_EXPORT2
1389  UNumberFormatSymbol symbol,
1390  const UChar *value,
1391  int32_t length,
1392  UErrorCode *status);
1393 
1394 
1404 U_STABLE const char* U_EXPORT2
1406  ULocDataLocaleType type,
1407  UErrorCode* status);
1408 
1417 U_STABLE void U_EXPORT2
1419 
1429 U_STABLE UDisplayContext U_EXPORT2
1430 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1431 
1432 #endif /* #if !UCONFIG_NO_FORMATTING */
1433 
1434 #endif
Default format.
Definition: unum.h:259
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:270
double unum_getDoubleAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The exponential symbol.
Definition: unum.h:1284
The monetary grouping separator.
Definition: unum.h:1299
One more than the highest normal UNumberFormatStyle value.
Definition: unum.h:252
Negative prefix.
Definition: unum.h:1157
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:195
const char * unum_getAvailable(int32_t localeIndex)
Get a locale for which decimal formatting patterns are available.
Currency format (generic).
Definition: unum.h:161
Decimal format ("normal" style).
Definition: unum.h:152
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:1049
UDisplayContext
Display context settings.
Significant digit symbol.
Definition: unum.h:1295
Currency format with a currency symbol, e.g., "$1.00", using non-accounting style for negative values...
Definition: unum.h:245
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:200
Lenient parse mode used by rule-based formats.
Definition: unum.h:994
Decimal format expressed using compact notation (short form, corresponds to UNumberCompactStyle=UNUM_...
Definition: unum.h:231
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:322
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:293
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:1264
Limit of boolean attributes.
Definition: unum.h:1064
Integer digits.
Definition: unum.h:961
Fraction digits.
Definition: unum.h:967
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1260
Half-even rounding, misspelled name.
Definition: unum.h:285
Positive prefix.
Definition: unum.h:1153
The ISO currency code.
Definition: unum.h:1163
Multiplication sign.
Definition: unum.h:1340
C API: Display context types (enum values)
The minus sign.
Definition: unum.h:1274
Nan symbol.
Definition: unum.h:1292
Currency format with an ISO currency code, e.g., "USD1.00".
Definition: unum.h:205
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:224
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:147
Use significant digits.
Definition: unum.h:984
Percent format.
Definition: unum.h:166
Half-even rounding.
Definition: unum.h:279
The position at which padding will take place.
Definition: unum.h:979
Decimal format expressed using compact notation (long form, corresponds to UNumberCompactStyle=UNUM_L...
Definition: unum.h:238
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
Spellout rule-based format.
Definition: unum.h:178
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:142
int32_t unum_countAvailable(void)
Determine how many locales have decimal formatting patterns available.
The percent sign.
Definition: unum.h:1268
Infinity symbol.
Definition: unum.h:1290
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:496
void * UNumberFormat
A number formatter.
Definition: unum.h:137
Minimum fraction digits.
Definition: unum.h:965
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:346
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:990
Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"...
Definition: unum.h:211
One more than the highest normal UNumberFormatSymbol value.
Definition: unum.h:1347
Parse integers only.
Definition: unum.h:951
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:1011
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1151
UNumberFormat * unum_clone(const UNumberFormat *fmt, UErrorCode *status)
Open a copy of a UNumberFormat.
Maximum fraction digits.
Definition: unum.h:963
Secondary grouping size.
Definition: unum.h:981
The width to which the output of format() is padded.
Definition: unum.h:977
Alias for UNUM_PATTERN_DECIMAL.
Definition: unum.h:264
"Smart pointer" class, closes a UNumberFormat via unum_close().
One below the first bitfield-boolean item.
Definition: unum.h:1035
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:299
Per mill symbol.
Definition: unum.h:1286
The pattern separator.
Definition: unum.h:1266
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:171
Use grouping separator.
Definition: unum.h:953
Minimum grouping digits, technology preview.
Definition: unum.h:1019
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:1042
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:349
Positive suffix.
Definition: unum.h:1155
Multiplier.
Definition: unum.h:969
Minimum integer digits.
Definition: unum.h:959
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:132
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:310
UDisplayContextType
Display context types, for getting values of a particular setting.
Ordinal rule-based format .
Definition: unum.h:185
Escape padding character.
Definition: unum.h:1288
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:1161
if this attribute is set to 1, specifies that, if the pattern contains a decimal mark the input is re...
Definition: unum.h:1059
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:973
The decimal separator.
Definition: unum.h:1262
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:218
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:975
C API: UFieldPositionIterator for use with format APIs.
Minimum significant digits.
Definition: unum.h:987
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:1280
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:1172
The monetary separator.
Definition: unum.h:1282
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:1029
The currency symbol.
Definition: unum.h:1278
The plus sign.
Definition: unum.h:1276
Duration rule-based format.
Definition: unum.h:190
#define U_DRAFT
This is used to declare a function as a draft public ICU C API.
Definition: umachine.h:113
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:949
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1159
One more than the highest normal UNumberFormatFields value.
Definition: unum.h:374
Grouping size.
Definition: unum.h:971
One more than the highest normal UCurrencySpacing value.
Definition: unum.h:336
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:1181
#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:957
Character representing a digit in the pattern.
Definition: unum.h:1272
C API: Locale.
Always show decimal point.
Definition: unum.h:955
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.