ICU 55.1 55.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Typedefs | Enumerations | Functions
unum.h File Reference

C API: NumberFormat. More...

`#include "unicode/utypes.h"`
`#include "unicode/localpointer.h"`
`#include "unicode/uloc.h"`
`#include "unicode/ucurr.h"`
`#include "unicode/umisc.h"`
`#include "unicode/parseerr.h"`
`#include "unicode/uformattable.h"`
`#include "unicode/udisplaycontext.h"`

Go to the source code of this file.

## Namespaces
namespace | icu
| File coll.h.

## Typedefs
typedef void * | UNumberFormat
| A number formatter.
typedef enum UNumberFormatStyle | UNumberFormatStyle
| The possible number format styles.
typedef enum UNumberFormatRoundingMode | UNumberFormatRoundingMode
| The possible number format rounding modes.
typedef enum UNumberFormatPadPosition | UNumberFormatPadPosition
| The possible number format pad positions.
typedef enum UNumberCompactStyle | UNumberCompactStyle
| Constants for specifying short or long format.
typedef enum UCurrencySpacing | UCurrencySpacing
typedef enum UNumberFormatFields | UNumberFormatFields
| FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberFormat.
typedef enum UNumberFormatAttribute | UNumberFormatAttribute
| The possible UNumberFormat numeric attributes.
typedef enum UNumberFormatTextAttribute | UNumberFormatTextAttribute
| The possible UNumberFormat text attributes.
typedef enum UNumberFormatSymbol | UNumberFormatSymbol
| Constants for specifying a number format symbol.

## Enumerations
enum | UNumberFormatStyle { UNUM_PATTERN_DECIMAL = 0, UNUM_DECIMAL = 1, UNUM_CURRENCY = 2, UNUM_PERCENT = 3, UNUM_SCIENTIFIC = 4, UNUM_SPELLOUT = 5, UNUM_ORDINAL = 6, UNUM_DURATION = 7, UNUM_NUMBERING_SYSTEM = 8, UNUM_PATTERN_RULEBASED = 9, UNUM_CURRENCY_ISO = 10, UNUM_CURRENCY_PLURAL = 11, UNUM_CURRENCY_ACCOUNTING = 12, UNUM_CASH_CURRENCY = 13, UNUM_FORMAT_STYLE_COUNT = 14, UNUM_DEFAULT = UNUM_DECIMAL, UNUM_IGNORE = UNUM_PATTERN_DECIMAL }
| The possible number format styles. More...
enum | UNumberFormatRoundingMode { UNUM_ROUND_CEILING, UNUM_ROUND_FLOOR, UNUM_ROUND_DOWN, UNUM_ROUND_UP, UNUM_ROUND_HALFEVEN, UNUM_FOUND_HALFEVEN = UNUM_ROUND_HALFEVEN, UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1, UNUM_ROUND_HALFUP, UNUM_ROUND_UNNECESSARY }
| The possible number format rounding modes. More...
enum | UNumberFormatPadPosition { UNUM_PAD_BEFORE_PREFIX, UNUM_PAD_AFTER_PREFIX, UNUM_PAD_BEFORE_SUFFIX, UNUM_PAD_AFTER_SUFFIX }
| The possible number format pad positions. More...
enum | UNumberCompactStyle { UNUM_SHORT, UNUM_LONG }
| Constants for specifying short or long format. More...
enum | UCurrencySpacing { UNUM_CURRENCY_MATCH, UNUM_CURRENCY_SURROUNDING_MATCH, UNUM_CURRENCY_INSERT, UNUM_CURRENCY_SPACING_COUNT }
| Constants for specifying currency spacing. More...
enum | UNumberFormatFields { UNUM_INTEGER_FIELD, UNUM_FRACTION_FIELD, UNUM_DECIMAL_SEPARATOR_FIELD, UNUM_EXPONENT_SYMBOL_FIELD, UNUM_EXPONENT_SIGN_FIELD, UNUM_EXPONENT_FIELD, UNUM_GROUPING_SEPARATOR_FIELD, UNUM_CURRENCY_FIELD, UNUM_PERCENT_FIELD, UNUM_PERMILL_FIELD, UNUM_SIGN_FIELD, UNUM_FIELD_COUNT }
| FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberFormat. More...
enum | UNumberFormatAttribute { UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_ROUNDING_INCREMENT, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE, UNUM_SIGNIFICANT_DIGITS_USED, UNUM_MIN_SIGNIFICANT_DIGITS, UNUM_MAX_SIGNIFICANT_DIGITS, UNUM_LENIENT_PARSE, UNUM_SCALE = UNUM_LENIENT_PARSE + 2, UNUM_NUMERIC_ATTRIBUTE_COUNT = UNUM_LENIENT_PARSE + 3, UNUM_CURRENCY_USAGE = UNUM_LENIENT_PARSE + 4, UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF, UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000, UNUM_PARSE_NO_EXPONENT, UNUM_PARSE_DECIMAL_MARK_REQUIRED = UNUM_PARSE_NO_EXPONENT+1, UNUM_LIMIT_BOOLEAN_ATTRIBUTE = UNUM_PARSE_NO_EXPONENT+2 }
| The possible UNumberFormat numeric attributes. More...
enum | UNumberFormatTextAttribute { UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, UNUM_DEFAULT_RULESET, UNUM_PUBLIC_RULESETS }
| The possible UNumberFormat text attributes. More...
enum | UNumberFormatSymbol { UNUM_DECIMAL_SEPARATOR_SYMBOL = 0, UNUM_GROUPING_SEPARATOR_SYMBOL = 1, UNUM_PATTERN_SEPARATOR_SYMBOL = 2, UNUM_PERCENT_SYMBOL = 3, UNUM_ZERO_DIGIT_SYMBOL = 4, UNUM_DIGIT_SYMBOL = 5, UNUM_MINUS_SIGN_SYMBOL = 6, UNUM_PLUS_SIGN_SYMBOL = 7, UNUM_CURRENCY_SYMBOL = 8, UNUM_INTL_CURRENCY_SYMBOL = 9, UNUM_MONETARY_SEPARATOR_SYMBOL = 10, UNUM_EXPONENTIAL_SYMBOL = 11, UNUM_PERMILL_SYMBOL = 12, UNUM_PAD_ESCAPE_SYMBOL = 13, UNUM_INFINITY_SYMBOL = 14, UNUM_NAN_SYMBOL = 15, UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, UNUM_ONE_DIGIT_SYMBOL = 18, UNUM_TWO_DIGIT_SYMBOL = 19, UNUM_THREE_DIGIT_SYMBOL = 20, UNUM_FOUR_DIGIT_SYMBOL = 21, UNUM_FIVE_DIGIT_SYMBOL = 22, UNUM_SIX_DIGIT_SYMBOL = 23, UNUM_SEVEN_DIGIT_SYMBOL = 24, UNUM_EIGHT_DIGIT_SYMBOL = 25, UNUM_NINE_DIGIT_SYMBOL = 26, UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27, UNUM_FORMAT_SYMBOL_COUNT = 28 }
| Constants for specifying a number format symbol. More...

## Functions
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.
void | unum_close (UNumberFormat *fmt)
| Close a UNumberFormat.
UNumberFormat * | unum_clone (const UNumberFormat *fmt, UErrorCode *status)
| Open a copy of 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.
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_formatDouble (const UNumberFormat *fmt, double number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status)
| Format a double using 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.
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.
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.
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.
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.
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_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.
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.
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.
void | unum_applyPattern (UNumberFormat *format, UBool localized, const UChar *pattern, int32_t patternLength, UParseError *parseError, UErrorCode *status)
| Set the pattern used by a UNumberFormat.
const char * | unum_getAvailable (int32_t localeIndex)
| Get a locale for which decimal formatting patterns are available.
int32_t | unum_countAvailable (void)
| Determine how many locales have decimal formatting patterns available.
int32_t | unum_getAttribute (const UNumberFormat *fmt, UNumberFormatAttribute attr)
| Get a numeric attribute associated with a UNumberFormat.
void | unum_setAttribute (UNumberFormat *fmt, UNumberFormatAttribute attr, int32_t newValue)
| Set a numeric attribute associated with a UNumberFormat.
double | unum_getDoubleAttribute (const UNumberFormat *fmt, UNumberFormatAttribute attr)
| Get a numeric attribute associated with a UNumberFormat.
void | unum_setDoubleAttribute (UNumberFormat *fmt, UNumberFormatAttribute attr, double newValue)
| Set a numeric attribute associated with a UNumberFormat.
int32_t | unum_getTextAttribute (const UNumberFormat *fmt, UNumberFormatTextAttribute tag, UChar *result, int32_t resultLength, UErrorCode *status)
| Get a text attribute associated with a UNumberFormat.
void | unum_setTextAttribute (UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status)
| Set a text attribute associated with a UNumberFormat.
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_getSymbol (const UNumberFormat *fmt, UNumberFormatSymbol symbol, UChar *buffer, int32_t size, UErrorCode *status)
| Get a symbol associated with a UNumberFormat.
void | unum_setSymbol (UNumberFormat *fmt, UNumberFormatSymbol symbol, const UChar *value, int32_t length, UErrorCode *status)
| Set a symbol associated with a UNumberFormat.
const char * | unum_getLocaleByType (const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode *status)
| Get the locale for this number format object.
void | unum_setContext (UNumberFormat *fmt, UDisplayContext value, UErrorCode *status)
| Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
UDisplayContext | unum_getContext (const UNumberFormat *fmt, UDisplayContextType type, UErrorCode *status)
| Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYPE_CAPITALIZATION.

## Detailed Description

C API: NumberFormat.

## Number Format C API

Number Format C API Provides functions for formatting and parsing a number. Also provides methods for determining which locales have number formats, and what their names are.

UNumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal. There are different number format styles like decimal, currency, percent and spellout.

To format a number for the current Locale, use one of the static factory methods:

    UChar myString[20];
    double myNumber = 7.0;
    UErrorCode status = U_ZERO_ERROR;
    UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
    unum_formatDouble(nf, myNumber, myString, 20, NULL, &status);
    printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)

If you are formatting multiple numbers, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.

    uint32_t i, resultlength, reslenneeded;
    UErrorCode status = U_ZERO_ERROR;
    UFieldPosition pos;
    uint32_t a[] = { 123, 3333, -1234567 };
    const uint32_t a_len = sizeof(a) / sizeof(a[0]);
    UNumberFormat* nf;
    UChar* result = NULL;

    nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
    for (i = 0; i < a_len; i++) {
       resultlength=0;
       reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
       result = NULL;
       if(status==U_BUFFER_OVERFLOW_ERROR){
          status=U_ZERO_ERROR;
          resultlength=reslenneeded+1;
          result=(UChar*)malloc(sizeof(UChar) * resultlength);
          unum_format(nf, a[i], result, resultlength, &pos, &status);
       }
       printf( " Example 2: %s\n", austrdup(result));
       free(result);
    }

To format a number for a different Locale, specify it in the call to unum_open().

    UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)

You can use a NumberFormat API unum_parse() to parse.

    UErrorCode status = U_ZERO_ERROR;
    int32_t pos=0;
    int32_t num;
    num = unum_parse(nf, str, u_strlen(str), &pos, &status);

Use UNUM_DECIMAL to get the normal number format for that country. There are other static options available. Use UNUM_CURRENCY to get the currency number format for that country. Use UNUM_PERCENT to get a format for displaying percentages. With this format, a fraction from 0.53 is displayed as 53%.

Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat formatter. The pattern must conform to the syntax defined for those formatters.

You can also control the display of numbers with such function as unum_getAttributes() and unum_setAttributes(), which let you set the miminum fraction digits, grouping, etc.

See Also
  UNumberFormatAttributes for more details

You can also use forms of the parse and format methods with ParsePosition and UFieldPosition to allow you to:

- (a) progressively parse through pieces of a string.
- (b) align the decimal point and other areas.

It is also possible to change or set the symbols used for a particular locale like the currency symbol, the grouping seperator , monetary seperator etc by making use of functions unum_setSymbols() and unum_getSymbols().

Definition in file unum.h.

## Typedef Documentation

typedef enum UCurrencySpacing UCurrencySpacing

Stable:
  ICU 4.8

Definition at line 303 of file unum.h.

typedef enum UNumberCompactStyle UNumberCompactStyle

Constants for specifying short or long format.

Stable:
  ICU 51

typedef void* UNumberFormat

A number formatter.

For usage in C programs.

Stable:
  ICU 2.0

Definition at line 134 of file unum.h.

typedef enum UNumberFormatAttribute UNumberFormatAttribute

The possible UNumberFormat numeric attributes.

Stable:
  ICU 2.0

typedef enum UNumberFormatFields UNumberFormatFields

FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberFormat.

Stable:
  ICU 49

typedef enum UNumberFormatPadPosition UNumberFormatPadPosition

The possible number format pad positions.

Stable:
  ICU 2.0

typedef enum UNumberFormatRoundingMode UNumberFormatRoundingMode

The possible number format rounding modes.

Stable:
  ICU 2.0

typedef enum UNumberFormatStyle UNumberFormatStyle

The possible number format styles.

Stable:
  ICU 2.0

typedef enum UNumberFormatSymbol UNumberFormatSymbol

Constants for specifying a number format symbol.

Stable:
  ICU 2.0

typedef enum UNumberFormatTextAttribute UNumberFormatTextAttribute

The possible UNumberFormat text attributes.

Stable:
  ICU 2.0

## Enumeration Type Documentation

enum UCurrencySpacing

Constants for specifying currency spacing.

Stable:
  ICU 4.8

Enumerator:

  UNUM_CURRENCY_MATCH | Stable: ICU 4.8
  UNUM_CURRENCY_SURROUNDING_MATCH | Stable: ICU 4.8
  UNUM_CURRENCY_INSERT | Stable: ICU 4.8
  UNUM_CURRENCY_SPACING_COUNT | Stable: ICU 4.8

Definition at line 293 of file unum.h.

enum UNumberCompactStyle

Constants for specifying short or long format.

Stable:
  ICU 51

Enumerator:

  UNUM_SHORT | Stable: ICU 51
  UNUM_LONG | Stable: ICU 51 Stable: ICU 51

Definition at line 281 of file unum.h.

enum UNumberFormatAttribute

The possible UNumberFormat numeric attributes.

Stable:
  ICU 2.0

Enumerator:

  UNUM_PARSE_INT_ONLY | Parse integers only.
  UNUM_GROUPING_USED | Use grouping separator.
  UNUM_DECIMAL_ALWAYS_SHOWN | Always show decimal point.
  UNUM_MAX_INTEGER_DIGITS | Maximum integer digits.
  UNUM_MIN_INTEGER_DIGITS | Minimum integer digits.
  UNUM_INTEGER_DIGITS | Integer digits.
  UNUM_MAX_FRACTION_DIGITS | Maximum fraction digits.
  UNUM_MIN_FRACTION_DIGITS | Minimum fraction digits.
  UNUM_FRACTION_DIGITS | Fraction digits.
  UNUM_MULTIPLIER | Multiplier.
  UNUM_GROUPING_SIZE | Grouping size.
  UNUM_ROUNDING_MODE | Rounding Mode.
  UNUM_ROUNDING_INCREMENT | Rounding increment.
  UNUM_FORMAT_WIDTH | The width to which the output of `format()` is padded.
  UNUM_PADDING_POSITION | The position at which padding will take place.
  UNUM_SECONDARY_GROUPING_SIZE | Secondary grouping size.
  UNUM_SIGNIFICANT_DIGITS_USED | Use significant digits. Stable: ICU 3.0
  UNUM_MIN_SIGNIFICANT_DIGITS | Minimum significant digits. Stable: ICU 3.0
  UNUM_MAX_SIGNIFICANT_DIGITS | Maximum significant digits. Stable: ICU 3.0
  UNUM_LENIENT_PARSE | Lenient parse mode used by rule-based formats. Stable: ICU 3.0
  UNUM_SCALE | Scale, which adjusts the position of the decimal point when formatting. Amounts will be multiplied by 10 ^ (scale) before they are formatted. The default value for the scale is 0 ( no adjustment ). Example: setting the scale to 3, 123 formats as "123,000" Example: setting the scale to -4, 123 formats as "0.0123" Stable: ICU 51
  UNUM_NUMERIC_ATTRIBUTE_COUNT | Count of "regular" numeric attributes. Internal: Do not use. This API is for internal use only.
  UNUM_CURRENCY_USAGE | if this attribute is set to 0, it is set to UNUM_CURRENCY_STANDARD purpose, otherwise it is UNUM_CURRENCY_CASH purpose Default: 0 (UNUM_CURRENCY_STANDARD purpose) Draft: This API may be changed in the future versions and was introduced in ICU 54
  UNUM_MAX_NONBOOLEAN_ATTRIBUTE | One below the first bitfield-boolean item. All items after this one are stored in boolean form. Internal: Do not use. This API is for internal use only.
  UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS | If 1, specifies that if setting the "max integer digits" attribute would truncate a value, set an error status rather than silently truncating. For example, formatting the value 1234 with 4 max int digits would succeed, but formatting 12345 would fail. There is no effect on parsing. Default: 0 (not set) Stable: ICU 50
  UNUM_PARSE_NO_EXPONENT | if this attribute is set to 1, specifies that, if the pattern doesn't contain an exponent, the exponent will not be parsed. If the pattern does contain an exponent, this attribute has no effect. Has no effect on formatting. Default: 0 (unset) Stable: ICU 50
  UNUM_PARSE_DECIMAL_MARK_REQUIRED | if this attribute is set to 1, specifies that, if the pattern contains a decimal mark the input is required to have one. If this attribute is set to 0, specifies that input does not have to contain a decimal mark. Has no effect on formatting. Default: 0 (unset) Draft: This API may be changed in the future versions and was introduced in ICU 54
  UNUM_LIMIT_BOOLEAN_ATTRIBUTE | Limit of boolean attributes. Internal: Do not use. This API is for internal use only.

Definition at line 843 of file unum.h.

enum UNumberFormatFields

FieldPosition and UFieldPosition selectors for format fields defined by NumberFormat and UNumberFormat.

Stable:
  ICU 49

Enumerator:

  UNUM_INTEGER_FIELD | Stable: ICU 49
  UNUM_FRACTION_FIELD | Stable: ICU 49
  UNUM_DECIMAL_SEPARATOR_FIELD | Stable: ICU 49
  UNUM_EXPONENT_SYMBOL_FIELD | Stable: ICU 49
  UNUM_EXPONENT_SIGN_FIELD | Stable: ICU 49
  UNUM_EXPONENT_FIELD | Stable: ICU 49
  UNUM_GROUPING_SEPARATOR_FIELD | Stable: ICU 49
  UNUM_CURRENCY_FIELD | Stable: ICU 49
  UNUM_PERCENT_FIELD | Stable: ICU 49
  UNUM_PERMILL_FIELD | Stable: ICU 49
  UNUM_SIGN_FIELD | Stable: ICU 49
  UNUM_FIELD_COUNT | Stable: ICU 49

Definition at line 311 of file unum.h.

enum UNumberFormatPadPosition

The possible number format pad positions.

Stable:
  ICU 2.0

Definition at line 270 of file unum.h.

enum UNumberFormatRoundingMode

The possible number format rounding modes.

Stable:
  ICU 2.0

Enumerator:

  UNUM_ROUND_HALFEVEN | Half-even rounding. Stable: , ICU 3.8
  UNUM_FOUND_HALFEVEN | Half-even rounding, misspelled name. Deprecated: , ICU 3.8
  UNUM_ROUND_UNNECESSARY | ROUND_UNNECESSARY reports an error if formatted result is not exact. Stable: ICU 4.8

Definition at line 241 of file unum.h.

enum UNumberFormatStyle

The possible number format styles.

Stable:
  ICU 2.0

Enumerator:

  UNUM_PATTERN_DECIMAL | Decimal format defined by a pattern string. Stable: ICU 3.0
  UNUM_DECIMAL | Decimal format ("normal" style). Stable: ICU 2.0
  UNUM_CURRENCY | Currency format with a currency symbol, e.g., "$1.00". Stable: ICU 2.0
  UNUM_PERCENT | Percent format. Stable: ICU 2.0
  UNUM_SCIENTIFIC | Scientific format. Stable: ICU 2.1
  UNUM_SPELLOUT | Spellout rule-based format. The default ruleset can be specified/changed using unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS. Stable: ICU 2.0
  UNUM_ORDINAL | Ordinal rule-based format . The default ruleset can be specified/changed using unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS. Stable: ICU 3.0
  UNUM_DURATION | Duration rule-based format. Stable: ICU 3.0
  UNUM_NUMBERING_SYSTEM | Numbering system rule-based format. Stable: ICU 4.2
  UNUM_PATTERN_RULEBASED | Rule-based format defined by a pattern string. Stable: ICU 3.0
  UNUM_CURRENCY_ISO | Currency format with an ISO currency code, e.g., "USD1.00". Stable: ICU 4.8
  UNUM_CURRENCY_PLURAL | Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars". Stable: ICU 4.8
  UNUM_CURRENCY_ACCOUNTING | Currency format for accounting, e.g., "($3.00)" for negative currency amount instead of "-$3.00" (UNUM_CURRENCY). Stable: ICU 53
  UNUM_CASH_CURRENCY | Currency format with a currency symbol given CASH usage, e.g., "NT$3" instead of "NT$3.23". Draft: This API may be changed in the future versions and was introduced in ICU 54
  UNUM_FORMAT_STYLE_COUNT | One more than the highest number format style constant. Stable: ICU 4.8
  UNUM_DEFAULT | Default format. Stable: ICU 2.0
  UNUM_IGNORE | Alias for UNUM_PATTERN_DECIMAL. Stable: ICU 3.0

Definition at line 139 of file unum.h.

enum UNumberFormatSymbol

Constants for specifying a number format symbol.

Stable:
  ICU 2.0

Enumerator:

  UNUM_DECIMAL_SEPARATOR_SYMBOL | The decimal separator.
  UNUM_GROUPING_SEPARATOR_SYMBOL | The grouping separator.
  UNUM_PATTERN_SEPARATOR_SYMBOL | The pattern separator.
  UNUM_PERCENT_SYMBOL | The percent sign.
  UNUM_ZERO_DIGIT_SYMBOL | Zero.
  UNUM_DIGIT_SYMBOL | Character representing a digit in the pattern.
  UNUM_MINUS_SIGN_SYMBOL | The minus sign.
  UNUM_PLUS_SIGN_SYMBOL | The plus sign.
  UNUM_CURRENCY_SYMBOL | The currency symbol.
  UNUM_INTL_CURRENCY_SYMBOL | The international currency symbol.
  UNUM_MONETARY_SEPARATOR_SYMBOL | The monetary separator.
  UNUM_EXPONENTIAL_SYMBOL | The exponential symbol.
  UNUM_PERMILL_SYMBOL | Per mill symbol.
  UNUM_PAD_ESCAPE_SYMBOL | Escape padding character.
  UNUM_INFINITY_SYMBOL | Infinity symbol.
  UNUM_NAN_SYMBOL | Nan symbol.
  UNUM_SIGNIFICANT_DIGIT_SYMBOL | Significant digit symbol. Stable: ICU 3.0
  UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL | The monetary grouping separator. Stable: ICU 3.6
  UNUM_ONE_DIGIT_SYMBOL | One. Stable: ICU 4.6
  UNUM_TWO_DIGIT_SYMBOL | Two. Stable: ICU 4.6
  UNUM_THREE_DIGIT_SYMBOL | Three. Stable: ICU 4.6
  UNUM_FOUR_DIGIT_SYMBOL | Four. Stable: ICU 4.6
  UNUM_FIVE_DIGIT_SYMBOL | Five. Stable: ICU 4.6
  UNUM_SIX_DIGIT_SYMBOL | Six. Stable: ICU 4.6
  UNUM_SEVEN_DIGIT_SYMBOL | Seven. Stable: ICU 4.6
  UNUM_EIGHT_DIGIT_SYMBOL | Eight. Stable: ICU 4.6
  UNUM_NINE_DIGIT_SYMBOL | Nine. Stable: ICU 4.6
  UNUM_EXPONENT_MULTIPLICATION_SYMBOL | Multiplication sign. Draft: This API may be changed in the future versions and was introduced in ICU 54
  UNUM_FORMAT_SYMBOL_COUNT | count symbol constants

Definition at line 1154 of file unum.h.

enum UNumberFormatTextAttribute

The possible UNumberFormat text attributes.

Stable:
  ICU 2.0

Enumerator:

  UNUM_POSITIVE_PREFIX | Positive prefix.
  UNUM_POSITIVE_SUFFIX | Positive suffix.
  UNUM_NEGATIVE_PREFIX | Negative prefix.
  UNUM_NEGATIVE_SUFFIX | Negative suffix.
  UNUM_PADDING_CHARACTER | The character used to pad to the format width.
  UNUM_CURRENCY_CODE | The ISO currency code.
  UNUM_DEFAULT_RULESET | The default rule set, such as "%spellout-numbering-year:", "%spellout-cardinal:", "%spellout-ordinal-masculine-plural:", "%spellout-ordinal-feminine:", or "%spellout-ordinal-neuter:". The available public rulesets can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS. This is only available with rule-based formatters. Stable: ICU 3.0
  UNUM_PUBLIC_RULESETS | The public rule sets. This is only available with rule-based formatters. This is a read-only attribute. The public rulesets are returned as a single string, with each ruleset name delimited by ';' (semicolon). See the CLDR LDML spec for more information about RBNF rulesets: http://www.unicode.org/reports/tr35/tr35-numbers.html#Rule-Based_Number_Formatting Stable: ICU 3.0

Definition at line 1045 of file unum.h.

## Function Documentation

void unum_applyPattern | ( | UNumberFormat * | format,
|  | UBool | localized,
|  | const UChar * | pattern,
|  | int32_t | patternLength,
|  | UParseError * | parseError,
|  | UErrorCode * | status
| ) |  |

Set the pattern used by a UNumberFormat.

This can only be used on a DecimalFormat, other formats return U_UNSUPPORTED_ERROR in the status.

Parameters

  format | The formatter to set.
  localized | TRUE if the pattern is localized, FALSE otherwise.
  pattern | The new pattern
  patternLength | The length of pattern, or -1 if null-terminated.
  parseError | A pointer to UParseError to recieve information about errors occurred during parsing, or NULL if no parse error information is desired.
  status | A pointer to an input-output UErrorCode.

See Also
  unum_toPattern
  DecimalFormat

Stable:
  ICU 2.0

UNumberFormat* unum_clone | ( | const UNumberFormat * | fmt,
|  | UErrorCode * | status
| ) |  |

Open a copy of a UNumberFormat.

This function performs a deep copy.

Parameters

  fmt | The format to copy
  status | A pointer to an UErrorCode to receive any errors.

Returns
  A pointer to a UNumberFormat identical to fmt.

Stable:
  ICU 2.0

void unum_close | ( | UNumberFormat * | fmt | ) |

Close a UNumberFormat.

Once closed, a UNumberFormat may no longer be used.

Parameters

  fmt | The formatter to close.

Stable:
  ICU 2.0

int32_t unum_countAvailable | ( | void |  | ) |

Determine how many locales have decimal formatting patterns available.

The results of this call are not valid for rule-based number formats. This function is useful for determining the loop ending condition for calls to unum_getAvailable.

Returns
  The number of locales for which decimal formatting patterns are available.

See Also
  unum_getAvailable

Stable:
  ICU 2.0

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 integer will be formatted according to the UNumberFormat's locale.

Parameters

  fmt | The formatter to use.
  number | The number to format.
  result | A pointer to a buffer to receive the NULL-terminated formatted number. If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  resultLength | The maximum size of result.
  pos | A pointer to a UFieldPosition. On input, position->field is read. On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists. This parameter may be NULL, in which case no field
  status | A pointer to an UErrorCode to receive any errors

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_formatInt64
  unum_formatDouble
  unum_parse
  unum_parseInt64
  unum_parseDouble
  UFieldPosition

Stable:
  ICU 2.0

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.

The number will be formatted according to the UNumberFormat's locale. The syntax of the input number is a "numeric string" as defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal

Parameters

  fmt | The formatter to use.
  number | The number to format.
  length | The length of the input number, or -1 if the input is nul-terminated.
  result | A pointer to a buffer to receive the NULL-terminated formatted number. If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  resultLength | The maximum size of result.
  pos | A pointer to a UFieldPosition. On input, position->field is read. On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists. This parameter may be NULL, in which case it is ignored.
  status | A pointer to an UErrorCode to receive any errors

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_format
  unum_formatInt64
  unum_parse
  unum_parseInt64
  unum_parseDouble
  UFieldPosition

Stable:
  ICU 4.4

int32_t unum_formatDouble | ( | const UNumberFormat * | fmt,
|  | double | number,
|  | UChar * | result,
|  | int32_t | resultLength,
|  | UFieldPosition * | pos,
|  | UErrorCode * | status
| ) |  |

Format a double using a UNumberFormat.

The double will be formatted according to the UNumberFormat's locale.

Parameters

  fmt | The formatter to use.
  number | The number to format.
  result | A pointer to a buffer to receive the NULL-terminated formatted number. If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  resultLength | The maximum size of result.
  pos | A pointer to a UFieldPosition. On input, position->field is read. On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists. This parameter may be NULL, in which case no field
  status | A pointer to an UErrorCode to receive any errors

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_format
  unum_formatInt64
  unum_parse
  unum_parseInt64
  unum_parseDouble
  UFieldPosition

Stable:
  ICU 2.0

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.

The double will be formatted according to the UNumberFormat's locale.

Parameters

  fmt | the formatter to use
  number | the number to format
  currency | the 3-letter null-terminated ISO 4217 currency code
  result | A pointer to a buffer to receive the NULL-terminated formatted number. If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  resultLength | the maximum number of UChars to write to result
  pos | a pointer to a UFieldPosition. On input, position->field is read. On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists. This parameter may be NULL, in which case it is ignored.
  status | a pointer to an input-output UErrorCode

Returns
  the total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_formatDouble
  unum_parseDoubleCurrency
  UFieldPosition

Stable:
  ICU 3.0

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.

The int64 will be formatted according to the UNumberFormat's locale.

Parameters

  fmt | The formatter to use.
  number | The number to format.
  result | A pointer to a buffer to receive the NULL-terminated formatted number. If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  resultLength | The maximum size of result.
  pos | A pointer to a UFieldPosition. On input, position->field is read. On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists. This parameter may be NULL, in which case no field
  status | A pointer to an UErrorCode to receive any errors

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_format
  unum_formatDouble
  unum_parse
  unum_parseInt64
  unum_parseDouble
  UFieldPosition

Stable:
  ICU 2.0

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.

Parameters

  fmt | the formatter to use
  number | the number to format, as a UFormattable
  result | A pointer to a buffer to receive the NULL-terminated formatted number. If the formatted number fits into dest but cannot be NULL-terminated (length == resultLength) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  resultLength | the maximum number of UChars to write to result
  pos | a pointer to a UFieldPosition. On input, position->field is read. On output, position->beginIndex and position->endIndex indicate the beginning and ending indices of field number position->field, if such a field exists. This parameter may be NULL, in which case it is ignored.
  status | a pointer to an input-output UErrorCode

Returns
  the total buffer size needed; if greater than resultLength, the output was truncated. Will return 0 on error.

See Also
  unum_parseToUFormattable

Stable:
  ICU 52

int32_t unum_getAttribute | ( | const UNumberFormat * | fmt,
|  | UNumberFormatAttribute | attr
| ) |  |

Get a numeric attribute associated with a UNumberFormat.

An example of a numeric attribute is the number of integer digits a formatter will produce.

Parameters

  fmt | The formatter to query.
  attr | The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE, UNUM_SCALE.

Returns
  The value of attr.

See Also
  unum_setAttribute
  unum_getDoubleAttribute
  unum_setDoubleAttribute
  unum_getTextAttribute
  unum_setTextAttribute

Stable:
  ICU 2.0

const char* unum_getAvailable | ( | int32_t | localeIndex | ) |

Get a locale for which decimal formatting patterns are available.

A UNumberFormat in a locale returned by this function will perform the correct formatting and parsing for the locale. The results of this call are not valid for rule-based number formats.

Parameters

  localeIndex | The index of the desired locale.

Returns
  A locale for which number formatting patterns are available, or 0 if none.

See Also
  unum_countAvailable

Stable:
  ICU 2.0

UDisplayContext unum_getContext | ( | const UNumberFormat * | fmt,
|  | UDisplayContextType | type,
|  | UErrorCode * | status
| ) |  |

Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYPE_CAPITALIZATION.

Parameters

  fmt | The formatter to query.
  type | The UDisplayContextType whose value to return
  status | A pointer to an UErrorCode to receive any errors

Returns
  The UDisplayContextValue for the specified type.

Stable:
  ICU 53

double unum_getDoubleAttribute | ( | const UNumberFormat * | fmt,
|  | UNumberFormatAttribute | attr
| ) |  |

Get a numeric attribute associated with a UNumberFormat.

An example of a numeric attribute is the number of integer digits a formatter will produce. If the formatter does not understand the attribute, -1 is returned.

Parameters

  fmt | The formatter to query.
  attr | The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.

Returns
  The value of attr.

See Also
  unum_getAttribute
  unum_setAttribute
  unum_setDoubleAttribute
  unum_getTextAttribute
  unum_setTextAttribute

Stable:
  ICU 2.0

const char* unum_getLocaleByType | ( | const UNumberFormat * | fmt,
|  | ULocDataLocaleType | type,
|  | UErrorCode * | status
| ) |  |

Get the locale for this number format object.

You can choose between valid and actual locale.

Parameters

  fmt | The formatter to get the locale from
  type | type of the locale we're looking for (valid or actual)
  status | error code for the operation

Returns
  the locale name

Stable:
  ICU 2.8

int32_t unum_getSymbol | ( | const UNumberFormat * | fmt,
|  | UNumberFormatSymbol | symbol,
|  | UChar * | buffer,
|  | int32_t | size,
|  | UErrorCode * | status
| ) |  |

Get a symbol associated with a UNumberFormat.

A UNumberFormat uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.

Parameters

  fmt | The formatter to query.
  symbol | The UNumberFormatSymbol constant for the symbol to get
  buffer | The string buffer that will receive the symbol string; if it is NULL, then only the length of the symbol is returned
  size | The size of the string buffer
  status | A pointer to an UErrorCode to receive any errors

Returns
  The length of the symbol; the buffer is not modified if `length>=size`

See Also
  unum_setSymbol

Stable:
  ICU 2.0

int32_t unum_getTextAttribute | ( | const UNumberFormat * | fmt,
|  | UNumberFormatTextAttribute | tag,
|  | UChar * | result,
|  | int32_t | resultLength,
|  | UErrorCode * | status
| ) |  |

Get a text attribute associated with a UNumberFormat.

An example of a text attribute is the suffix for positive numbers. If the formatter does not understand the attribute, U_UNSUPPORTED_ERROR is returned as the status. Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.

Parameters

  fmt | The formatter to query.
  tag | The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
  result | A pointer to a buffer to receive the attribute.
  resultLength | The maximum size of result.
  status | A pointer to an UErrorCode to receive any errors

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_setTextAttribute
  unum_getAttribute
  unum_setAttribute

Stable:
  ICU 2.0

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.

A UNumberFormat may be used to format numbers by calling unum_format, and to parse numbers by calling unum_parse. The caller must call unum_close when done to release resources used by this object.

Parameters

  style | The type of number format to open: one of UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_CURRENCY_ISO, UNUM_CURRENCY_PLURAL, UNUM_SPELLOUT, UNUM_ORDINAL, UNUM_DURATION, UNUM_NUMBERING_SYSTEM, UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT. If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the number format is opened using the given pattern, which must conform to the syntax described in DecimalFormat or RuleBasedNumberFormat, respectively.
  pattern | A pattern specifying the format to use. This parameter is ignored unless the style is UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
  patternLength | The number of characters in the pattern, or -1 if null-terminated. This parameter is ignored unless the style is UNUM_PATTERN.
  locale | A locale identifier to use to determine formatting and parsing conventions, or NULL to use the default locale.
  parseErr | A pointer to a UParseError struct to receive the details of any parsing errors, or NULL if no parsing error details are desired.
  status | A pointer to an input-output UErrorCode.

Returns
  A pointer to a newly created UNumberFormat, or NULL if an error occurred.

See Also
  unum_close
  DecimalFormat

Stable:
  ICU 2.0

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 string will be parsed according to the UNumberFormat's locale.

Parameters

  fmt | The formatter to use.
  text | The text to parse.
  textLength | The length of text, or -1 if null-terminated.
  parsePos | If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing. If not NULL, on output the offset at which parsing ended.
  status | A pointer to an UErrorCode to receive any errors

Returns
  The value of the parsed integer

See Also
  unum_parseInt64
  unum_parseDouble
  unum_format
  unum_formatInt64
  unum_formatDouble

Stable:
  ICU 2.0

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.

The input string will be parsed according to the UNumberFormat's locale. The syntax of the output is a "numeric string" as defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal

Parameters

  fmt | The formatter to use.
  text | The text to parse.
  textLength | The length of text, or -1 if null-terminated.
  parsePos | If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing. If not NULL, on output the offset at which parsing ended.
  outBuf | A (char *) buffer to receive the parsed number as a string. The output string will be nul-terminated if there is sufficient space.
  outBufLength | The size of the output buffer. May be zero, in which case the outBuf pointer may be NULL, and the function will return the size of the output string.
  status | A pointer to an UErrorCode to receive any errors

Returns
  the length of the output string, not including any terminating nul.

See Also
  unum_parse
  unum_parseInt64
  unum_format
  unum_formatInt64
  unum_formatDouble

Stable:
  ICU 4.4

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.

The string will be parsed according to the UNumberFormat's locale.

Parameters

  fmt | The formatter to use.
  text | The text to parse.
  textLength | The length of text, or -1 if null-terminated.
  parsePos | If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing. If not NULL, on output the offset at which parsing ended.
  status | A pointer to an UErrorCode to receive any errors

Returns
  The value of the parsed double

See Also
  unum_parse
  unum_parseInt64
  unum_format
  unum_formatInt64
  unum_formatDouble

Stable:
  ICU 2.0

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.

The string will be parsed according to the UNumberFormat's locale.

Parameters

  fmt | the formatter to use
  text | the text to parse
  textLength | the length of text, or -1 if null-terminated
  parsePos | a pointer to an offset index into text at which to begin parsing. On output, *parsePos will point after the last parsed character. This parameter may be NULL, in which case parsing begins at offset 0.
  currency | a pointer to the buffer to receive the parsed null- terminated currency. This buffer must have a capacity of at least 4 UChars.
  status | a pointer to an input-output UErrorCode

Returns
  the parsed double

See Also
  unum_parseDouble
  unum_formatDoubleCurrency

Stable:
  ICU 3.0

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.

The string will be parsed according to the UNumberFormat's locale.

Parameters

  fmt | The formatter to use.
  text | The text to parse.
  textLength | The length of text, or -1 if null-terminated.
  parsePos | If not NULL, on input a pointer to an integer specifying the offset at which to begin parsing. If not NULL, on output the offset at which parsing ended.
  status | A pointer to an UErrorCode to receive any errors

Returns
  The value of the parsed integer

See Also
  unum_parse
  unum_parseDouble
  unum_format
  unum_formatInt64
  unum_formatDouble

Stable:
  ICU 2.8

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.

Example code:

const UChar str[] = { 0x0031, 0x0032, 0x0033, 0x0000 }; /* 123 */
int32_t result = 0;
UFormattable *ufmt = ufmt_open(&status);
unum_parseToUFormattable(unum, ufmt, str, -1, NULL, &status);
if (ufmt_isNumeric(ufmt)) {
result = ufmt_getLong(ufmt, &status); /* == 123 */
} /* else { ... } */
ufmt_close(ufmt);

Parameters

  fmt | the formatter to use
  result | the UFormattable to hold the result. If NULL, a new UFormattable will be allocated (which the caller must close with ufmt_close).
  text | the text to parse
  textLength | the length of text, or -1 if null-terminated
  parsePos | a pointer to an offset index into text at which to begin parsing. On output, *parsePos will point after the last parsed character. This parameter may be NULL in which case parsing begins at offset 0.
  status | a pointer to an input-output UErrorCode

Returns
  the UFormattable. Will be ==result unless NULL was passed in for result, in which case it will be the newly opened UFormattable.

See Also
  ufmt_getType
  ufmt_close

Stable:
  ICU 52

void unum_setAttribute | ( | UNumberFormat * | fmt,
|  | UNumberFormatAttribute | attr,
|  | int32_t | newValue
| ) |  |

Set a numeric attribute associated with a UNumberFormat.

An example of a numeric attribute is the number of integer digits a formatter will produce. If the formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand the lenient-parse attribute.

Parameters

  fmt | The formatter to set.
  attr | The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED, UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS, UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER, UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE, UNUM_LENIENT_PARSE, or UNUM_SCALE.
  newValue | The new value of attr.

See Also
  unum_getAttribute
  unum_getDoubleAttribute
  unum_setDoubleAttribute
  unum_getTextAttribute
  unum_setTextAttribute

Stable:
  ICU 2.0

void unum_setContext | ( | UNumberFormat * | fmt,
|  | UDisplayContext | value,
|  | UErrorCode * | status
| ) |  |

Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALONE.

Parameters

  fmt | The formatter for which to set a UDisplayContext value.
  value | The UDisplayContext value to set.
  status | A pointer to an UErrorCode to receive any errors

Stable:
  ICU 53

void unum_setDoubleAttribute | ( | UNumberFormat * | fmt,
|  | UNumberFormatAttribute | attr,
|  | double | newValue
| ) |  |

Set a numeric attribute associated with a UNumberFormat.

An example of a numeric attribute is the number of integer digits a formatter will produce. If the formatter does not understand the attribute, this call is ignored.

Parameters

  fmt | The formatter to set.
  attr | The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
  newValue | The new value of attr.

See Also
  unum_getAttribute
  unum_setAttribute
  unum_getDoubleAttribute
  unum_getTextAttribute
  unum_setTextAttribute

Stable:
  ICU 2.0

void unum_setSymbol | ( | UNumberFormat * | fmt,
|  | UNumberFormatSymbol | symbol,
|  | const UChar * | value,
|  | int32_t | length,
|  | UErrorCode * | status
| ) |  |

Set a symbol associated with a UNumberFormat.

A UNumberFormat uses symbols to represent the special locale-dependent characters in a number, for example the percent sign. This API is not supported for rule-based formatters.

Parameters

  fmt | The formatter to set.
  symbol | The UNumberFormatSymbol constant for the symbol to set
  value | The string to set the symbol to
  length | The length of the string, or -1 for a zero-terminated string
  status | A pointer to an UErrorCode to receive any errors.

See Also
  unum_getSymbol

Stable:
  ICU 2.0

void unum_setTextAttribute | ( | UNumberFormat * | fmt,
|  | UNumberFormatTextAttribute | tag,
|  | const UChar * | newValue,
|  | int32_t | newValueLength,
|  | UErrorCode * | status
| ) |  |

Set a text attribute associated with a UNumberFormat.

An example of a text attribute is the suffix for positive numbers. Rule-based formatters only understand UNUM_DEFAULT_RULESET.

Parameters

  fmt | The formatter to set.
  tag | The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX, UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE, or UNUM_DEFAULT_RULESET.
  newValue | The new value of attr.
  newValueLength | The length of newValue, or -1 if null-terminated.
  status | A pointer to an UErrorCode to receive any errors

See Also
  unum_getTextAttribute
  unum_getAttribute
  unum_setAttribute

Stable:
  ICU 2.0

int32_t unum_toPattern | ( | const UNumberFormat * | fmt,
|  | UBool | isPatternLocalized,
|  | UChar * | result,
|  | int32_t | resultLength,
|  | UErrorCode * | status
| ) |  |

Extract the pattern from a UNumberFormat.

The pattern will follow the DecimalFormat pattern syntax.

Parameters

  fmt | The formatter to query.
  isPatternLocalized | TRUE if the pattern should be localized, FALSE otherwise. This is ignored if the formatter is a rule-based formatter.
  result | A pointer to a buffer to receive the pattern.
  resultLength | The maximum size of result.
  status | A pointer to an input-output UErrorCode.

Returns
  The total buffer size needed; if greater than resultLength, the output was truncated.

See Also
  unum_applyPattern
  DecimalFormat

Stable:
  ICU 2.0