unumberformatter.h
Go to the documentation of this file.
// © 2018 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#ifndef __UNUMBERFORMATTER_H__
#define __UNUMBERFORMATTER_H__
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "unicode/parseerr.h"
#include "unicode/unumberoptions.h"
#include "unicode/uformattednumber.h"
typedef enum UNumberRoundingPriority {
UNUM_ROUNDING_PRIORITY_RELAXED,
UNUM_ROUNDING_PRIORITY_STRICT,
} UNumberRoundingPriority;
typedef enum UNumberUnitWidth {
UNUM_UNIT_WIDTH_NARROW = 0,
UNUM_UNIT_WIDTH_SHORT = 1,
UNUM_UNIT_WIDTH_FULL_NAME = 2,
UNUM_UNIT_WIDTH_ISO_CODE = 3,
UNUM_UNIT_WIDTH_FORMAL = 4,
UNUM_UNIT_WIDTH_VARIANT = 5,
UNUM_UNIT_WIDTH_HIDDEN = 6,
// Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
// needed for unconditionalized struct MacroProps
UNUM_UNIT_WIDTH_COUNT = 7
} UNumberUnitWidth;
typedef enum UNumberSignDisplay {
UNUM_SIGN_AUTO,
UNUM_SIGN_ALWAYS,
UNUM_SIGN_NEVER,
UNUM_SIGN_ACCOUNTING,
UNUM_SIGN_ACCOUNTING_ALWAYS,
UNUM_SIGN_EXCEPT_ZERO,
UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO,
UNUM_SIGN_NEGATIVE,
UNUM_SIGN_ACCOUNTING_NEGATIVE,
// Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
// needed for unconditionalized struct MacroProps
UNUM_SIGN_COUNT = 9,
} UNumberSignDisplay;
typedef enum UNumberDecimalSeparatorDisplay {
UNUM_DECIMAL_SEPARATOR_AUTO,
UNUM_DECIMAL_SEPARATOR_ALWAYS,
// Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
// needed for unconditionalized struct MacroProps
UNUM_DECIMAL_SEPARATOR_COUNT
} UNumberDecimalSeparatorDisplay;
typedef enum UNumberTrailingZeroDisplay {
UNUM_TRAILING_ZERO_AUTO,
UNUM_TRAILING_ZERO_HIDE_IF_WHOLE,
} UNumberTrailingZeroDisplay;
struct UNumberFormatter;
typedef struct UNumberFormatter UNumberFormatter;
U_CAPI UNumberFormatter* U_EXPORT2
unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale,
UErrorCode* ec);
U_CAPI UNumberFormatter* U_EXPORT2
unumf_openForSkeletonAndLocaleWithError(
const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec);
U_CAPI void U_EXPORT2
unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult,
UErrorCode* ec);
U_CAPI void U_EXPORT2
unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult,
UErrorCode* ec);
U_CAPI void U_EXPORT2
unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen,
UFormattedNumber* uresult, UErrorCode* ec);
U_CAPI void U_EXPORT2
unumf_close(UNumberFormatter* uformatter);
#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close);
U_NAMESPACE_END
#endif // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */
#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:386
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:415