A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/unum_8h.html below:

ICU 77.1: i18n/unicode/unum.h File Reference

C API: Compatibility APIs for number formatting.

Number Format C API

IMPORTANT: New users with are strongly encouraged to see if unumberformatter.h fits their use case. Although not deprecated, this header is provided for backwards compatibility only.

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:

double myNumber = 7.0;

printf(" Example 1: %s\n", austrdup(myString) );

char16_t UChar

The base type for UTF-16 code units and pointers.

U_CAPI 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.

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

Format a double using a UNumberFormat.

@ UNUM_DEFAULT

Default format.

void * UNumberFormat

A number formatter.

#define NULL

Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.

UErrorCode

Standard ICU4C error code type, a substitute for exceptions.

@ U_ZERO_ERROR

No error, no warning.

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;

uint32_t a[] = { 123, 3333, -1234567 };

const uint32_t a_len = sizeof(a) / sizeof(a[0]);

for (i = 0; i < a_len; i++) {

resultlength=0;

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);

}

A struct representing a range of text containing a specific field.

U_CAPI 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.

@ U_BUFFER_OVERFLOW_ERROR

A result would not fit in the supplied buffer.

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


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

int32_t pos=0;

int32_t num;

U_CAPI int32_t u_strlen(const UChar *s)

U_CAPI 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.

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 minimum 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:

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

Definition in file unum.h.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4