2 *******************************************************************************
3 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
5 * Modification History:
7 * Date Name Description
8 * 06/24/99 helena Integrated Alan's NF enhancements and Java2 bug fixes
9 *******************************************************************************
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/localpointer.h"
20 #include "unicode/uloc.h"
21 #include "unicode/umisc.h"
22 #include "unicode/parseerr.h"
25 * \brief C API: NumberFormat
27 * <h2> Number Format C API </h2>
29 * Number Format C API Provides functions for
30 * formatting and parsing a number. Also provides methods for
31 * determining which locales have number formats, and what their names
34 * UNumberFormat helps you to format and parse numbers for any locale.
35 * Your code can be completely independent of the locale conventions
36 * for decimal points, thousands-separators, or even the particular
37 * decimal digits used, or whether the number format is even decimal.
38 * There are different number format styles like decimal, currency,
39 * percent and spellout.
41 * To format a number for the current Locale, use one of the static
46 * double myNumber = 7.0;
47 * UErrorCode status = U_ZERO_ERROR;
48 * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
49 * unum_formatDouble(nf, myNumber, myString, 20, NULL, &status);
50 * printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)
53 * If you are formatting multiple numbers, it is more efficient to get
54 * the format and use it multiple times so that the system doesn't
55 * have to fetch the information about the local language and country
56 * conventions multiple times.
59 * uint32_t i, resultlength, reslenneeded;
60 * UErrorCode status = U_ZERO_ERROR;
62 * uint32_t a[] = { 123, 3333, -1234567 };
63 * const uint32_t a_len = sizeof(a) / sizeof(a[0]);
65 * UChar* result = NULL;
67 * nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
68 * for (i = 0; i < a_len; i++) {
70 * reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
72 * if(status==U_BUFFER_OVERFLOW_ERROR){
73 * status=U_ZERO_ERROR;
74 * resultlength=reslenneeded+1;
75 * result=(UChar*)malloc(sizeof(UChar) * resultlength);
76 * unum_format(nf, a[i], result, resultlength, &pos, &status);
78 * printf( " Example 2: %s\n", austrdup(result));
83 * To format a number for a different Locale, specify it in the
84 * call to unum_open().
87 * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)
90 * You can use a NumberFormat API unum_parse() to parse.
93 * UErrorCode status = U_ZERO_ERROR;
96 * num = unum_parse(nf, str, u_strlen(str), &pos, &status);
99 * Use UNUM_DECIMAL to get the normal number format for that country.
100 * There are other static options available. Use UNUM_CURRENCY
101 * to get the currency number format for that country. Use UNUM_PERCENT
102 * to get a format for displaying percentages. With this format, a
103 * fraction from 0.53 is displayed as 53%.
105 * Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat
106 * formatter. The pattern must conform to the syntax defined for those
109 * You can also control the display of numbers with such function as
110 * unum_getAttributes() and unum_setAttributes(), which let you set the
111 * miminum fraction digits, grouping, etc.
112 * @see UNumberFormatAttributes for more details
114 * You can also use forms of the parse and format methods with
115 * ParsePosition and UFieldPosition to allow you to:
117 * <li>(a) progressively parse through pieces of a string.
118 * <li>(b) align the decimal point and other areas.
121 * It is also possible to change or set the symbols used for a particular
122 * locale like the currency symbol, the grouping seperator , monetary seperator
123 * etc by making use of functions unum_setSymbols() and unum_getSymbols().
126 /** A number formatter.
127 * For usage in C programs.
130 typedef void* UNumberFormat
;
132 /** The possible number format styles.
135 typedef enum UNumberFormatStyle
{
137 * Decimal format defined by a pattern string.
140 UNUM_PATTERN_DECIMAL
=0,
142 * Decimal format ("normal" style).
147 * Currency format with a currency symbol, e.g., "$1.00".
162 * Spellout rule-based format
167 * Ordinal rule-based format
172 * Duration rule-based format
177 * Numbering system rule-based format
180 UNUM_NUMBERING_SYSTEM
,
182 * Rule-based format defined by a pattern string.
185 UNUM_PATTERN_RULEBASED
,
187 * Currency format with an ISO currency code, e.g., "USD1.00".
192 * Currency format with a pluralized currency name,
193 * e.g., "1.00 US dollar" and "3.00 US dollars".
196 UNUM_CURRENCY_PLURAL
,
198 * One more than the highest number format style constant.
201 UNUM_FORMAT_STYLE_COUNT
,
206 UNUM_DEFAULT
= UNUM_DECIMAL
,
208 * Alias for UNUM_PATTERN_DECIMAL
211 UNUM_IGNORE
= UNUM_PATTERN_DECIMAL
212 } UNumberFormatStyle
;
214 /** The possible number format rounding modes.
217 typedef enum UNumberFormatRoundingMode
{
227 #ifndef U_HIDE_DEPRECATED_API
229 * Half-even rounding, misspelled name
230 * @deprecated, ICU 3.8
232 UNUM_FOUND_HALFEVEN
= UNUM_ROUND_HALFEVEN
,
233 #endif /* U_HIDE_DEPRECATED_API */
237 * ROUND_UNNECESSARY reports an error if formatted result is not exact.
240 UNUM_ROUND_UNNECESSARY
241 } UNumberFormatRoundingMode
;
243 /** The possible number format pad positions.
246 typedef enum UNumberFormatPadPosition
{
247 UNUM_PAD_BEFORE_PREFIX
,
248 UNUM_PAD_AFTER_PREFIX
,
249 UNUM_PAD_BEFORE_SUFFIX
,
250 UNUM_PAD_AFTER_SUFFIX
251 } UNumberFormatPadPosition
;
253 #ifndef U_HIDE_DRAFT_API
255 * Constants for specifying short or long format.
258 typedef enum UNumberCompactStyle
{
264 } UNumberCompactStyle
;
265 #endif /* U_HIDE_DRAFT_API */
268 * Constants for specifying currency spacing
271 enum UCurrencySpacing
{
272 /** @stable ICU 4.8 */
274 /** @stable ICU 4.8 */
275 UNUM_CURRENCY_SURROUNDING_MATCH
,
276 /** @stable ICU 4.8 */
277 UNUM_CURRENCY_INSERT
,
278 /** @stable ICU 4.8 */
279 UNUM_CURRENCY_SPACING_COUNT
281 typedef enum UCurrencySpacing UCurrencySpacing
; /**< @stable ICU 4.8 */
285 * FieldPosition and UFieldPosition selectors for format fields
286 * defined by NumberFormat and UNumberFormat.
289 typedef enum UNumberFormatFields
{
290 /** @stable ICU 49 */
292 /** @stable ICU 49 */
294 /** @stable ICU 49 */
295 UNUM_DECIMAL_SEPARATOR_FIELD
,
296 /** @stable ICU 49 */
297 UNUM_EXPONENT_SYMBOL_FIELD
,
298 /** @stable ICU 49 */
299 UNUM_EXPONENT_SIGN_FIELD
,
300 /** @stable ICU 49 */
302 /** @stable ICU 49 */
303 UNUM_GROUPING_SEPARATOR_FIELD
,
304 /** @stable ICU 49 */
306 /** @stable ICU 49 */
308 /** @stable ICU 49 */
310 /** @stable ICU 49 */
312 /** @stable ICU 49 */
314 } UNumberFormatFields
;
318 * Create and return a new UNumberFormat for formatting and parsing
319 * numbers. A UNumberFormat may be used to format numbers by calling
320 * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
321 * The caller must call {@link #unum_close } when done to release resources
322 * used by this object.
323 * @param style The type of number format to open: one of
324 * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT,
325 * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
326 * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
327 * number format is opened using the given pattern, which must conform
328 * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
330 * @param pattern A pattern specifying the format to use.
331 * This parameter is ignored unless the style is
332 * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
333 * @param patternLength The number of characters in the pattern, or -1
334 * if null-terminated. This parameter is ignored unless the style is
336 * @param locale A locale identifier to use to determine formatting
337 * and parsing conventions, or NULL to use the default locale.
338 * @param parseErr A pointer to a UParseError struct to receive the
339 * details of any parsing errors, or NULL if no parsing error details
341 * @param status A pointer to an input-output UErrorCode.
342 * @return A pointer to a newly created UNumberFormat, or NULL if an
348 U_STABLE UNumberFormat
* U_EXPORT2
349 unum_open( UNumberFormatStyle style
,
350 const UChar
* pattern
,
351 int32_t patternLength
,
353 UParseError
* parseErr
,
358 * Close a UNumberFormat.
359 * Once closed, a UNumberFormat may no longer be used.
360 * @param fmt The formatter to close.
363 U_STABLE
void U_EXPORT2
364 unum_close(UNumberFormat
* fmt
);
366 #if U_SHOW_CPLUSPLUS_API
371 * \class LocalUNumberFormatPointer
372 * "Smart pointer" class, closes a UNumberFormat via unum_close().
373 * For most methods see the LocalPointerBase base class.
375 * @see LocalPointerBase
379 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer
, UNumberFormat
, unum_close
);
386 * Open a copy of a UNumberFormat.
387 * This function performs a deep copy.
388 * @param fmt The format to copy
389 * @param status A pointer to an UErrorCode to receive any errors.
390 * @return A pointer to a UNumberFormat identical to fmt.
393 U_STABLE UNumberFormat
* U_EXPORT2
394 unum_clone(const UNumberFormat
*fmt
,
398 * Format an integer using a UNumberFormat.
399 * The integer will be formatted according to the UNumberFormat's locale.
400 * @param fmt The formatter to use.
401 * @param number The number to format.
402 * @param result A pointer to a buffer to receive the formatted number.
403 * @param resultLength The maximum size of result.
404 * @param pos A pointer to a UFieldPosition. On input, position->field
405 * is read. On output, position->beginIndex and position->endIndex indicate
406 * the beginning and ending indices of field number position->field, if such
407 * a field exists. This parameter may be NULL, in which case no field
408 * @param status A pointer to an UErrorCode to receive any errors
409 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
410 * @see unum_formatInt64
411 * @see unum_formatDouble
413 * @see unum_parseInt64
414 * @see unum_parseDouble
415 * @see UFieldPosition
418 U_STABLE
int32_t U_EXPORT2
419 unum_format( const UNumberFormat
* fmt
,
422 int32_t resultLength
,
427 * Format an int64 using a UNumberFormat.
428 * The int64 will be formatted according to the UNumberFormat's locale.
429 * @param fmt The formatter to use.
430 * @param number The number to format.
431 * @param result A pointer to a buffer to receive the formatted number.
432 * @param resultLength The maximum size of result.
433 * @param pos A pointer to a UFieldPosition. On input, position->field
434 * is read. On output, position->beginIndex and position->endIndex indicate
435 * the beginning and ending indices of field number position->field, if such
436 * a field exists. This parameter may be NULL, in which case no field
437 * @param status A pointer to an UErrorCode to receive any errors
438 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
440 * @see unum_formatDouble
442 * @see unum_parseInt64
443 * @see unum_parseDouble
444 * @see UFieldPosition
447 U_STABLE
int32_t U_EXPORT2
448 unum_formatInt64(const UNumberFormat
*fmt
,
451 int32_t resultLength
,
456 * Format a double using a UNumberFormat.
457 * The double will be formatted according to the UNumberFormat's locale.
458 * @param fmt The formatter to use.
459 * @param number The number to format.
460 * @param result A pointer to a buffer to receive the formatted number.
461 * @param resultLength The maximum size of result.
462 * @param pos A pointer to a UFieldPosition. On input, position->field
463 * is read. On output, position->beginIndex and position->endIndex indicate
464 * the beginning and ending indices of field number position->field, if such
465 * a field exists. This parameter may be NULL, in which case no field
466 * @param status A pointer to an UErrorCode to receive any errors
467 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
469 * @see unum_formatInt64
471 * @see unum_parseInt64
472 * @see unum_parseDouble
473 * @see UFieldPosition
476 U_STABLE
int32_t U_EXPORT2
477 unum_formatDouble( const UNumberFormat
* fmt
,
480 int32_t resultLength
,
481 UFieldPosition
*pos
, /* 0 if ignore */
485 * Format a decimal number using a UNumberFormat.
486 * The number will be formatted according to the UNumberFormat's locale.
487 * The syntax of the input number is a "numeric string"
488 * as defined in the Decimal Arithmetic Specification, available at
489 * http://speleotrove.com/decimal
490 * @param fmt The formatter to use.
491 * @param number The number to format.
492 * @param length The length of the input number, or -1 if the input is nul-terminated.
493 * @param result A pointer to a buffer to receive the formatted number.
494 * @param resultLength The maximum size of result.
495 * @param pos A pointer to a UFieldPosition. On input, position->field
496 * is read. On output, position->beginIndex and position->endIndex indicate
497 * the beginning and ending indices of field number position->field, if such
498 * a field exists. This parameter may be NULL, in which case it is ignored.
499 * @param status A pointer to an UErrorCode to receive any errors
500 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
502 * @see unum_formatInt64
504 * @see unum_parseInt64
505 * @see unum_parseDouble
506 * @see UFieldPosition
509 U_STABLE
int32_t U_EXPORT2
510 unum_formatDecimal( const UNumberFormat
* fmt
,
514 int32_t resultLength
,
515 UFieldPosition
*pos
, /* 0 if ignore */
519 * Format a double currency amount using a UNumberFormat.
520 * The double will be formatted according to the UNumberFormat's locale.
521 * @param fmt the formatter to use
522 * @param number the number to format
523 * @param currency the 3-letter null-terminated ISO 4217 currency code
524 * @param result a pointer to the buffer to receive the formatted number
525 * @param resultLength the maximum number of UChars to write to result
526 * @param pos a pointer to a UFieldPosition. On input,
527 * position->field is read. On output, position->beginIndex and
528 * position->endIndex indicate the beginning and ending indices of
529 * field number position->field, if such a field exists. This
530 * parameter may be NULL, in which case it is ignored.
531 * @param status a pointer to an input-output UErrorCode
532 * @return the total buffer size needed; if greater than resultLength,
533 * the output was truncated.
534 * @see unum_formatDouble
535 * @see unum_parseDoubleCurrency
536 * @see UFieldPosition
539 U_STABLE
int32_t U_EXPORT2
540 unum_formatDoubleCurrency(const UNumberFormat
* fmt
,
544 int32_t resultLength
,
545 UFieldPosition
* pos
, /* ignored if 0 */
549 * Parse a string into an integer using a UNumberFormat.
550 * The string will be parsed according to the UNumberFormat's locale.
551 * @param fmt The formatter to use.
552 * @param text The text to parse.
553 * @param textLength The length of text, or -1 if null-terminated.
554 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
555 * to begin parsing. If not 0, on output the offset at which parsing ended.
556 * @param status A pointer to an UErrorCode to receive any errors
557 * @return The value of the parsed integer
558 * @see unum_parseInt64
559 * @see unum_parseDouble
561 * @see unum_formatInt64
562 * @see unum_formatDouble
565 U_STABLE
int32_t U_EXPORT2
566 unum_parse( const UNumberFormat
* fmt
,
569 int32_t *parsePos
/* 0 = start */,
573 * Parse a string into an int64 using a UNumberFormat.
574 * The string will be parsed according to the UNumberFormat's locale.
575 * @param fmt The formatter to use.
576 * @param text The text to parse.
577 * @param textLength The length of text, or -1 if null-terminated.
578 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
579 * to begin parsing. If not 0, on output the offset at which parsing ended.
580 * @param status A pointer to an UErrorCode to receive any errors
581 * @return The value of the parsed integer
583 * @see unum_parseDouble
585 * @see unum_formatInt64
586 * @see unum_formatDouble
589 U_STABLE
int64_t U_EXPORT2
590 unum_parseInt64(const UNumberFormat
* fmt
,
593 int32_t *parsePos
/* 0 = start */,
597 * Parse a string into a double using a UNumberFormat.
598 * The string will be parsed according to the UNumberFormat's locale.
599 * @param fmt The formatter to use.
600 * @param text The text to parse.
601 * @param textLength The length of text, or -1 if null-terminated.
602 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
603 * to begin parsing. If not 0, on output the offset at which parsing ended.
604 * @param status A pointer to an UErrorCode to receive any errors
605 * @return The value of the parsed double
607 * @see unum_parseInt64
609 * @see unum_formatInt64
610 * @see unum_formatDouble
613 U_STABLE
double U_EXPORT2
614 unum_parseDouble( const UNumberFormat
* fmt
,
617 int32_t *parsePos
/* 0 = start */,
622 * Parse a number from a string into an unformatted numeric string using a UNumberFormat.
623 * The input string will be parsed according to the UNumberFormat's locale.
624 * The syntax of the output is a "numeric string"
625 * as defined in the Decimal Arithmetic Specification, available at
626 * http://speleotrove.com/decimal
627 * @param fmt The formatter to use.
628 * @param text The text to parse.
629 * @param textLength The length of text, or -1 if null-terminated.
630 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
631 * to begin parsing. If not 0, on output the offset at which parsing ended.
632 * @param outBuf A (char *) buffer to receive the parsed number as a string. The output string
633 * will be nul-terminated if there is sufficient space.
634 * @param outBufLength The size of the output buffer. May be zero, in which case
635 * the outBuf pointer may be NULL, and the function will return the
636 * size of the output string.
637 * @param status A pointer to an UErrorCode to receive any errors
638 * @return the length of the output string, not including any terminating nul.
640 * @see unum_parseInt64
642 * @see unum_formatInt64
643 * @see unum_formatDouble
646 U_STABLE
int32_t U_EXPORT2
647 unum_parseDecimal(const UNumberFormat
* fmt
,
650 int32_t *parsePos
/* 0 = start */,
652 int32_t outBufLength
,
656 * Parse a string into a double and a currency using a UNumberFormat.
657 * The string will be parsed according to the UNumberFormat's locale.
658 * @param fmt the formatter to use
659 * @param text the text to parse
660 * @param textLength the length of text, or -1 if null-terminated
661 * @param parsePos a pointer to an offset index into text at which to
662 * begin parsing. On output, *parsePos will point after the last
663 * parsed character. This parameter may be 0, in which case parsing
664 * begins at offset 0.
665 * @param currency a pointer to the buffer to receive the parsed null-
666 * terminated currency. This buffer must have a capacity of at least
668 * @param status a pointer to an input-output UErrorCode
669 * @return the parsed double
670 * @see unum_parseDouble
671 * @see unum_formatDoubleCurrency
674 U_STABLE
double U_EXPORT2
675 unum_parseDoubleCurrency(const UNumberFormat
* fmt
,
678 int32_t* parsePos
, /* 0 = start */
683 * Set the pattern used by a UNumberFormat. This can only be used
684 * on a DecimalFormat, other formats return U_UNSUPPORTED_ERROR
686 * @param format The formatter to set.
687 * @param localized TRUE if the pattern is localized, FALSE otherwise.
688 * @param pattern The new pattern
689 * @param patternLength The length of pattern, or -1 if null-terminated.
690 * @param parseError A pointer to UParseError to recieve information
691 * about errors occurred during parsing, or NULL if no parse error
692 * information is desired.
693 * @param status A pointer to an input-output UErrorCode.
694 * @see unum_toPattern
698 U_STABLE
void U_EXPORT2
699 unum_applyPattern( UNumberFormat
*format
,
701 const UChar
*pattern
,
702 int32_t patternLength
,
703 UParseError
*parseError
,
708 * Get a locale for which decimal formatting patterns are available.
709 * A UNumberFormat in a locale returned by this function will perform the correct
710 * formatting and parsing for the locale. The results of this call are not
711 * valid for rule-based number formats.
712 * @param localeIndex The index of the desired locale.
713 * @return A locale for which number formatting patterns are available, or 0 if none.
714 * @see unum_countAvailable
717 U_STABLE
const char* U_EXPORT2
718 unum_getAvailable(int32_t localeIndex
);
721 * Determine how many locales have decimal formatting patterns available. The
722 * results of this call are not valid for rule-based number formats.
723 * This function is useful for determining the loop ending condition for
724 * calls to {@link #unum_getAvailable }.
725 * @return The number of locales for which decimal formatting patterns are available.
726 * @see unum_getAvailable
729 U_STABLE
int32_t U_EXPORT2
730 unum_countAvailable(void);
732 #if UCONFIG_HAVE_PARSEALLINPUT
736 typedef enum UNumberFormatAttributeValue
{
743 } UNumberFormatAttributeValue
;
746 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
747 typedef enum UNumberFormatAttribute
{
748 /** Parse integers only */
750 /** Use grouping separator */
752 /** Always show decimal point */
753 UNUM_DECIMAL_ALWAYS_SHOWN
,
754 /** Maximum integer digits */
755 UNUM_MAX_INTEGER_DIGITS
,
756 /** Minimum integer digits */
757 UNUM_MIN_INTEGER_DIGITS
,
758 /** Integer digits */
760 /** Maximum fraction digits */
761 UNUM_MAX_FRACTION_DIGITS
,
762 /** Minimum fraction digits */
763 UNUM_MIN_FRACTION_DIGITS
,
764 /** Fraction digits */
765 UNUM_FRACTION_DIGITS
,
772 /** Rounding increment */
773 UNUM_ROUNDING_INCREMENT
,
774 /** The width to which the output of <code>format()</code> is padded. */
776 /** The position at which padding will take place. */
777 UNUM_PADDING_POSITION
,
778 /** Secondary grouping size */
779 UNUM_SECONDARY_GROUPING_SIZE
,
780 /** Use significant digits
782 UNUM_SIGNIFICANT_DIGITS_USED
,
783 /** Minimum significant digits
785 UNUM_MIN_SIGNIFICANT_DIGITS
,
786 /** Maximum significant digits
788 UNUM_MAX_SIGNIFICANT_DIGITS
,
789 /** Lenient parse mode used by rule-based formats.
793 #if UCONFIG_HAVE_PARSEALLINPUT
794 /** Consume all input. (may use fastpath). Set to UNUM_YES (require fastpath), UNUM_NO (skip fastpath), or UNUM_MAYBE (heuristic).
795 * This is an internal ICU API. Do not use.
798 UNUM_PARSE_ALL_INPUT
,
800 #ifndef U_HIDE_DRAFT_API
802 * Scale, which adjusts the position of the
803 * decimal point when formatting. Amounts will be multiplied by 10 ^ (scale)
804 * before they are formatted. The default value for the scale is 0 ( no adjustment ).
806 * <p>Example: setting the scale to 3, 123 formats as "123,000"
807 * <p>Example: setting the scale to -4, 123 formats as "0.0123"
810 UNUM_SCALE
= UNUM_LENIENT_PARSE
+ 2,
811 #endif /* U_HIDE_DRAFT_API */
812 #ifndef U_HIDE_INTERNAL_API
813 /** Count of "regular" numeric attributes.
815 UNUM_NUMERIC_ATTRIBUTE_COUNT
,
817 /** One below the first bitfield-boolean item.
818 * All items after this one are stored in boolean form.
820 UNUM_MAX_NONBOOLEAN_ATTRIBUTE
= 0x0FFF,
821 #endif /* U_HIDE_INTERNAL_API */
823 #ifndef U_HIDE_DRAFT_API
824 /** If 1, specifies that if setting the "max integer digits" attribute would truncate a value, set an error status rather than silently truncating.
825 * For example, formatting the value 1234 with 4 max int digits would succeed, but formatting 12345 would fail. There is no effect on parsing.
826 * Default: 0 (not set)
829 UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS
= 0x1000,
831 * 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.
832 * Has no effect on formatting.
836 UNUM_PARSE_NO_EXPONENT
,
837 #endif /* U_HIDE_DRAFT_API */
839 #ifndef U_HIDE_INTERNAL_API
840 /** Limit of boolean attributes.
842 UNUM_LIMIT_BOOLEAN_ATTRIBUTE
843 #endif /* U_HIDE_INTERNAL_API */
844 } UNumberFormatAttribute
;
847 * Get a numeric attribute associated with a UNumberFormat.
848 * An example of a numeric attribute is the number of integer digits a formatter will produce.
849 * @param fmt The formatter to query.
850 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
851 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
852 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
853 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
855 * @return The value of attr.
856 * @see unum_setAttribute
857 * @see unum_getDoubleAttribute
858 * @see unum_setDoubleAttribute
859 * @see unum_getTextAttribute
860 * @see unum_setTextAttribute
863 U_STABLE
int32_t U_EXPORT2
864 unum_getAttribute(const UNumberFormat
* fmt
,
865 UNumberFormatAttribute attr
);
868 * Set a numeric attribute associated with a UNumberFormat.
869 * An example of a numeric attribute is the number of integer digits a formatter will produce. If the
870 * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
871 * the lenient-parse attribute.
872 * @param fmt The formatter to set.
873 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
874 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
875 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
876 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
877 * UNUM_LENIENT_PARSE, or UNUM_SCALE.
878 * @param newValue The new value of attr.
879 * @see unum_getAttribute
880 * @see unum_getDoubleAttribute
881 * @see unum_setDoubleAttribute
882 * @see unum_getTextAttribute
883 * @see unum_setTextAttribute
886 U_STABLE
void U_EXPORT2
887 unum_setAttribute( UNumberFormat
* fmt
,
888 UNumberFormatAttribute attr
,
893 * Get a numeric attribute associated with a UNumberFormat.
894 * An example of a numeric attribute is the number of integer digits a formatter will produce.
895 * If the formatter does not understand the attribute, -1 is returned.
896 * @param fmt The formatter to query.
897 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
898 * @return The value of attr.
899 * @see unum_getAttribute
900 * @see unum_setAttribute
901 * @see unum_setDoubleAttribute
902 * @see unum_getTextAttribute
903 * @see unum_setTextAttribute
906 U_STABLE
double U_EXPORT2
907 unum_getDoubleAttribute(const UNumberFormat
* fmt
,
908 UNumberFormatAttribute attr
);
911 * Set a numeric attribute associated with a UNumberFormat.
912 * An example of a numeric attribute is the number of integer digits a formatter will produce.
913 * If the formatter does not understand the attribute, this call is ignored.
914 * @param fmt The formatter to set.
915 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
916 * @param newValue The new value of attr.
917 * @see unum_getAttribute
918 * @see unum_setAttribute
919 * @see unum_getDoubleAttribute
920 * @see unum_getTextAttribute
921 * @see unum_setTextAttribute
924 U_STABLE
void U_EXPORT2
925 unum_setDoubleAttribute( UNumberFormat
* fmt
,
926 UNumberFormatAttribute attr
,
929 /** The possible UNumberFormat text attributes @stable ICU 2.0*/
930 typedef enum UNumberFormatTextAttribute
{
931 /** Positive prefix */
932 UNUM_POSITIVE_PREFIX
,
933 /** Positive suffix */
934 UNUM_POSITIVE_SUFFIX
,
935 /** Negative prefix */
936 UNUM_NEGATIVE_PREFIX
,
937 /** Negative suffix */
938 UNUM_NEGATIVE_SUFFIX
,
939 /** The character used to pad to the format width. */
940 UNUM_PADDING_CHARACTER
,
941 /** The ISO currency code */
944 * The default rule set. This is only available with rule-based formatters.
947 UNUM_DEFAULT_RULESET
,
949 * The public rule sets. This is only available with rule-based formatters.
950 * This is a read-only attribute. The public rulesets are returned as a
951 * single string, with each ruleset name delimited by ';' (semicolon).
955 } UNumberFormatTextAttribute
;
958 * Get a text attribute associated with a UNumberFormat.
959 * An example of a text attribute is the suffix for positive numbers. If the formatter
960 * does not understand the attribute, U_UNSUPPORTED_ERROR is returned as the status.
961 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
962 * @param fmt The formatter to query.
963 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
964 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
965 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
966 * @param result A pointer to a buffer to receive the attribute.
967 * @param resultLength The maximum size of result.
968 * @param status A pointer to an UErrorCode to receive any errors
969 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
970 * @see unum_setTextAttribute
971 * @see unum_getAttribute
972 * @see unum_setAttribute
975 U_STABLE
int32_t U_EXPORT2
976 unum_getTextAttribute( const UNumberFormat
* fmt
,
977 UNumberFormatTextAttribute tag
,
979 int32_t resultLength
,
983 * Set a text attribute associated with a UNumberFormat.
984 * An example of a text attribute is the suffix for positive numbers. Rule-based formatters
985 * only understand UNUM_DEFAULT_RULESET.
986 * @param fmt The formatter to set.
987 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
988 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
989 * or UNUM_DEFAULT_RULESET.
990 * @param newValue The new value of attr.
991 * @param newValueLength The length of newValue, or -1 if null-terminated.
992 * @param status A pointer to an UErrorCode to receive any errors
993 * @see unum_getTextAttribute
994 * @see unum_getAttribute
995 * @see unum_setAttribute
998 U_STABLE
void U_EXPORT2
999 unum_setTextAttribute( UNumberFormat
* fmt
,
1000 UNumberFormatTextAttribute tag
,
1001 const UChar
* newValue
,
1002 int32_t newValueLength
,
1003 UErrorCode
*status
);
1006 * Extract the pattern from a UNumberFormat. The pattern will follow
1007 * the DecimalFormat pattern syntax.
1008 * @param fmt The formatter to query.
1009 * @param isPatternLocalized TRUE if the pattern should be localized,
1010 * FALSE otherwise. This is ignored if the formatter is a rule-based
1012 * @param result A pointer to a buffer to receive the pattern.
1013 * @param resultLength The maximum size of result.
1014 * @param status A pointer to an input-output UErrorCode.
1015 * @return The total buffer size needed; if greater than resultLength,
1016 * the output was truncated.
1017 * @see unum_applyPattern
1018 * @see DecimalFormat
1021 U_STABLE
int32_t U_EXPORT2
1022 unum_toPattern( const UNumberFormat
* fmt
,
1023 UBool isPatternLocalized
,
1025 int32_t resultLength
,
1026 UErrorCode
* status
);
1030 * Constants for specifying a number format symbol.
1033 typedef enum UNumberFormatSymbol
{
1034 /** The decimal separator */
1035 UNUM_DECIMAL_SEPARATOR_SYMBOL
= 0,
1036 /** The grouping separator */
1037 UNUM_GROUPING_SEPARATOR_SYMBOL
= 1,
1038 /** The pattern separator */
1039 UNUM_PATTERN_SEPARATOR_SYMBOL
= 2,
1040 /** The percent sign */
1041 UNUM_PERCENT_SYMBOL
= 3,
1043 UNUM_ZERO_DIGIT_SYMBOL
= 4,
1044 /** Character representing a digit in the pattern */
1045 UNUM_DIGIT_SYMBOL
= 5,
1046 /** The minus sign */
1047 UNUM_MINUS_SIGN_SYMBOL
= 6,
1048 /** The plus sign */
1049 UNUM_PLUS_SIGN_SYMBOL
= 7,
1050 /** The currency symbol */
1051 UNUM_CURRENCY_SYMBOL
= 8,
1052 /** The international currency symbol */
1053 UNUM_INTL_CURRENCY_SYMBOL
= 9,
1054 /** The monetary separator */
1055 UNUM_MONETARY_SEPARATOR_SYMBOL
= 10,
1056 /** The exponential symbol */
1057 UNUM_EXPONENTIAL_SYMBOL
= 11,
1058 /** Per mill symbol */
1059 UNUM_PERMILL_SYMBOL
= 12,
1060 /** Escape padding character */
1061 UNUM_PAD_ESCAPE_SYMBOL
= 13,
1062 /** Infinity symbol */
1063 UNUM_INFINITY_SYMBOL
= 14,
1065 UNUM_NAN_SYMBOL
= 15,
1066 /** Significant digit symbol
1067 * @stable ICU 3.0 */
1068 UNUM_SIGNIFICANT_DIGIT_SYMBOL
= 16,
1069 /** The monetary grouping separator
1072 UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL
= 17,
1076 UNUM_ONE_DIGIT_SYMBOL
= 18,
1080 UNUM_TWO_DIGIT_SYMBOL
= 19,
1084 UNUM_THREE_DIGIT_SYMBOL
= 20,
1088 UNUM_FOUR_DIGIT_SYMBOL
= 21,
1092 UNUM_FIVE_DIGIT_SYMBOL
= 22,
1096 UNUM_SIX_DIGIT_SYMBOL
= 23,
1100 UNUM_SEVEN_DIGIT_SYMBOL
= 24,
1104 UNUM_EIGHT_DIGIT_SYMBOL
= 25,
1108 UNUM_NINE_DIGIT_SYMBOL
= 26,
1109 /** count symbol constants */
1110 UNUM_FORMAT_SYMBOL_COUNT
= 27
1111 } UNumberFormatSymbol
;
1114 * Get a symbol associated with a UNumberFormat.
1115 * A UNumberFormat uses symbols to represent the special locale-dependent
1116 * characters in a number, for example the percent sign. This API is not
1117 * supported for rule-based formatters.
1118 * @param fmt The formatter to query.
1119 * @param symbol The UNumberFormatSymbol constant for the symbol to get
1120 * @param buffer The string buffer that will receive the symbol string;
1121 * if it is NULL, then only the length of the symbol is returned
1122 * @param size The size of the string buffer
1123 * @param status A pointer to an UErrorCode to receive any errors
1124 * @return The length of the symbol; the buffer is not modified if
1125 * <code>length>=size</code>
1126 * @see unum_setSymbol
1129 U_STABLE
int32_t U_EXPORT2
1130 unum_getSymbol(const UNumberFormat
*fmt
,
1131 UNumberFormatSymbol symbol
,
1134 UErrorCode
*status
);
1137 * Set a symbol associated with a UNumberFormat.
1138 * A UNumberFormat uses symbols to represent the special locale-dependent
1139 * characters in a number, for example the percent sign. This API is not
1140 * supported for rule-based formatters.
1141 * @param fmt The formatter to set.
1142 * @param symbol The UNumberFormatSymbol constant for the symbol to set
1143 * @param value The string to set the symbol to
1144 * @param length The length of the string, or -1 for a zero-terminated string
1145 * @param status A pointer to an UErrorCode to receive any errors.
1146 * @see unum_getSymbol
1149 U_STABLE
void U_EXPORT2
1150 unum_setSymbol(UNumberFormat
*fmt
,
1151 UNumberFormatSymbol symbol
,
1154 UErrorCode
*status
);
1158 * Get the locale for this number format object.
1159 * You can choose between valid and actual locale.
1160 * @param fmt The formatter to get the locale from
1161 * @param type type of the locale we're looking for (valid or actual)
1162 * @param status error code for the operation
1163 * @return the locale name
1166 U_STABLE
const char* U_EXPORT2
1167 unum_getLocaleByType(const UNumberFormat
*fmt
,
1168 ULocDataLocaleType type
,
1169 UErrorCode
* status
);
1171 #endif /* #if !UCONFIG_NO_FORMATTING */