2 *******************************************************************************
3 * Copyright (C) 1997-2012, 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_getAttribues() and unum_setAtributes(), 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
;
254 * Constants for specifying currency spacing
257 enum UCurrencySpacing
{
258 /** @stable ICU 4.8 */
260 /** @stable ICU 4.8 */
261 UNUM_CURRENCY_SURROUNDING_MATCH
,
262 /** @stable ICU 4.8 */
263 UNUM_CURRENCY_INSERT
,
264 /** @stable ICU 4.8 */
265 UNUM_CURRENCY_SPACING_COUNT
267 typedef enum UCurrencySpacing UCurrencySpacing
; /**< @stable ICU 4.8 */
271 * FieldPosition and UFieldPosition selectors for format fields
272 * defined by NumberFormat and UNumberFormat.
275 typedef enum UNumberFormatFields
{
276 /** @stable ICU 49 */
278 /** @stable ICU 49 */
280 /** @stable ICU 49 */
281 UNUM_DECIMAL_SEPARATOR_FIELD
,
282 /** @stable ICU 49 */
283 UNUM_EXPONENT_SYMBOL_FIELD
,
284 /** @stable ICU 49 */
285 UNUM_EXPONENT_SIGN_FIELD
,
286 /** @stable ICU 49 */
288 /** @stable ICU 49 */
289 UNUM_GROUPING_SEPARATOR_FIELD
,
290 /** @stable ICU 49 */
292 /** @stable ICU 49 */
294 /** @stable ICU 49 */
296 /** @stable ICU 49 */
298 /** @stable ICU 49 */
300 } UNumberFormatFields
;
304 * Create and return a new UNumberFormat for formatting and parsing
305 * numbers. A UNumberFormat may be used to format numbers by calling
306 * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
307 * The caller must call {@link #unum_close } when done to release resources
308 * used by this object.
309 * @param style The type of number format to open: one of
310 * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT,
311 * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
312 * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
313 * number format is opened using the given pattern, which must conform
314 * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
316 * @param pattern A pattern specifying the format to use.
317 * This parameter is ignored unless the style is
318 * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
319 * @param patternLength The number of characters in the pattern, or -1
320 * if null-terminated. This parameter is ignored unless the style is
322 * @param locale A locale identifier to use to determine formatting
323 * and parsing conventions, or NULL to use the default locale.
324 * @param parseErr A pointer to a UParseError struct to receive the
325 * details of any parsing errors, or NULL if no parsing error details
327 * @param status A pointer to an input-output UErrorCode.
328 * @return A pointer to a newly created UNumberFormat, or NULL if an
334 U_STABLE UNumberFormat
* U_EXPORT2
335 unum_open( UNumberFormatStyle style
,
336 const UChar
* pattern
,
337 int32_t patternLength
,
339 UParseError
* parseErr
,
344 * Close a UNumberFormat.
345 * Once closed, a UNumberFormat may no longer be used.
346 * @param fmt The formatter to close.
349 U_STABLE
void U_EXPORT2
350 unum_close(UNumberFormat
* fmt
);
352 #if U_SHOW_CPLUSPLUS_API
357 * \class LocalUNumberFormatPointer
358 * "Smart pointer" class, closes a UNumberFormat via unum_close().
359 * For most methods see the LocalPointerBase base class.
361 * @see LocalPointerBase
365 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer
, UNumberFormat
, unum_close
);
372 * Open a copy of a UNumberFormat.
373 * This function performs a deep copy.
374 * @param fmt The format to copy
375 * @param status A pointer to an UErrorCode to receive any errors.
376 * @return A pointer to a UNumberFormat identical to fmt.
379 U_STABLE UNumberFormat
* U_EXPORT2
380 unum_clone(const UNumberFormat
*fmt
,
384 * Format an integer using a UNumberFormat.
385 * The integer will be formatted according to the UNumberFormat's locale.
386 * @param fmt The formatter to use.
387 * @param number The number to format.
388 * @param result A pointer to a buffer to receive the formatted number.
389 * @param resultLength The maximum size of result.
390 * @param pos A pointer to a UFieldPosition. On input, position->field
391 * is read. On output, position->beginIndex and position->endIndex indicate
392 * the beginning and ending indices of field number position->field, if such
393 * a field exists. This parameter may be NULL, in which case no field
394 * @param status A pointer to an UErrorCode to receive any errors
395 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
396 * @see unum_formatInt64
397 * @see unum_formatDouble
399 * @see unum_parseInt64
400 * @see unum_parseDouble
401 * @see UFieldPosition
404 U_STABLE
int32_t U_EXPORT2
405 unum_format( const UNumberFormat
* fmt
,
408 int32_t resultLength
,
413 * Format an int64 using a UNumberFormat.
414 * The int64 will be formatted according to the UNumberFormat's locale.
415 * @param fmt The formatter to use.
416 * @param number The number to format.
417 * @param result A pointer to a buffer to receive the formatted number.
418 * @param resultLength The maximum size of result.
419 * @param pos A pointer to a UFieldPosition. On input, position->field
420 * is read. On output, position->beginIndex and position->endIndex indicate
421 * the beginning and ending indices of field number position->field, if such
422 * a field exists. This parameter may be NULL, in which case no field
423 * @param status A pointer to an UErrorCode to receive any errors
424 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
426 * @see unum_formatDouble
428 * @see unum_parseInt64
429 * @see unum_parseDouble
430 * @see UFieldPosition
433 U_STABLE
int32_t U_EXPORT2
434 unum_formatInt64(const UNumberFormat
*fmt
,
437 int32_t resultLength
,
442 * Format a double using a UNumberFormat.
443 * The double will be formatted according to the UNumberFormat's locale.
444 * @param fmt The formatter to use.
445 * @param number The number to format.
446 * @param result A pointer to a buffer to receive the formatted number.
447 * @param resultLength The maximum size of result.
448 * @param pos A pointer to a UFieldPosition. On input, position->field
449 * is read. On output, position->beginIndex and position->endIndex indicate
450 * the beginning and ending indices of field number position->field, if such
451 * a field exists. This parameter may be NULL, in which case no field
452 * @param status A pointer to an UErrorCode to receive any errors
453 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
455 * @see unum_formatInt64
457 * @see unum_parseInt64
458 * @see unum_parseDouble
459 * @see UFieldPosition
462 U_STABLE
int32_t U_EXPORT2
463 unum_formatDouble( const UNumberFormat
* fmt
,
466 int32_t resultLength
,
467 UFieldPosition
*pos
, /* 0 if ignore */
471 * Format a decimal number using a UNumberFormat.
472 * The number will be formatted according to the UNumberFormat's locale.
473 * The syntax of the input number is a "numeric string"
474 * as defined in the Decimal Arithmetic Specification, available at
475 * http://speleotrove.com/decimal
476 * @param fmt The formatter to use.
477 * @param number The number to format.
478 * @param length The length of the input number, or -1 if the input is nul-terminated.
479 * @param result A pointer to a buffer to receive the formatted number.
480 * @param resultLength The maximum size of result.
481 * @param pos A pointer to a UFieldPosition. On input, position->field
482 * is read. On output, position->beginIndex and position->endIndex indicate
483 * the beginning and ending indices of field number position->field, if such
484 * a field exists. This parameter may be NULL, in which case it is ignored.
485 * @param status A pointer to an UErrorCode to receive any errors
486 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
488 * @see unum_formatInt64
490 * @see unum_parseInt64
491 * @see unum_parseDouble
492 * @see UFieldPosition
495 U_STABLE
int32_t U_EXPORT2
496 unum_formatDecimal( const UNumberFormat
* fmt
,
500 int32_t resultLength
,
501 UFieldPosition
*pos
, /* 0 if ignore */
505 * Format a double currency amount using a UNumberFormat.
506 * The double will be formatted according to the UNumberFormat's locale.
507 * @param fmt the formatter to use
508 * @param number the number to format
509 * @param currency the 3-letter null-terminated ISO 4217 currency code
510 * @param result a pointer to the buffer to receive the formatted number
511 * @param resultLength the maximum number of UChars to write to result
512 * @param pos a pointer to a UFieldPosition. On input,
513 * position->field is read. On output, position->beginIndex and
514 * position->endIndex indicate the beginning and ending indices of
515 * field number position->field, if such a field exists. This
516 * parameter may be NULL, in which case it is ignored.
517 * @param status a pointer to an input-output UErrorCode
518 * @return the total buffer size needed; if greater than resultLength,
519 * the output was truncated.
520 * @see unum_formatDouble
521 * @see unum_parseDoubleCurrency
522 * @see UFieldPosition
525 U_STABLE
int32_t U_EXPORT2
526 unum_formatDoubleCurrency(const UNumberFormat
* fmt
,
530 int32_t resultLength
,
531 UFieldPosition
* pos
, /* ignored if 0 */
535 * Parse a string into an integer using a UNumberFormat.
536 * The string will be parsed according to the UNumberFormat's locale.
537 * @param fmt The formatter to use.
538 * @param text The text to parse.
539 * @param textLength The length of text, or -1 if null-terminated.
540 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
541 * to begin parsing. If not 0, on output the offset at which parsing ended.
542 * @param status A pointer to an UErrorCode to receive any errors
543 * @return The value of the parsed integer
544 * @see unum_parseInt64
545 * @see unum_parseDouble
547 * @see unum_formatInt64
548 * @see unum_formatDouble
551 U_STABLE
int32_t U_EXPORT2
552 unum_parse( const UNumberFormat
* fmt
,
555 int32_t *parsePos
/* 0 = start */,
559 * Parse a string into an int64 using a UNumberFormat.
560 * The string will be parsed according to the UNumberFormat's locale.
561 * @param fmt The formatter to use.
562 * @param text The text to parse.
563 * @param textLength The length of text, or -1 if null-terminated.
564 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
565 * to begin parsing. If not 0, on output the offset at which parsing ended.
566 * @param status A pointer to an UErrorCode to receive any errors
567 * @return The value of the parsed integer
569 * @see unum_parseDouble
571 * @see unum_formatInt64
572 * @see unum_formatDouble
575 U_STABLE
int64_t U_EXPORT2
576 unum_parseInt64(const UNumberFormat
* fmt
,
579 int32_t *parsePos
/* 0 = start */,
583 * Parse a string into a double using a UNumberFormat.
584 * The string will be parsed according to the UNumberFormat's locale.
585 * @param fmt The formatter to use.
586 * @param text The text to parse.
587 * @param textLength The length of text, or -1 if null-terminated.
588 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
589 * to begin parsing. If not 0, on output the offset at which parsing ended.
590 * @param status A pointer to an UErrorCode to receive any errors
591 * @return The value of the parsed double
593 * @see unum_parseInt64
595 * @see unum_formatInt64
596 * @see unum_formatDouble
599 U_STABLE
double U_EXPORT2
600 unum_parseDouble( const UNumberFormat
* fmt
,
603 int32_t *parsePos
/* 0 = start */,
608 * Parse a number from a string into an unformatted numeric string using a UNumberFormat.
609 * The input string will be parsed according to the UNumberFormat's locale.
610 * The syntax of the output is a "numeric string"
611 * as defined in the Decimal Arithmetic Specification, available at
612 * http://speleotrove.com/decimal
613 * @param fmt The formatter to use.
614 * @param text The text to parse.
615 * @param textLength The length of text, or -1 if null-terminated.
616 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
617 * to begin parsing. If not 0, on output the offset at which parsing ended.
618 * @param outBuf A (char *) buffer to receive the parsed number as a string. The output string
619 * will be nul-terminated if there is sufficient space.
620 * @param outBufLength The size of the output buffer. May be zero, in which case
621 * the outBuf pointer may be NULL, and the function will return the
622 * size of the output string.
623 * @param status A pointer to an UErrorCode to receive any errors
624 * @return the length of the output string, not including any terminating nul.
626 * @see unum_parseInt64
628 * @see unum_formatInt64
629 * @see unum_formatDouble
632 U_STABLE
int32_t U_EXPORT2
633 unum_parseDecimal(const UNumberFormat
* fmt
,
636 int32_t *parsePos
/* 0 = start */,
638 int32_t outBufLength
,
642 * Parse a string into a double and a currency using a UNumberFormat.
643 * The string will be parsed according to the UNumberFormat's locale.
644 * @param fmt the formatter to use
645 * @param text the text to parse
646 * @param textLength the length of text, or -1 if null-terminated
647 * @param parsePos a pointer to an offset index into text at which to
648 * begin parsing. On output, *parsePos will point after the last
649 * parsed character. This parameter may be 0, in which case parsing
650 * begins at offset 0.
651 * @param currency a pointer to the buffer to receive the parsed null-
652 * terminated currency. This buffer must have a capacity of at least
654 * @param status a pointer to an input-output UErrorCode
655 * @return the parsed double
656 * @see unum_parseDouble
657 * @see unum_formatDoubleCurrency
660 U_STABLE
double U_EXPORT2
661 unum_parseDoubleCurrency(const UNumberFormat
* fmt
,
664 int32_t* parsePos
, /* 0 = start */
669 * Set the pattern used by a UNumberFormat. This can only be used
670 * on a DecimalFormat, other formats return U_ILLEGAL_ARGUMENT_ERROR
672 * @param format The formatter to set.
673 * @param localized TRUE if the pattern is localized, FALSE otherwise.
674 * @param pattern The new pattern
675 * @param patternLength The length of pattern, or -1 if null-terminated.
676 * @param parseError A pointer to UParseError to recieve information
677 * about errors occurred during parsing, or NULL if no parse error
678 * information is desired.
679 * @param status A pointer to an input-output UErrorCode.
680 * @see unum_toPattern
684 U_STABLE
void U_EXPORT2
685 unum_applyPattern( UNumberFormat
*format
,
687 const UChar
*pattern
,
688 int32_t patternLength
,
689 UParseError
*parseError
,
694 * Get a locale for which decimal formatting patterns are available.
695 * A UNumberFormat in a locale returned by this function will perform the correct
696 * formatting and parsing for the locale. The results of this call are not
697 * valid for rule-based number formats.
698 * @param localeIndex The index of the desired locale.
699 * @return A locale for which number formatting patterns are available, or 0 if none.
700 * @see unum_countAvailable
703 U_STABLE
const char* U_EXPORT2
704 unum_getAvailable(int32_t localeIndex
);
707 * Determine how many locales have decimal formatting patterns available. The
708 * results of this call are not valid for rule-based number formats.
709 * This function is useful for determining the loop ending condition for
710 * calls to {@link #unum_getAvailable }.
711 * @return The number of locales for which decimal formatting patterns are available.
712 * @see unum_getAvailable
715 U_STABLE
int32_t U_EXPORT2
716 unum_countAvailable(void);
718 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
719 typedef enum UNumberFormatAttribute
{
720 /** Parse integers only */
722 /** Use grouping separator */
724 /** Always show decimal point */
725 UNUM_DECIMAL_ALWAYS_SHOWN
,
726 /** Maximum integer digits */
727 UNUM_MAX_INTEGER_DIGITS
,
728 /** Minimum integer digits */
729 UNUM_MIN_INTEGER_DIGITS
,
730 /** Integer digits */
732 /** Maximum fraction digits */
733 UNUM_MAX_FRACTION_DIGITS
,
734 /** Minimum fraction digits */
735 UNUM_MIN_FRACTION_DIGITS
,
736 /** Fraction digits */
737 UNUM_FRACTION_DIGITS
,
744 /** Rounding increment */
745 UNUM_ROUNDING_INCREMENT
,
746 /** The width to which the output of <code>format()</code> is padded. */
748 /** The position at which padding will take place. */
749 UNUM_PADDING_POSITION
,
750 /** Secondary grouping size */
751 UNUM_SECONDARY_GROUPING_SIZE
,
752 /** Use significant digits
754 UNUM_SIGNIFICANT_DIGITS_USED
,
755 /** Minimum significant digits
757 UNUM_MIN_SIGNIFICANT_DIGITS
,
758 /** Maximum significant digits
760 UNUM_MAX_SIGNIFICANT_DIGITS
,
761 /** Lenient parse mode used by rule-based formats.
765 } UNumberFormatAttribute
;
768 * Get a numeric attribute associated with a UNumberFormat.
769 * An example of a numeric attribute is the number of integer digits a formatter will produce.
770 * @param fmt The formatter to query.
771 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
772 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
773 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
774 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE.
775 * @return The value of attr.
776 * @see unum_setAttribute
777 * @see unum_getDoubleAttribute
778 * @see unum_setDoubleAttribute
779 * @see unum_getTextAttribute
780 * @see unum_setTextAttribute
783 U_STABLE
int32_t U_EXPORT2
784 unum_getAttribute(const UNumberFormat
* fmt
,
785 UNumberFormatAttribute attr
);
788 * Set a numeric attribute associated with a UNumberFormat.
789 * An example of a numeric attribute is the number of integer digits a formatter will produce. If the
790 * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
791 * the lenient-parse attribute.
792 * @param fmt The formatter to set.
793 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
794 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
795 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
796 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
797 * or UNUM_LENIENT_PARSE.
798 * @param newValue The new value of attr.
799 * @see unum_getAttribute
800 * @see unum_getDoubleAttribute
801 * @see unum_setDoubleAttribute
802 * @see unum_getTextAttribute
803 * @see unum_setTextAttribute
806 U_STABLE
void U_EXPORT2
807 unum_setAttribute( UNumberFormat
* fmt
,
808 UNumberFormatAttribute attr
,
813 * Get a numeric attribute associated with a UNumberFormat.
814 * An example of a numeric attribute is the number of integer digits a formatter will produce.
815 * If the formatter does not understand the attribute, -1 is returned.
816 * @param fmt The formatter to query.
817 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
818 * @return The value of attr.
819 * @see unum_getAttribute
820 * @see unum_setAttribute
821 * @see unum_setDoubleAttribute
822 * @see unum_getTextAttribute
823 * @see unum_setTextAttribute
826 U_STABLE
double U_EXPORT2
827 unum_getDoubleAttribute(const UNumberFormat
* fmt
,
828 UNumberFormatAttribute attr
);
831 * Set a numeric attribute associated with a UNumberFormat.
832 * An example of a numeric attribute is the number of integer digits a formatter will produce.
833 * If the formatter does not understand the attribute, this call is ignored.
834 * @param fmt The formatter to set.
835 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
836 * @param newValue The new value of attr.
837 * @see unum_getAttribute
838 * @see unum_setAttribute
839 * @see unum_getDoubleAttribute
840 * @see unum_getTextAttribute
841 * @see unum_setTextAttribute
844 U_STABLE
void U_EXPORT2
845 unum_setDoubleAttribute( UNumberFormat
* fmt
,
846 UNumberFormatAttribute attr
,
849 /** The possible UNumberFormat text attributes @stable ICU 2.0*/
850 typedef enum UNumberFormatTextAttribute
{
851 /** Positive prefix */
852 UNUM_POSITIVE_PREFIX
,
853 /** Positive suffix */
854 UNUM_POSITIVE_SUFFIX
,
855 /** Negative prefix */
856 UNUM_NEGATIVE_PREFIX
,
857 /** Negative suffix */
858 UNUM_NEGATIVE_SUFFIX
,
859 /** The character used to pad to the format width. */
860 UNUM_PADDING_CHARACTER
,
861 /** The ISO currency code */
864 * The default rule set. This is only available with rule-based formatters.
867 UNUM_DEFAULT_RULESET
,
869 * The public rule sets. This is only available with rule-based formatters.
870 * This is a read-only attribute. The public rulesets are returned as a
871 * single string, with each ruleset name delimited by ';' (semicolon).
875 } UNumberFormatTextAttribute
;
878 * Get a text attribute associated with a UNumberFormat.
879 * An example of a text attribute is the suffix for positive numbers. If the formatter
880 * does not understand the attributre, U_UNSUPPORTED_ERROR is returned as the status.
881 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
882 * @param fmt The formatter to query.
883 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
884 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
885 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
886 * @param result A pointer to a buffer to receive the attribute.
887 * @param resultLength The maximum size of result.
888 * @param status A pointer to an UErrorCode to receive any errors
889 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
890 * @see unum_setTextAttribute
891 * @see unum_getAttribute
892 * @see unum_setAttribute
895 U_STABLE
int32_t U_EXPORT2
896 unum_getTextAttribute( const UNumberFormat
* fmt
,
897 UNumberFormatTextAttribute tag
,
899 int32_t resultLength
,
903 * Set a text attribute associated with a UNumberFormat.
904 * An example of a text attribute is the suffix for positive numbers. Rule-based formatters
905 * only understand UNUM_DEFAULT_RULESET.
906 * @param fmt The formatter to set.
907 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
908 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
909 * or UNUM_DEFAULT_RULESET.
910 * @param newValue The new value of attr.
911 * @param newValueLength The length of newValue, or -1 if null-terminated.
912 * @param status A pointer to an UErrorCode to receive any errors
913 * @see unum_getTextAttribute
914 * @see unum_getAttribute
915 * @see unum_setAttribute
918 U_STABLE
void U_EXPORT2
919 unum_setTextAttribute( UNumberFormat
* fmt
,
920 UNumberFormatTextAttribute tag
,
921 const UChar
* newValue
,
922 int32_t newValueLength
,
926 * Extract the pattern from a UNumberFormat. The pattern will follow
927 * the DecimalFormat pattern syntax.
928 * @param fmt The formatter to query.
929 * @param isPatternLocalized TRUE if the pattern should be localized,
930 * FALSE otherwise. This is ignored if the formatter is a rule-based
932 * @param result A pointer to a buffer to receive the pattern.
933 * @param resultLength The maximum size of result.
934 * @param status A pointer to an input-output UErrorCode.
935 * @return The total buffer size needed; if greater than resultLength,
936 * the output was truncated.
937 * @see unum_applyPattern
941 U_STABLE
int32_t U_EXPORT2
942 unum_toPattern( const UNumberFormat
* fmt
,
943 UBool isPatternLocalized
,
945 int32_t resultLength
,
950 * Constants for specifying a number format symbol.
953 typedef enum UNumberFormatSymbol
{
954 /** The decimal separator */
955 UNUM_DECIMAL_SEPARATOR_SYMBOL
= 0,
956 /** The grouping separator */
957 UNUM_GROUPING_SEPARATOR_SYMBOL
= 1,
958 /** The pattern separator */
959 UNUM_PATTERN_SEPARATOR_SYMBOL
= 2,
960 /** The percent sign */
961 UNUM_PERCENT_SYMBOL
= 3,
963 UNUM_ZERO_DIGIT_SYMBOL
= 4,
964 /** Character representing a digit in the pattern */
965 UNUM_DIGIT_SYMBOL
= 5,
966 /** The minus sign */
967 UNUM_MINUS_SIGN_SYMBOL
= 6,
969 UNUM_PLUS_SIGN_SYMBOL
= 7,
970 /** The currency symbol */
971 UNUM_CURRENCY_SYMBOL
= 8,
972 /** The international currency symbol */
973 UNUM_INTL_CURRENCY_SYMBOL
= 9,
974 /** The monetary separator */
975 UNUM_MONETARY_SEPARATOR_SYMBOL
= 10,
976 /** The exponential symbol */
977 UNUM_EXPONENTIAL_SYMBOL
= 11,
978 /** Per mill symbol */
979 UNUM_PERMILL_SYMBOL
= 12,
980 /** Escape padding character */
981 UNUM_PAD_ESCAPE_SYMBOL
= 13,
982 /** Infinity symbol */
983 UNUM_INFINITY_SYMBOL
= 14,
985 UNUM_NAN_SYMBOL
= 15,
986 /** Significant digit symbol
988 UNUM_SIGNIFICANT_DIGIT_SYMBOL
= 16,
989 /** The monetary grouping separator
992 UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL
= 17,
996 UNUM_ONE_DIGIT_SYMBOL
= 18,
1000 UNUM_TWO_DIGIT_SYMBOL
= 19,
1004 UNUM_THREE_DIGIT_SYMBOL
= 20,
1008 UNUM_FOUR_DIGIT_SYMBOL
= 21,
1012 UNUM_FIVE_DIGIT_SYMBOL
= 22,
1016 UNUM_SIX_DIGIT_SYMBOL
= 23,
1020 UNUM_SEVEN_DIGIT_SYMBOL
= 24,
1024 UNUM_EIGHT_DIGIT_SYMBOL
= 25,
1028 UNUM_NINE_DIGIT_SYMBOL
= 26,
1029 /** count symbol constants */
1030 UNUM_FORMAT_SYMBOL_COUNT
= 27
1031 } UNumberFormatSymbol
;
1034 * Get a symbol associated with a UNumberFormat.
1035 * A UNumberFormat uses symbols to represent the special locale-dependent
1036 * characters in a number, for example the percent sign. This API is not
1037 * supported for rule-based formatters.
1038 * @param fmt The formatter to query.
1039 * @param symbol The UNumberFormatSymbol constant for the symbol to get
1040 * @param buffer The string buffer that will receive the symbol string;
1041 * if it is NULL, then only the length of the symbol is returned
1042 * @param size The size of the string buffer
1043 * @param status A pointer to an UErrorCode to receive any errors
1044 * @return The length of the symbol; the buffer is not modified if
1045 * <code>length>=size</code>
1046 * @see unum_setSymbol
1049 U_STABLE
int32_t U_EXPORT2
1050 unum_getSymbol(const UNumberFormat
*fmt
,
1051 UNumberFormatSymbol symbol
,
1054 UErrorCode
*status
);
1057 * Set a symbol associated with a UNumberFormat.
1058 * A UNumberFormat uses symbols to represent the special locale-dependent
1059 * characters in a number, for example the percent sign. This API is not
1060 * supported for rule-based formatters.
1061 * @param fmt The formatter to set.
1062 * @param symbol The UNumberFormatSymbol constant for the symbol to set
1063 * @param value The string to set the symbol to
1064 * @param length The length of the string, or -1 for a zero-terminated string
1065 * @param status A pointer to an UErrorCode to receive any errors.
1066 * @see unum_getSymbol
1069 U_STABLE
void U_EXPORT2
1070 unum_setSymbol(UNumberFormat
*fmt
,
1071 UNumberFormatSymbol symbol
,
1074 UErrorCode
*status
);
1078 * Get the locale for this number format object.
1079 * You can choose between valid and actual locale.
1080 * @param fmt The formatter to get the locale from
1081 * @param type type of the locale we're looking for (valid or actual)
1082 * @param status error code for the operation
1083 * @return the locale name
1086 U_STABLE
const char* U_EXPORT2
1087 unum_getLocaleByType(const UNumberFormat
*fmt
,
1088 ULocDataLocaleType type
,
1089 UErrorCode
* status
);
1091 #endif /* #if !UCONFIG_NO_FORMATTING */