ICU 55.1  55.1
unum.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 * Modification History:
6 *
7 * Date Name Description
8 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
9 *******************************************************************************
10 */
11 
12 #ifndef _UNUM
13 #define _UNUM
14 
15 #include "unicode/utypes.h"
16 
17 #if !UCONFIG_NO_FORMATTING
18 
19 #include "unicode/localpointer.h"
20 #include "unicode/uloc.h"
21 #include "unicode/ucurr.h"
22 #include "unicode/umisc.h"
23 #include "unicode/parseerr.h"
24 #include "unicode/uformattable.h"
26 
134 typedef void* UNumberFormat;
135 
139 typedef enum UNumberFormatStyle {
211 #ifndef U_HIDE_DRAFT_API
212 
218 #endif /* U_HIDE_DRAFT_API */
219 
225 
237 
242  UNUM_ROUND_CEILING,
243  UNUM_ROUND_FLOOR,
244  UNUM_ROUND_DOWN,
245  UNUM_ROUND_UP,
251 #ifndef U_HIDE_DEPRECATED_API
252 
257 #endif /* U_HIDE_DEPRECATED_API */
258  UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
259  UNUM_ROUND_HALFUP,
266 
271  UNUM_PAD_BEFORE_PREFIX,
272  UNUM_PAD_AFTER_PREFIX,
273  UNUM_PAD_BEFORE_SUFFIX,
274  UNUM_PAD_AFTER_SUFFIX
276 
281 typedef enum UNumberCompactStyle {
288 
302 };
311 typedef enum UNumberFormatFields {
337 
338 
372 U_STABLE UNumberFormat* U_EXPORT2
374  const UChar* pattern,
375  int32_t patternLength,
376  const char* locale,
377  UParseError* parseErr,
378  UErrorCode* status);
379 
380 
387 U_STABLE void U_EXPORT2
389 
390 #if U_SHOW_CPLUSPLUS_API
391 
393 
404 
406 
407 #endif
408 
417 U_STABLE UNumberFormat* U_EXPORT2
418 unum_clone(const UNumberFormat *fmt,
419  UErrorCode *status);
420 
445 U_STABLE int32_t U_EXPORT2
446 unum_format( const UNumberFormat* fmt,
447  int32_t number,
448  UChar* result,
449  int32_t resultLength,
450  UFieldPosition *pos,
451  UErrorCode* status);
452 
477 U_STABLE int32_t U_EXPORT2
479  int64_t number,
480  UChar* result,
481  int32_t resultLength,
482  UFieldPosition *pos,
483  UErrorCode* status);
484 
509 U_STABLE int32_t U_EXPORT2
510 unum_formatDouble( const UNumberFormat* fmt,
511  double number,
512  UChar* result,
513  int32_t resultLength,
514  UFieldPosition *pos, /* 0 if ignore */
515  UErrorCode* status);
516 
545 U_STABLE int32_t U_EXPORT2
547  const char * number,
548  int32_t length,
549  UChar* result,
550  int32_t resultLength,
551  UFieldPosition *pos, /* 0 if ignore */
552  UErrorCode* status);
553 
578 U_STABLE int32_t U_EXPORT2
580  double number,
581  UChar* currency,
582  UChar* result,
583  int32_t resultLength,
584  UFieldPosition* pos,
585  UErrorCode* status);
586 
607 U_STABLE int32_t U_EXPORT2
609  const UFormattable *number,
610  UChar *result,
611  int32_t resultLength,
612  UFieldPosition *pos,
613  UErrorCode *status);
614 
632 U_STABLE int32_t U_EXPORT2
633 unum_parse( const UNumberFormat* fmt,
634  const UChar* text,
635  int32_t textLength,
636  int32_t *parsePos /* 0 = start */,
637  UErrorCode *status);
638 
656 U_STABLE int64_t U_EXPORT2
657 unum_parseInt64(const UNumberFormat* fmt,
658  const UChar* text,
659  int32_t textLength,
660  int32_t *parsePos /* 0 = start */,
661  UErrorCode *status);
662 
680 U_STABLE double U_EXPORT2
681 unum_parseDouble( const UNumberFormat* fmt,
682  const UChar* text,
683  int32_t textLength,
684  int32_t *parsePos /* 0 = start */,
685  UErrorCode *status);
686 
687 
713 U_STABLE int32_t U_EXPORT2
715  const UChar* text,
716  int32_t textLength,
717  int32_t *parsePos /* 0 = start */,
718  char *outBuf,
719  int32_t outBufLength,
720  UErrorCode *status);
721 
741 U_STABLE double U_EXPORT2
743  const UChar* text,
744  int32_t textLength,
745  int32_t* parsePos, /* 0 = start */
746  UChar* currency,
747  UErrorCode* status);
748 
767 U_STABLE UFormattable* U_EXPORT2
769  UFormattable *result,
770  const UChar* text,
771  int32_t textLength,
772  int32_t* parsePos, /* 0 = start */
773  UErrorCode* status);
774 
791 U_STABLE void U_EXPORT2
793  UBool localized,
794  const UChar *pattern,
795  int32_t patternLength,
796  UParseError *parseError,
797  UErrorCode *status
798  );
799 
810 U_STABLE const char* U_EXPORT2
811 unum_getAvailable(int32_t localeIndex);
812 
822 U_STABLE int32_t U_EXPORT2
823 unum_countAvailable(void);
824 
825 #if UCONFIG_HAVE_PARSEALLINPUT
826 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
830 typedef enum UNumberFormatAttributeValue {
831 #ifndef U_HIDE_INTERNAL_API
832 
833  UNUM_NO = 0,
835  UNUM_YES = 1,
837  UNUM_MAYBE = 2
838 #endif /* U_HIDE_INTERNAL_API */
839 } UNumberFormatAttributeValue;
840 #endif
841 
889 #if UCONFIG_HAVE_PARSEALLINPUT
890 
894  UNUM_PARSE_ALL_INPUT = UNUM_LENIENT_PARSE + 1,
895 #endif
896 
906 
907 #ifndef U_HIDE_INTERNAL_API
908 
911 #endif /* U_HIDE_INTERNAL_API */
912 
913 #ifndef U_HIDE_DRAFT_API
914 
921 #endif /* U_HIDE_DRAFT_API */
922 
923  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
928 
942 
943 #ifndef U_HIDE_DRAFT_API
944 
953 #endif /* U_HIDE_DRAFT_API */
954 
955  /* The following cannot be #ifndef U_HIDE_INTERNAL_API, needed in .h file variable declararions */
960 
978 U_STABLE int32_t U_EXPORT2
981 
1001 U_STABLE void U_EXPORT2
1004  int32_t newValue);
1005 
1006 
1021 U_STABLE double U_EXPORT2
1023  UNumberFormatAttribute attr);
1024 
1039 U_STABLE void U_EXPORT2
1042  double newValue);
1043 
1077 
1096 U_STABLE int32_t U_EXPORT2
1099  UChar* result,
1100  int32_t resultLength,
1101  UErrorCode* status);
1102 
1119 U_STABLE void U_EXPORT2
1122  const UChar* newValue,
1123  int32_t newValueLength,
1124  UErrorCode *status);
1125 
1142 U_STABLE int32_t U_EXPORT2
1143 unum_toPattern( const UNumberFormat* fmt,
1144  UBool isPatternLocalized,
1145  UChar* result,
1146  int32_t resultLength,
1147  UErrorCode* status);
1148 
1149 
1154 typedef enum UNumberFormatSymbol {
1230 
1231 #ifndef U_HIDE_DRAFT_API
1232 
1236 #endif /* U_HIDE_DRAFT_API */
1237 
1241 
1258 U_STABLE int32_t U_EXPORT2
1259 unum_getSymbol(const UNumberFormat *fmt,
1260  UNumberFormatSymbol symbol,
1261  UChar *buffer,
1262  int32_t size,
1263  UErrorCode *status);
1264 
1278 U_STABLE void U_EXPORT2
1280  UNumberFormatSymbol symbol,
1281  const UChar *value,
1282  int32_t length,
1283  UErrorCode *status);
1284 
1285 
1295 U_STABLE const char* U_EXPORT2
1297  ULocDataLocaleType type,
1298  UErrorCode* status);
1299 
1308 U_STABLE void U_EXPORT2
1310 
1320 U_STABLE UDisplayContext U_EXPORT2
1321 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1322 
1323 #endif /* #if !UCONFIG_NO_FORMATTING */
1324 
1325 #endif
Default format.
Definition: unum.h:230
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:241
double unum_getDoubleAttribute(const UNumberFormat *fmt, UNumberFormatAttribute attr)
Get a numeric attribute associated with a UNumberFormat.
The exponential symbol.
Definition: unum.h:1178
The monetary grouping separator.
Definition: unum.h:1193
One more than the highest number format style constant.
Definition: unum.h:224
Negative prefix.
Definition: unum.h:1051
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:188
Count of "regular" numeric attributes.
Definition: unum.h:910
const char * unum_getAvailable(int32_t localeIndex)
Get a locale for which decimal formatting patterns are available.
Currency format with a currency symbol, e.g., "$1.00".
Definition: unum.h:154
Decimal format ("normal" style).
Definition: unum.h:149
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:941
UDisplayContext
Display context settings.
Significant digit symbol.
Definition: unum.h:1189
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:193
Lenient parse mode used by rule-based formats.
Definition: unum.h:888
UCurrencySpacing
Constants for specifying currency spacing.
Definition: unum.h:293
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:264
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:1158
Limit of boolean attributes.
Definition: unum.h:958
Integer digits.
Definition: unum.h:855
Fraction digits.
Definition: unum.h:861
UNumberFormatSymbol
Constants for specifying a number format symbol.
Definition: unum.h:1154
Half-even rounding, misspelled name.
Definition: unum.h:256
Positive prefix.
Definition: unum.h:1047
The ISO currency code.
Definition: unum.h:1057
Multiplication sign.
Definition: unum.h:1235
C API: Display context types (enum values)
The minus sign.
Definition: unum.h:1168
Nan symbol.
Definition: unum.h:1186
Currency format with an ISO currency code, e.g., "USD1.00".
Definition: unum.h:198
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:217
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:144
Use significant digits.
Definition: unum.h:878
Percent format.
Definition: unum.h:159
Half-even rounding.
Definition: unum.h:250
The position at which padding will take place.
Definition: unum.h:873
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
Spellout rule-based format.
Definition: unum.h:171
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:139
int32_t unum_countAvailable(void)
Determine how many locales have decimal formatting patterns available.
The percent sign.
Definition: unum.h:1162
Infinity symbol.
Definition: unum.h:1184
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:356
void * UNumberFormat
A number formatter.
Definition: unum.h:134
Minimum fraction digits.
Definition: unum.h:859
A struct representing a range of text containing a specific field.
Definition: umisc.h:32
UNumberFormatFields
FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberForma...
Definition: unum.h:311
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:884
Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars"...
Definition: unum.h:204
count symbol constants
Definition: unum.h:1239
Parse integers only.
Definition: unum.h:845
Scale, which adjusts the position of the decimal point when formatting.
Definition: unum.h:905
UNumberFormatTextAttribute
The possible UNumberFormat text attributes.
Definition: unum.h:1045
UNumberFormat * unum_clone(const UNumberFormat *fmt, UErrorCode *status)
Open a copy of a UNumberFormat.
Maximum fraction digits.
Definition: unum.h:857
Secondary grouping size.
Definition: unum.h:875
The width to which the output of format() is padded.
Definition: unum.h:871
Alias for UNUM_PATTERN_DECIMAL.
Definition: unum.h:235
"Smart pointer" class, closes a UNumberFormat via unum_close().
One below the first bitfield-boolean item.
Definition: unum.h:927
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:270
Per mill symbol.
Definition: unum.h:1180
The pattern separator.
Definition: unum.h:1160
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:164
Use grouping separator.
Definition: unum.h:847
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:934
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:312
Positive suffix.
Definition: unum.h:1049
Multiplier.
Definition: unum.h:863
Minimum integer digits.
Definition: unum.h:853
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:130
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:281
UDisplayContextType
Display context types, for getting values of a particular setting.
Ordinal rule-based format .
Definition: unum.h:178
Escape padding character.
Definition: unum.h:1182
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:1055
if this attribute is set to 1, specifies that, if the pattern contains a decimal mark the input is re...
Definition: unum.h:952
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:867
The decimal separator.
Definition: unum.h:1156
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:336
Currency format for accounting, e.g., "($3.00)" for negative currency amount instead of "-$3...
Definition: unum.h:210
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:869
Minimum significant digits.
Definition: unum.h:881
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
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:1174
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:1066
The monetary separator.
Definition: unum.h:1176
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:920
The currency symbol.
Definition: unum.h:1172
The plus sign.
Definition: unum.h:1170
Duration rule-based format.
Definition: unum.h:183
void * UFormattable
Opaque type representing various types of data which may be used for formatting and parsing operation...
Definition: uformattable.h:62
UNumberFormatAttribute
The possible UNumberFormat numeric attributes.
Definition: unum.h:843
void unum_close(UNumberFormat *fmt)
Close a UNumberFormat.
Negative suffix.
Definition: unum.h:1053
Grouping size.
Definition: unum.h:865
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:1075
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:109
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
Maximum integer digits.
Definition: unum.h:851
Character representing a digit in the pattern.
Definition: unum.h:1166
C API: Locale.
Always show decimal point.
Definition: unum.h:849
void unum_setTextAttribute(UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
Set a text attribute associated with a UNumberFormat.