2 *******************************************************************************
3 * Copyright (C) 1997-2010, 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 pattern
140 UNUM_PATTERN_DECIMAL
=0,
141 /** Decimal format */
143 /** Currency format */
145 /** Percent format */
147 /** Scientific format */
149 /** Spellout rule-based format */
152 * Ordinal rule-based format
157 * Duration rule-based format
162 * Numbering system rule-based format
165 UNUM_NUMBERING_SYSTEM
,
167 * Rule-based format defined by pattern
170 UNUM_PATTERN_RULEBASED
,
171 /** Default format */
172 UNUM_DEFAULT
= UNUM_DECIMAL
,
173 /** (Alias for UNUM_PATTERN_DECIMAL) */
174 UNUM_IGNORE
= UNUM_PATTERN_DECIMAL
175 } UNumberFormatStyle
;
177 /** The possible number format rounding modes.
180 typedef enum UNumberFormatRoundingMode
{
186 * Half-even rounding, misspelled name
187 * @deprecated, ICU 3.8
196 UNUM_ROUND_HALFEVEN
= UNUM_FOUND_HALFEVEN
197 } UNumberFormatRoundingMode
;
199 /** The possible number format pad positions.
202 typedef enum UNumberFormatPadPosition
{
203 UNUM_PAD_BEFORE_PREFIX
,
204 UNUM_PAD_AFTER_PREFIX
,
205 UNUM_PAD_BEFORE_SUFFIX
,
206 UNUM_PAD_AFTER_SUFFIX
207 } UNumberFormatPadPosition
;
210 * Create and return a new UNumberFormat for formatting and parsing
211 * numbers. A UNumberFormat may be used to format numbers by calling
212 * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
213 * The caller must call {@link #unum_close } when done to release resources
214 * used by this object.
215 * @param style The type of number format to open: one of
216 * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT,
217 * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
218 * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
219 * number format is opened using the given pattern, which must conform
220 * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
222 * @param pattern A pattern specifying the format to use.
223 * This parameter is ignored unless the style is
224 * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
225 * @param patternLength The number of characters in the pattern, or -1
226 * if null-terminated. This parameter is ignored unless the style is
228 * @param locale A locale identifier to use to determine formatting
229 * and parsing conventions, or NULL to use the default locale.
230 * @param parseErr A pointer to a UParseError struct to receive the
231 * details of any parsing errors, or NULL if no parsing error details
233 * @param status A pointer to an input-output UErrorCode.
234 * @return A pointer to a newly created UNumberFormat, or NULL if an
240 U_STABLE UNumberFormat
* U_EXPORT2
241 unum_open( UNumberFormatStyle style
,
242 const UChar
* pattern
,
243 int32_t patternLength
,
245 UParseError
* parseErr
,
250 * Close a UNumberFormat.
251 * Once closed, a UNumberFormat may no longer be used.
252 * @param fmt The formatter to close.
255 U_STABLE
void U_EXPORT2
256 unum_close(UNumberFormat
* fmt
);
258 #if U_SHOW_CPLUSPLUS_API
263 * \class LocalUNumberFormatPointer
264 * "Smart pointer" class, closes a UNumberFormat via unum_close().
265 * For most methods see the LocalPointerBase base class.
267 * @see LocalPointerBase
271 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer
, UNumberFormat
, unum_close
);
278 * Open a copy of a UNumberFormat.
279 * This function performs a deep copy.
280 * @param fmt The format to copy
281 * @param status A pointer to an UErrorCode to receive any errors.
282 * @return A pointer to a UNumberFormat identical to fmt.
285 U_STABLE UNumberFormat
* U_EXPORT2
286 unum_clone(const UNumberFormat
*fmt
,
290 * Format an integer using a UNumberFormat.
291 * The integer will be formatted according to the UNumberFormat's locale.
292 * @param fmt The formatter to use.
293 * @param number The number to format.
294 * @param result A pointer to a buffer to receive the formatted number.
295 * @param resultLength The maximum size of result.
296 * @param pos A pointer to a UFieldPosition. On input, position->field
297 * is read. On output, position->beginIndex and position->endIndex indicate
298 * the beginning and ending indices of field number position->field, if such
299 * a field exists. This parameter may be NULL, in which case no field
300 * @param status A pointer to an UErrorCode to receive any errors
301 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
302 * @see unum_formatInt64
303 * @see unum_formatDouble
305 * @see unum_parseInt64
306 * @see unum_parseDouble
307 * @see UFieldPosition
310 U_STABLE
int32_t U_EXPORT2
311 unum_format( const UNumberFormat
* fmt
,
314 int32_t resultLength
,
319 * Format an int64 using a UNumberFormat.
320 * The int64 will be formatted according to the UNumberFormat's locale.
321 * @param fmt The formatter to use.
322 * @param number The number to format.
323 * @param result A pointer to a buffer to receive the formatted number.
324 * @param resultLength The maximum size of result.
325 * @param pos A pointer to a UFieldPosition. On input, position->field
326 * is read. On output, position->beginIndex and position->endIndex indicate
327 * the beginning and ending indices of field number position->field, if such
328 * a field exists. This parameter may be NULL, in which case no field
329 * @param status A pointer to an UErrorCode to receive any errors
330 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
332 * @see unum_formatDouble
334 * @see unum_parseInt64
335 * @see unum_parseDouble
336 * @see UFieldPosition
339 U_STABLE
int32_t U_EXPORT2
340 unum_formatInt64(const UNumberFormat
*fmt
,
343 int32_t resultLength
,
348 * Format a double using a UNumberFormat.
349 * The double will be formatted according to the UNumberFormat's locale.
350 * @param fmt The formatter to use.
351 * @param number The number to format.
352 * @param result A pointer to a buffer to receive the formatted number.
353 * @param resultLength The maximum size of result.
354 * @param pos A pointer to a UFieldPosition. On input, position->field
355 * is read. On output, position->beginIndex and position->endIndex indicate
356 * the beginning and ending indices of field number position->field, if such
357 * a field exists. This parameter may be NULL, in which case no field
358 * @param status A pointer to an UErrorCode to receive any errors
359 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
361 * @see unum_formatInt64
363 * @see unum_parseInt64
364 * @see unum_parseDouble
365 * @see UFieldPosition
368 U_STABLE
int32_t U_EXPORT2
369 unum_formatDouble( const UNumberFormat
* fmt
,
372 int32_t resultLength
,
373 UFieldPosition
*pos
, /* 0 if ignore */
377 * Format a decimal number using a UNumberFormat.
378 * The number will be formatted according to the UNumberFormat's locale.
379 * The syntax of the input number is a "numeric string"
380 * as defined in the Decimal Arithmetic Specification, available at
381 * http://speleotrove.com/decimal
382 * @param fmt The formatter to use.
383 * @param number The number to format.
384 * @param length The length of the input number, or -1 if the input is nul-terminated.
385 * @param result A pointer to a buffer to receive the formatted number.
386 * @param resultLength The maximum size of result.
387 * @param pos A pointer to a UFieldPosition. On input, position->field
388 * is read. On output, position->beginIndex and position->endIndex indicate
389 * the beginning and ending indices of field number position->field, if such
390 * a field exists. This parameter may be NULL, in which case it is ignored.
391 * @param status A pointer to an UErrorCode to receive any errors
392 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
394 * @see unum_formatInt64
396 * @see unum_parseInt64
397 * @see unum_parseDouble
398 * @see UFieldPosition
401 U_STABLE
int32_t U_EXPORT2
402 unum_formatDecimal( const UNumberFormat
* fmt
,
406 int32_t resultLength
,
407 UFieldPosition
*pos
, /* 0 if ignore */
411 * Format a double currency amount using a UNumberFormat.
412 * The double will be formatted according to the UNumberFormat's locale.
413 * @param fmt the formatter to use
414 * @param number the number to format
415 * @param currency the 3-letter null-terminated ISO 4217 currency code
416 * @param result a pointer to the buffer to receive the formatted number
417 * @param resultLength the maximum number of UChars to write to result
418 * @param pos a pointer to a UFieldPosition. On input,
419 * position->field is read. On output, position->beginIndex and
420 * position->endIndex indicate the beginning and ending indices of
421 * field number position->field, if such a field exists. This
422 * parameter may be NULL, in which case it is ignored.
423 * @param status a pointer to an input-output UErrorCode
424 * @return the total buffer size needed; if greater than resultLength,
425 * the output was truncated.
426 * @see unum_formatDouble
427 * @see unum_parseDoubleCurrency
428 * @see UFieldPosition
431 U_STABLE
int32_t U_EXPORT2
432 unum_formatDoubleCurrency(const UNumberFormat
* fmt
,
436 int32_t resultLength
,
437 UFieldPosition
* pos
, /* ignored if 0 */
441 * Parse a string into an integer using a UNumberFormat.
442 * The string will be parsed according to the UNumberFormat's locale.
443 * @param fmt The formatter to use.
444 * @param text The text to parse.
445 * @param textLength The length of text, or -1 if null-terminated.
446 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
447 * to begin parsing. If not 0, on output the offset at which parsing ended.
448 * @param status A pointer to an UErrorCode to receive any errors
449 * @return The value of the parsed integer
450 * @see unum_parseInt64
451 * @see unum_parseDouble
453 * @see unum_formatInt64
454 * @see unum_formatDouble
457 U_STABLE
int32_t U_EXPORT2
458 unum_parse( const UNumberFormat
* fmt
,
461 int32_t *parsePos
/* 0 = start */,
465 * Parse a string into an int64 using a UNumberFormat.
466 * The string will be parsed according to the UNumberFormat's locale.
467 * @param fmt The formatter to use.
468 * @param text The text to parse.
469 * @param textLength The length of text, or -1 if null-terminated.
470 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
471 * to begin parsing. If not 0, on output the offset at which parsing ended.
472 * @param status A pointer to an UErrorCode to receive any errors
473 * @return The value of the parsed integer
475 * @see unum_parseDouble
477 * @see unum_formatInt64
478 * @see unum_formatDouble
481 U_STABLE
int64_t U_EXPORT2
482 unum_parseInt64(const UNumberFormat
* fmt
,
485 int32_t *parsePos
/* 0 = start */,
489 * Parse a string into a double using a UNumberFormat.
490 * The string will be parsed according to the UNumberFormat's locale.
491 * @param fmt The formatter to use.
492 * @param text The text to parse.
493 * @param textLength The length of text, or -1 if null-terminated.
494 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
495 * to begin parsing. If not 0, on output the offset at which parsing ended.
496 * @param status A pointer to an UErrorCode to receive any errors
497 * @return The value of the parsed double
499 * @see unum_parseInt64
501 * @see unum_formatInt64
502 * @see unum_formatDouble
505 U_STABLE
double U_EXPORT2
506 unum_parseDouble( const UNumberFormat
* fmt
,
509 int32_t *parsePos
/* 0 = start */,
514 * Parse a number from a string into an unformatted numeric string using a UNumberFormat.
515 * The input string will be parsed according to the UNumberFormat's locale.
516 * The syntax of the output is a "numeric string"
517 * as defined in the Decimal Arithmetic Specification, available at
518 * http://speleotrove.com/decimal
519 * @param fmt The formatter to use.
520 * @param text The text to parse.
521 * @param textLength The length of text, or -1 if null-terminated.
522 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
523 * to begin parsing. If not 0, on output the offset at which parsing ended.
524 * @param outBuf A (char *) buffer to receive the parsed number as a string. The output string
525 * will be nul-terminated if there is sufficient space.
526 * @param outBufLength The size of the output buffer. May be zero, in which case
527 * the outBuf pointer may be NULL, and the function will return the
528 * size of the output string.
529 * @param status A pointer to an UErrorCode to receive any errors
530 * @return the length of the output string, not including any terminating nul.
532 * @see unum_parseInt64
534 * @see unum_formatInt64
535 * @see unum_formatDouble
538 U_STABLE
int32_t U_EXPORT2
539 unum_parseDecimal(const UNumberFormat
* fmt
,
542 int32_t *parsePos
/* 0 = start */,
544 int32_t outBufLength
,
548 * Parse a string into a double and a currency using a UNumberFormat.
549 * The string will be parsed according to the UNumberFormat's locale.
550 * @param fmt the formatter to use
551 * @param text the text to parse
552 * @param textLength the length of text, or -1 if null-terminated
553 * @param parsePos a pointer to an offset index into text at which to
554 * begin parsing. On output, *parsePos will point after the last
555 * parsed character. This parameter may be 0, in which case parsing
556 * begins at offset 0.
557 * @param currency a pointer to the buffer to receive the parsed null-
558 * terminated currency. This buffer must have a capacity of at least
560 * @param status a pointer to an input-output UErrorCode
561 * @return the parsed double
562 * @see unum_parseDouble
563 * @see unum_formatDoubleCurrency
566 U_STABLE
double U_EXPORT2
567 unum_parseDoubleCurrency(const UNumberFormat
* fmt
,
570 int32_t* parsePos
, /* 0 = start */
575 * Set the pattern used by a UNumberFormat. This can only be used
576 * on a DecimalFormat, other formats return U_ILLEGAL_ARGUMENT_ERROR
578 * @param format The formatter to set.
579 * @param localized TRUE if the pattern is localized, FALSE otherwise.
580 * @param pattern The new pattern
581 * @param patternLength The length of pattern, or -1 if null-terminated.
582 * @param parseError A pointer to UParseError to recieve information
583 * about errors occurred during parsing, or NULL if no parse error
584 * information is desired.
585 * @param status A pointer to an input-output UErrorCode.
586 * @see unum_toPattern
590 U_STABLE
void U_EXPORT2
591 unum_applyPattern( UNumberFormat
*format
,
593 const UChar
*pattern
,
594 int32_t patternLength
,
595 UParseError
*parseError
,
600 * Get a locale for which decimal formatting patterns are available.
601 * A UNumberFormat in a locale returned by this function will perform the correct
602 * formatting and parsing for the locale. The results of this call are not
603 * valid for rule-based number formats.
604 * @param localeIndex The index of the desired locale.
605 * @return A locale for which number formatting patterns are available, or 0 if none.
606 * @see unum_countAvailable
609 U_STABLE
const char* U_EXPORT2
610 unum_getAvailable(int32_t localeIndex
);
613 * Determine how many locales have decimal formatting patterns available. The
614 * results of this call are not valid for rule-based number formats.
615 * This function is useful for determining the loop ending condition for
616 * calls to {@link #unum_getAvailable }.
617 * @return The number of locales for which decimal formatting patterns are available.
618 * @see unum_getAvailable
621 U_STABLE
int32_t U_EXPORT2
622 unum_countAvailable(void);
624 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
625 typedef enum UNumberFormatAttribute
{
626 /** Parse integers only */
628 /** Use grouping separator */
630 /** Always show decimal point */
631 UNUM_DECIMAL_ALWAYS_SHOWN
,
632 /** Maximum integer digits */
633 UNUM_MAX_INTEGER_DIGITS
,
634 /** Minimum integer digits */
635 UNUM_MIN_INTEGER_DIGITS
,
636 /** Integer digits */
638 /** Maximum fraction digits */
639 UNUM_MAX_FRACTION_DIGITS
,
640 /** Minimum fraction digits */
641 UNUM_MIN_FRACTION_DIGITS
,
642 /** Fraction digits */
643 UNUM_FRACTION_DIGITS
,
650 /** Rounding increment */
651 UNUM_ROUNDING_INCREMENT
,
652 /** The width to which the output of <code>format()</code> is padded. */
654 /** The position at which padding will take place. */
655 UNUM_PADDING_POSITION
,
656 /** Secondary grouping size */
657 UNUM_SECONDARY_GROUPING_SIZE
,
658 /** Use significant digits
660 UNUM_SIGNIFICANT_DIGITS_USED
,
661 /** Minimum significant digits
663 UNUM_MIN_SIGNIFICANT_DIGITS
,
664 /** Maximum significant digits
666 UNUM_MAX_SIGNIFICANT_DIGITS
,
667 /** Lenient parse mode used by rule-based formats.
671 } UNumberFormatAttribute
;
674 * Get a numeric attribute associated with a UNumberFormat.
675 * An example of a numeric attribute is the number of integer digits a formatter will produce.
676 * @param fmt The formatter to query.
677 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
678 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
679 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
680 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE.
681 * @return The value of attr.
682 * @see unum_setAttribute
683 * @see unum_getDoubleAttribute
684 * @see unum_setDoubleAttribute
685 * @see unum_getTextAttribute
686 * @see unum_setTextAttribute
689 U_STABLE
int32_t U_EXPORT2
690 unum_getAttribute(const UNumberFormat
* fmt
,
691 UNumberFormatAttribute attr
);
694 * Set a numeric attribute associated with a UNumberFormat.
695 * An example of a numeric attribute is the number of integer digits a formatter will produce. If the
696 * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
697 * the lenient-parse attribute.
698 * @param fmt The formatter to set.
699 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
700 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
701 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
702 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
703 * or UNUM_LENIENT_PARSE.
704 * @param newValue The new value of attr.
705 * @see unum_getAttribute
706 * @see unum_getDoubleAttribute
707 * @see unum_setDoubleAttribute
708 * @see unum_getTextAttribute
709 * @see unum_setTextAttribute
712 U_STABLE
void U_EXPORT2
713 unum_setAttribute( UNumberFormat
* fmt
,
714 UNumberFormatAttribute attr
,
719 * Get a numeric attribute associated with a UNumberFormat.
720 * An example of a numeric attribute is the number of integer digits a formatter will produce.
721 * If the formatter does not understand the attribute, -1 is returned.
722 * @param fmt The formatter to query.
723 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
724 * @return The value of attr.
725 * @see unum_getAttribute
726 * @see unum_setAttribute
727 * @see unum_setDoubleAttribute
728 * @see unum_getTextAttribute
729 * @see unum_setTextAttribute
732 U_STABLE
double U_EXPORT2
733 unum_getDoubleAttribute(const UNumberFormat
* fmt
,
734 UNumberFormatAttribute attr
);
737 * Set a numeric attribute associated with a UNumberFormat.
738 * An example of a numeric attribute is the number of integer digits a formatter will produce.
739 * If the formatter does not understand the attribute, this call is ignored.
740 * @param fmt The formatter to set.
741 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
742 * @param newValue The new value of attr.
743 * @see unum_getAttribute
744 * @see unum_setAttribute
745 * @see unum_getDoubleAttribute
746 * @see unum_getTextAttribute
747 * @see unum_setTextAttribute
750 U_STABLE
void U_EXPORT2
751 unum_setDoubleAttribute( UNumberFormat
* fmt
,
752 UNumberFormatAttribute attr
,
755 /** The possible UNumberFormat text attributes @stable ICU 2.0*/
756 typedef enum UNumberFormatTextAttribute
{
757 /** Positive prefix */
758 UNUM_POSITIVE_PREFIX
,
759 /** Positive suffix */
760 UNUM_POSITIVE_SUFFIX
,
761 /** Negative prefix */
762 UNUM_NEGATIVE_PREFIX
,
763 /** Negative suffix */
764 UNUM_NEGATIVE_SUFFIX
,
765 /** The character used to pad to the format width. */
766 UNUM_PADDING_CHARACTER
,
767 /** The ISO currency code */
770 * The default rule set. This is only available with rule-based formatters.
773 UNUM_DEFAULT_RULESET
,
775 * The public rule sets. This is only available with rule-based formatters.
776 * This is a read-only attribute. The public rulesets are returned as a
777 * single string, with each ruleset name delimited by ';' (semicolon).
781 } UNumberFormatTextAttribute
;
784 * Get a text attribute associated with a UNumberFormat.
785 * An example of a text attribute is the suffix for positive numbers. If the formatter
786 * does not understand the attributre, U_UNSUPPORTED_ERROR is returned as the status.
787 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
788 * @param fmt The formatter to query.
789 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
790 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
791 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
792 * @param result A pointer to a buffer to receive the attribute.
793 * @param resultLength The maximum size of result.
794 * @param status A pointer to an UErrorCode to receive any errors
795 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
796 * @see unum_setTextAttribute
797 * @see unum_getAttribute
798 * @see unum_setAttribute
801 U_STABLE
int32_t U_EXPORT2
802 unum_getTextAttribute( const UNumberFormat
* fmt
,
803 UNumberFormatTextAttribute tag
,
805 int32_t resultLength
,
809 * Set a text attribute associated with a UNumberFormat.
810 * An example of a text attribute is the suffix for positive numbers. Rule-based formatters
811 * only understand UNUM_DEFAULT_RULESET.
812 * @param fmt The formatter to set.
813 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
814 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
815 * or UNUM_DEFAULT_RULESET.
816 * @param newValue The new value of attr.
817 * @param newValueLength The length of newValue, or -1 if null-terminated.
818 * @param status A pointer to an UErrorCode to receive any errors
819 * @see unum_getTextAttribute
820 * @see unum_getAttribute
821 * @see unum_setAttribute
824 U_STABLE
void U_EXPORT2
825 unum_setTextAttribute( UNumberFormat
* fmt
,
826 UNumberFormatTextAttribute tag
,
827 const UChar
* newValue
,
828 int32_t newValueLength
,
832 * Extract the pattern from a UNumberFormat. The pattern will follow
833 * the DecimalFormat pattern syntax.
834 * @param fmt The formatter to query.
835 * @param isPatternLocalized TRUE if the pattern should be localized,
836 * FALSE otherwise. This is ignored if the formatter is a rule-based
838 * @param result A pointer to a buffer to receive the pattern.
839 * @param resultLength The maximum size of result.
840 * @param status A pointer to an input-output UErrorCode.
841 * @return The total buffer size needed; if greater than resultLength,
842 * the output was truncated.
843 * @see unum_applyPattern
847 U_STABLE
int32_t U_EXPORT2
848 unum_toPattern( const UNumberFormat
* fmt
,
849 UBool isPatternLocalized
,
851 int32_t resultLength
,
856 * Constants for specifying a number format symbol.
859 typedef enum UNumberFormatSymbol
{
860 /** The decimal separator */
861 UNUM_DECIMAL_SEPARATOR_SYMBOL
= 0,
862 /** The grouping separator */
863 UNUM_GROUPING_SEPARATOR_SYMBOL
= 1,
864 /** The pattern separator */
865 UNUM_PATTERN_SEPARATOR_SYMBOL
= 2,
866 /** The percent sign */
867 UNUM_PERCENT_SYMBOL
= 3,
869 UNUM_ZERO_DIGIT_SYMBOL
= 4,
870 /** Character representing a digit in the pattern */
871 UNUM_DIGIT_SYMBOL
= 5,
872 /** The minus sign */
873 UNUM_MINUS_SIGN_SYMBOL
= 6,
875 UNUM_PLUS_SIGN_SYMBOL
= 7,
876 /** The currency symbol */
877 UNUM_CURRENCY_SYMBOL
= 8,
878 /** The international currency symbol */
879 UNUM_INTL_CURRENCY_SYMBOL
= 9,
880 /** The monetary separator */
881 UNUM_MONETARY_SEPARATOR_SYMBOL
= 10,
882 /** The exponential symbol */
883 UNUM_EXPONENTIAL_SYMBOL
= 11,
884 /** Per mill symbol */
885 UNUM_PERMILL_SYMBOL
= 12,
886 /** Escape padding character */
887 UNUM_PAD_ESCAPE_SYMBOL
= 13,
888 /** Infinity symbol */
889 UNUM_INFINITY_SYMBOL
= 14,
891 UNUM_NAN_SYMBOL
= 15,
892 /** Significant digit symbol
894 UNUM_SIGNIFICANT_DIGIT_SYMBOL
= 16,
895 /** The monetary grouping separator
898 UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL
= 17,
902 UNUM_ONE_DIGIT_SYMBOL
= 18,
906 UNUM_TWO_DIGIT_SYMBOL
= 19,
910 UNUM_THREE_DIGIT_SYMBOL
= 20,
914 UNUM_FOUR_DIGIT_SYMBOL
= 21,
918 UNUM_FIVE_DIGIT_SYMBOL
= 22,
922 UNUM_SIX_DIGIT_SYMBOL
= 23,
926 UNUM_SEVEN_DIGIT_SYMBOL
= 24,
930 UNUM_EIGHT_DIGIT_SYMBOL
= 25,
934 UNUM_NINE_DIGIT_SYMBOL
= 26,
935 /** count symbol constants */
936 UNUM_FORMAT_SYMBOL_COUNT
= 27
937 } UNumberFormatSymbol
;
940 * Get a symbol associated with a UNumberFormat.
941 * A UNumberFormat uses symbols to represent the special locale-dependent
942 * characters in a number, for example the percent sign. This API is not
943 * supported for rule-based formatters.
944 * @param fmt The formatter to query.
945 * @param symbol The UNumberFormatSymbol constant for the symbol to get
946 * @param buffer The string buffer that will receive the symbol string;
947 * if it is NULL, then only the length of the symbol is returned
948 * @param size The size of the string buffer
949 * @param status A pointer to an UErrorCode to receive any errors
950 * @return The length of the symbol; the buffer is not modified if
951 * <code>length>=size</code>
952 * @see unum_setSymbol
955 U_STABLE
int32_t U_EXPORT2
956 unum_getSymbol(const UNumberFormat
*fmt
,
957 UNumberFormatSymbol symbol
,
963 * Set a symbol associated with a UNumberFormat.
964 * A UNumberFormat uses symbols to represent the special locale-dependent
965 * characters in a number, for example the percent sign. This API is not
966 * supported for rule-based formatters.
967 * @param fmt The formatter to set.
968 * @param symbol The UNumberFormatSymbol constant for the symbol to set
969 * @param value The string to set the symbol to
970 * @param length The length of the string, or -1 for a zero-terminated string
971 * @param status A pointer to an UErrorCode to receive any errors.
972 * @see unum_getSymbol
975 U_STABLE
void U_EXPORT2
976 unum_setSymbol(UNumberFormat
*fmt
,
977 UNumberFormatSymbol symbol
,
984 * Get the locale for this number format object.
985 * You can choose between valid and actual locale.
986 * @param fmt The formatter to get the locale from
987 * @param type type of the locale we're looking for (valid or actual)
988 * @param status error code for the operation
989 * @return the locale name
992 U_STABLE
const char* U_EXPORT2
993 unum_getLocaleByType(const UNumberFormat
*fmt
,
994 ULocDataLocaleType type
,
997 #endif /* #if !UCONFIG_NO_FORMATTING */