#include "unicode/utypes.h"
#include "unicode/uloc.h"
#include "unicode/umisc.h"
#include "unicode/parseerr.h"
Go to the source code of this file.
Defines | |
#define | UNFSYMBOLSMAXSIZE 10 |
The maximum size for a textual number format symbol. | |
Typedefs | |
typedef void * | UNumberFormat |
A number formatter. | |
Enumerations | |
enum | UNumberFormatStyle { UNUM_PATTERN_DECIMAL = 0, UNUM_DECIMAL = 1, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT, UNUM_ORDINAL, UNUM_DURATION, UNUM_PATTERN_RULEBASED, 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_FOUND_HALFEVEN, UNUM_ROUND_HALFDOWN, UNUM_ROUND_HALFUP } |
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 | 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 } |
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, UNUM_GROUPING_SEPARATOR_SYMBOL, UNUM_PATTERN_SEPARATOR_SYMBOL, UNUM_PERCENT_SYMBOL, UNUM_ZERO_DIGIT_SYMBOL, UNUM_DIGIT_SYMBOL, UNUM_MINUS_SIGN_SYMBOL, UNUM_PLUS_SIGN_SYMBOL, UNUM_CURRENCY_SYMBOL, UNUM_INTL_CURRENCY_SYMBOL, UNUM_MONETARY_SEPARATOR_SYMBOL, UNUM_EXPONENTIAL_SYMBOL, UNUM_PERMILL_SYMBOL, UNUM_PAD_ESCAPE_SYMBOL, UNUM_INFINITY_SYMBOL, UNUM_NAN_SYMBOL, UNUM_SIGNIFICANT_DIGIT_SYMBOL, UNUM_FORMAT_SYMBOL_COUNT } |
Constants for specifying a number format symbol. More... | |
Functions | |
U_CAPI UNumberFormat *U_EXPORT2 | 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. | |
U_CAPI void U_EXPORT2 | unum_close (UNumberFormat *fmt) |
Close a UNumberFormat. | |
U_CAPI UNumberFormat *U_EXPORT2 | unum_clone (const UNumberFormat *fmt, UErrorCode *status) |
Open a copy of a UNumberFormat. | |
U_CAPI int32_t U_EXPORT2 | unum_format (const UNumberFormat *fmt, int32_t number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status) |
Format an integer using a UNumberFormat. | |
U_CAPI int32_t U_EXPORT2 | unum_formatInt64 (const UNumberFormat *fmt, int64_t number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status) |
Format an int64 using a UNumberFormat. | |
U_CAPI int32_t U_EXPORT2 | unum_formatDouble (const UNumberFormat *fmt, double number, UChar *result, int32_t resultLength, UFieldPosition *pos, UErrorCode *status) |
Format a double using a UNumberFormat. | |
U_DRAFT int32_t U_EXPORT2 | 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. | |
U_CAPI int32_t U_EXPORT2 | 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. | |
U_STABLE int64_t U_EXPORT2 | 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. | |
U_CAPI double U_EXPORT2 | 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. | |
U_DRAFT double U_EXPORT2 | 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. | |
U_CAPI void U_EXPORT2 | unum_applyPattern (UNumberFormat *format, UBool localized, const UChar *pattern, int32_t patternLength, UParseError *parseError, UErrorCode *status) |
Set the pattern used by a UNumberFormat. | |
U_CAPI const char *U_EXPORT2 | unum_getAvailable (int32_t index) |
Get a locale for which decimal formatting patterns are available. | |
U_CAPI int32_t U_EXPORT2 | unum_countAvailable (void) |
Determine how many locales have decimal formatting patterns available. | |
U_CAPI int32_t U_EXPORT2 | unum_getAttribute (const UNumberFormat *fmt, UNumberFormatAttribute attr) |
Get a numeric attribute associated with a UNumberFormat. | |
U_CAPI void U_EXPORT2 | unum_setAttribute (UNumberFormat *fmt, UNumberFormatAttribute attr, int32_t newValue) |
Set a numeric attribute associated with a UNumberFormat. | |
U_CAPI double U_EXPORT2 | unum_getDoubleAttribute (const UNumberFormat *fmt, UNumberFormatAttribute attr) |
Get a numeric attribute associated with a UNumberFormat. | |
U_CAPI void U_EXPORT2 | unum_setDoubleAttribute (UNumberFormat *fmt, UNumberFormatAttribute attr, double newValue) |
Set a numeric attribute associated with a UNumberFormat. | |
U_CAPI int32_t U_EXPORT2 | unum_getTextAttribute (const UNumberFormat *fmt, UNumberFormatTextAttribute tag, UChar *result, int32_t resultLength, UErrorCode *status) |
Get a text attribute associated with a UNumberFormat. | |
U_CAPI void U_EXPORT2 | unum_setTextAttribute (UNumberFormat *fmt, UNumberFormatTextAttribute tag, const UChar *newValue, int32_t newValueLength, UErrorCode *status) |
Set a text attribute associated with a UNumberFormat. | |
U_CAPI int32_t U_EXPORT2 | unum_toPattern (const UNumberFormat *fmt, UBool isPatternLocalized, UChar *result, int32_t resultLength, UErrorCode *status) |
Extract the pattern from a UNumberFormat. | |
U_CAPI int32_t U_EXPORT2 | unum_getSymbol (const UNumberFormat *fmt, UNumberFormatSymbol symbol, UChar *buffer, int32_t size, UErrorCode *status) |
Get a symbol associated with a UNumberFormat. | |
U_CAPI void U_EXPORT2 | unum_setSymbol (UNumberFormat *fmt, UNumberFormatSymbol symbol, const UChar *value, int32_t length, UErrorCode *status) |
Set a symbol associated with a UNumberFormat. | |
U_CAPI const char *U_EXPORT2 | unum_getLocaleByType (const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode *status) |
Get the locale for this number format object. |
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:
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.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*)
To format a number for a different Locale, specify it in the call to unum_open().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); }
You can use a NumberFormat API unum_parse() to parse.UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)
Use UCAL_DECIMAL to get the normal number format for that country. There are other static options available. Use UCAL_CURRENCY to get the currency number format for that country. Use UCAL_PERCENT to get a format for displaying percentages. With this format, a fraction from 0.53 is displayed as 53%.UErrorCode status = U_ZERO_ERROR; int32_t pos=0; int32_t num; num = unum_parse(nf, str, u_strlen(str), &pos, &status);
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_getAttribues() and unum_setAtributes(), which let you set the miminum fraction digits, grouping, etc.
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.
#define UNFSYMBOLSMAXSIZE 10 |
typedef void* UNumberFormat |
The possible UNumberFormat numeric attributes.
enum UNumberFormatStyle |
The possible number format styles.
enum UNumberFormatSymbol |
Constants for specifying a number format symbol.
The possible UNumberFormat text attributes.
U_CAPI void U_EXPORT2 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_ILLEGAL_ARGUMENT_ERROR in the status.
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. |
U_CAPI UNumberFormat* U_EXPORT2 unum_clone | ( | const UNumberFormat * | fmt, | |
UErrorCode * | status | |||
) |
Open a copy of a UNumberFormat.
This function performs a deep copy.
fmt | The format to copy | |
status | A pointer to an UErrorCode to receive any errors. |
U_CAPI void U_EXPORT2 unum_close | ( | UNumberFormat * | fmt | ) |
Close a UNumberFormat.
Once closed, a UNumberFormat may no longer be used.
fmt | The formatter to close. |
U_CAPI int32_t U_EXPORT2 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.
U_CAPI int32_t U_EXPORT2 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.
fmt | The formatter to use. | |
number | The number to format. | |
result | A pointer to a buffer to receive the formatted number. | |
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 |
U_CAPI int32_t U_EXPORT2 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.
fmt | The formatter to use. | |
number | The number to format. | |
result | A pointer to a buffer to receive the formatted number. | |
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 |
U_DRAFT int32_t U_EXPORT2 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.
fmt | the formatter to use | |
number | the number to format | |
currency | the 3-letter null-terminated ISO 4217 currency code | |
result | a pointer to the buffer to receive the formatted number | |
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 |
U_CAPI int32_t U_EXPORT2 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.
fmt | The formatter to use. | |
number | The number to format. | |
result | A pointer to a buffer to receive the formatted number. | |
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 |
U_CAPI int32_t U_EXPORT2 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.
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. |
U_CAPI const char* U_EXPORT2 unum_getAvailable | ( | int32_t | index | ) |
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.
index | The index of the desired locale. |
U_CAPI double U_EXPORT2 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.
fmt | The formatter to query. | |
attr | The attribute to query; e.g. UNUM_ROUNDING_INCREMENT. |
U_CAPI const char* U_EXPORT2 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.
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 |
U_CAPI int32_t U_EXPORT2 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.
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 |
length>=size
U_CAPI int32_t U_EXPORT2 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 attributre, U_UNSUPPORTED_ERROR is returned as the status. Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
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 |
U_CAPI UNumberFormat* U_EXPORT2 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.
style | The type of number format to open: one of UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT, 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. |
U_CAPI int32_t U_EXPORT2 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.
fmt | The formatter to use. | |
text | The text to parse. | |
textLength | The length of text, or -1 if null-terminated. | |
parsePos | If not 0, on input a pointer to an integer specifying the offset at which to begin parsing. If not 0, on output the offset at which parsing ended. | |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI double U_EXPORT2 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.
fmt | The formatter to use. | |
text | The text to parse. | |
textLength | The length of text, or -1 if null-terminated. | |
parsePos | If not 0, on input a pointer to an integer specifying the offset at which to begin parsing. If not 0, on output the offset at which parsing ended. | |
status | A pointer to an UErrorCode to receive any errors |
U_DRAFT double U_EXPORT2 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.
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 0, 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 |
U_STABLE int64_t U_EXPORT2 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.
fmt | The formatter to use. | |
text | The text to parse. | |
textLength | The length of text, or -1 if null-terminated. | |
parsePos | If not 0, on input a pointer to an integer specifying the offset at which to begin parsing. If not 0, on output the offset at which parsing ended. | |
status | A pointer to an UErrorCode to receive any errors |
U_CAPI void U_EXPORT2 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.
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, or UNUM_LENIENT_PARSE. | |
newValue | The new value of attr. |
U_CAPI void U_EXPORT2 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.
fmt | The formatter to set. | |
attr | The attribute to set; e.g. UNUM_ROUNDING_INCREMENT. | |
newValue | The new value of attr. |
U_CAPI void U_EXPORT2 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.
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. |
U_CAPI void U_EXPORT2 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.
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 |
U_CAPI int32_t U_EXPORT2 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.
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. |