ICU 76.1: i18n/unicode/unumberformatter.h Source File

ICU 76.1 76.1

unumberformatter.h
Go to the documentation of this file.
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #ifndef __UNUMBERFORMATTER_H__
5 #define __UNUMBERFORMATTER_H__
6
7 #include "unicode/utypes.h"
8
9 #if !UCONFIG_NO_FORMATTING
10
11 #include "unicode/parseerr.h"
12 #include "unicode/unumberoptions.h"
13 #include "unicode/uformattednumber.h"
14
15
118 typedef enum UNumberRoundingPriority {
124 UNUM_ROUNDING_PRIORITY_RELAXED,
125
131 UNUM_ROUNDING_PRIORITY_STRICT,
132 } UNumberRoundingPriority;
133
152 typedef enum UNumberUnitWidth {
164 UNUM_UNIT_WIDTH_NARROW = 0,
165
180 UNUM_UNIT_WIDTH_SHORT = 1,
181
191 UNUM_UNIT_WIDTH_FULL_NAME = 2,
192
202 UNUM_UNIT_WIDTH_ISO_CODE = 3,
203
213 UNUM_UNIT_WIDTH_FORMAL = 4,
214
224 UNUM_UNIT_WIDTH_VARIANT = 5,
225
233 UNUM_UNIT_WIDTH_HIDDEN = 6,
234
235 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
236 // needed for unconditionalized struct MacroProps
242 UNUM_UNIT_WIDTH_COUNT = 7
243 } UNumberUnitWidth;
244
264 typedef enum UNumberSignDisplay {
274 UNUM_SIGN_AUTO,
275
282 UNUM_SIGN_ALWAYS,
283
289 UNUM_SIGN_NEVER,
290
305 UNUM_SIGN_ACCOUNTING,
306
315 UNUM_SIGN_ACCOUNTING_ALWAYS,
316
323 UNUM_SIGN_EXCEPT_ZERO,
324
332 UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
333
339 UNUM_SIGN_NEGATIVE,
340
346 UNUM_SIGN_ACCOUNTING_NEGATIVE,
347
348 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
349 // needed for unconditionalized struct MacroProps
355 UNUM_SIGN_COUNT = 9,
356 } UNumberSignDisplay;
357
369 typedef enum UNumberDecimalSeparatorDisplay {
376 UNUM_DECIMAL_SEPARATOR_AUTO,
377
383 UNUM_DECIMAL_SEPARATOR_ALWAYS,
384
385 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
386 // needed for unconditionalized struct MacroProps
392 UNUM_DECIMAL_SEPARATOR_COUNT
393 } UNumberDecimalSeparatorDisplay;
394
403 typedef enum UNumberTrailingZeroDisplay {
409 UNUM_TRAILING_ZERO_AUTO,
410
416 UNUM_TRAILING_ZERO_HIDE_IF_WHOLE,
417 } UNumberTrailingZeroDisplay;
418
419 struct UNumberFormatter;
427 typedef struct UNumberFormatter UNumberFormatter;
428
429
450 U_CAPI UNumberFormatter* U_EXPORT2
451 unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
452 UErrorCode* ec);
453
454
470 U_CAPI UNumberFormatter* U_EXPORT2
471 unumf_openForSkeletonAndLocaleWithError(
472 const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec);
473
474
475
491 U_CAPI void U_EXPORT2
492 unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
493 UErrorCode* ec);
494
495
511 U_CAPI void U_EXPORT2
512 unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
513 UErrorCode* ec);
514
515
535 U_CAPI void U_EXPORT2
536 unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
537 UFormattedNumber* uresult, UErrorCode* ec);
538
539
540
547 U_CAPI void U_EXPORT2
548 unumf_close(UNumberFormatter* uformatter);
549
550
551
552 #if U_SHOW_CPLUSPLUS_API
553 U_NAMESPACE_BEGIN
554
570 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close);
571
572 U_NAMESPACE_END
573 #endif // U_SHOW_CPLUSPLUS_API
574
575 #endif /* #if !UCONFIG_NO_FORMATTING */
576 #endif //__UNUMBERFORMATTER_H__
LocalUNumberFormatterPointer
"Smart pointer" class; closes a UNumberFormatter via unumf_close().
U_DEFINE_LOCAL_OPEN_POINTER
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:550
parseerr.h
C API: Parse Error Information.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
uformattednumber.h
C API: Formatted number result from various number formatting functions.
UFormattedNumber
struct UFormattedNumber UFormattedNumber
C-compatible version of icu::number::FormattedNumber.
Definition: uformattednumber.h:43
U_CAPI
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
UChar
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
UNumberRoundingPriority
UNumberRoundingPriority
An enum declaring how to resolve conflicts between maximum fraction digits and maximum significant di...
Definition: unumberformatter.h:118
UNUM_ROUNDING_PRIORITY_RELAXED
@ UNUM_ROUNDING_PRIORITY_RELAXED
Favor greater precision by relaxing one of the rounding constraints.
Definition: unumberformatter.h:124
UNUM_ROUNDING_PRIORITY_STRICT
@ UNUM_ROUNDING_PRIORITY_STRICT
Favor adherence to all rounding constraints by producing lower precision.
Definition: unumberformatter.h:131
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: unumberformatter.h:264
UNUM_SIGN_ALWAYS
@ UNUM_SIGN_ALWAYS
Show the minus sign on negative numbers and the plus sign on positive numbers, including zero.
Definition: unumberformatter.h:282
UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO
@ UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO
Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive nu...
Definition: unumberformatter.h:332
UNUM_SIGN_ACCOUNTING_NEGATIVE
@ UNUM_SIGN_ACCOUNTING_NEGATIVE
Same as ACCOUNTING, but do not show the sign on negative zero.
Definition: unumberformatter.h:346
UNUM_SIGN_AUTO
@ UNUM_SIGN_AUTO
Show the minus sign on negative numbers, and do not show the sign on positive numbers.
Definition: unumberformatter.h:274
UNUM_SIGN_ACCOUNTING
@ UNUM_SIGN_ACCOUNTING
Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive ...
Definition: unumberformatter.h:305
UNUM_SIGN_NEVER
@ UNUM_SIGN_NEVER
Do not show the sign on positive or negative numbers.
Definition: unumberformatter.h:289
UNUM_SIGN_ACCOUNTING_ALWAYS
@ UNUM_SIGN_ACCOUNTING_ALWAYS
Use the locale-dependent accounting format on negative numbers, and show the plus sign on positive nu...
Definition: unumberformatter.h:315
UNUM_SIGN_EXCEPT_ZERO
@ UNUM_SIGN_EXCEPT_ZERO
Show the minus sign on negative numbers and the plus sign on positive numbers.
Definition: unumberformatter.h:323
UNUM_SIGN_NEGATIVE
@ UNUM_SIGN_NEGATIVE
Same as AUTO, but do not show the sign on negative zero.
Definition: unumberformatter.h:339
UNUM_SIGN_COUNT
@ UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: unumberformatter.h:355
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:369
UNUM_DECIMAL_SEPARATOR_COUNT
@ UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: unumberformatter.h:392
UNUM_DECIMAL_SEPARATOR_AUTO
@ UNUM_DECIMAL_SEPARATOR_AUTO
Show the decimal separator when there are one or more digits to display after the separator,...
Definition: unumberformatter.h:376
UNUM_DECIMAL_SEPARATOR_ALWAYS
@ UNUM_DECIMAL_SEPARATOR_ALWAYS
Always show the decimal separator, even if there are no digits to display after the separator.
Definition: unumberformatter.h:383
UNumberTrailingZeroDisplay
UNumberTrailingZeroDisplay
An enum declaring how to render trailing zeros.
Definition: unumberformatter.h:403
UNUM_TRAILING_ZERO_AUTO
@ UNUM_TRAILING_ZERO_AUTO
Display trailing zeros according to the settings for minimum fraction and significant digits.
Definition: unumberformatter.h:409
UNUM_TRAILING_ZERO_HIDE_IF_WHOLE
@ UNUM_TRAILING_ZERO_HIDE_IF_WHOLE
Same as AUTO, but hide trailing zeros after the decimal separator if they are all zero.
Definition: unumberformatter.h:416
unumf_openForSkeletonAndLocaleWithError
U_CAPI UNumberFormatter * unumf_openForSkeletonAndLocaleWithError(const UChar *skeleton, int32_t skeletonLen, const char *locale, UParseError *perror, UErrorCode *ec)
Like unumf_openForSkeletonAndLocale, but accepts a UParseError, which will be populated with the loca...
unumf_formatDouble
U_CAPI void unumf_formatDouble(const UNumberFormatter *uformatter, double value, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format a double to a UFormattedNumber.
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:152
UNUM_UNIT_WIDTH_HIDDEN
@ UNUM_UNIT_WIDTH_HIDDEN
Format the number according to the specified unit, but do not display the unit.
Definition: unumberformatter.h:233
UNUM_UNIT_WIDTH_FULL_NAME
@ UNUM_UNIT_WIDTH_FULL_NAME
Print the full name of the unit, without any abbreviations.
Definition: unumberformatter.h:191
UNUM_UNIT_WIDTH_FORMAL
@ UNUM_UNIT_WIDTH_FORMAL
Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan dollar in zh-TW.
Definition: unumberformatter.h:213
UNUM_UNIT_WIDTH_NARROW
@ UNUM_UNIT_WIDTH_NARROW
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:164
UNUM_UNIT_WIDTH_VARIANT
@ UNUM_UNIT_WIDTH_VARIANT
Use the alternate variant of the currency symbol; for example, "TL" for the Turkish lira (TRY).
Definition: unumberformatter.h:224
UNUM_UNIT_WIDTH_ISO_CODE
@ UNUM_UNIT_WIDTH_ISO_CODE
Use the three-digit ISO XXX code in place of the symbol for displaying currencies.
Definition: unumberformatter.h:202
UNUM_UNIT_WIDTH_SHORT
@ UNUM_UNIT_WIDTH_SHORT
Print an abbreviated version of the unit name.
Definition: unumberformatter.h:180
UNUM_UNIT_WIDTH_COUNT
@ UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
Definition: unumberformatter.h:242
unumf_formatDecimal
U_CAPI void unumf_formatDecimal(const UNumberFormatter *uformatter, const char *value, int32_t valueLen, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format a decimal number to a UFormattedNumber.
unumf_formatInt
U_CAPI void unumf_formatInt(const UNumberFormatter *uformatter, int64_t value, UFormattedNumber *uresult, UErrorCode *ec)
Uses a UNumberFormatter to format an integer to a UFormattedNumber.
UNumberFormatter
struct UNumberFormatter UNumberFormatter
C-compatible version of icu::number::LocalizedNumberFormatter.
Definition: unumberformatter.h:427
unumf_close
U_CAPI void unumf_close(UNumberFormatter *uformatter)
Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale().
unumf_openForSkeletonAndLocale
U_CAPI UNumberFormatter * unumf_openForSkeletonAndLocale(const UChar *skeleton, int32_t skeletonLen, const char *locale, UErrorCode *ec)
Creates a new UNumberFormatter for the given skeleton string and locale.
unumberoptions.h
C API: Header-only input options for various number formatting APIs.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430