2 *******************************************************************************
3 * Copyright (C) 1997-2008, 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/uloc.h"
20 #include "unicode/umisc.h"
21 #include "unicode/parseerr.h"
24 * \brief C API: NumberFormat
26 * <h2> Number Format C API </h2>
28 * Number Format C API Provides functions for
29 * formatting and parsing a number. Also provides methods for
30 * determining which locales have number formats, and what their names
33 * UNumberFormat helps you to format and parse numbers for any locale.
34 * Your code can be completely independent of the locale conventions
35 * for decimal points, thousands-separators, or even the particular
36 * decimal digits used, or whether the number format is even decimal.
37 * There are different number format styles like decimal, currency,
38 * percent and spellout.
40 * To format a number for the current Locale, use one of the static
45 * double myNumber = 7.0;
46 * UErrorCode status = U_ZERO_ERROR;
47 * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
48 * unum_formatDouble(nf, myNumber, myString, 20, NULL, &status);
49 * printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)
52 * If you are formatting multiple numbers, it is more efficient to get
53 * the format and use it multiple times so that the system doesn't
54 * have to fetch the information about the local language and country
55 * conventions multiple times.
58 * uint32_t i, resultlength, reslenneeded;
59 * UErrorCode status = U_ZERO_ERROR;
61 * uint32_t a[] = { 123, 3333, -1234567 };
62 * const uint32_t a_len = sizeof(a) / sizeof(a[0]);
64 * UChar* result = NULL;
66 * nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
67 * for (i = 0; i < a_len; i++) {
69 * reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
71 * if(status==U_BUFFER_OVERFLOW_ERROR){
72 * status=U_ZERO_ERROR;
73 * resultlength=reslenneeded+1;
74 * result=(UChar*)malloc(sizeof(UChar) * resultlength);
75 * unum_format(nf, a[i], result, resultlength, &pos, &status);
77 * printf( " Example 2: %s\n", austrdup(result));
82 * To format a number for a different Locale, specify it in the
83 * call to unum_open().
86 * UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)
89 * You can use a NumberFormat API unum_parse() to parse.
92 * UErrorCode status = U_ZERO_ERROR;
95 * num = unum_parse(nf, str, u_strlen(str), &pos, &status);
98 * Use UNUM_DECIMAL to get the normal number format for that country.
99 * There are other static options available. Use UNUM_CURRENCY
100 * to get the currency number format for that country. Use UNUM_PERCENT
101 * to get a format for displaying percentages. With this format, a
102 * fraction from 0.53 is displayed as 53%.
104 * Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat
105 * formatter. The pattern must conform to the syntax defined for those
108 * You can also control the display of numbers with such function as
109 * unum_getAttribues() and unum_setAtributes(), which let you set the
110 * miminum fraction digits, grouping, etc.
111 * @see UNumberFormatAttributes for more details
113 * You can also use forms of the parse and format methods with
114 * ParsePosition and UFieldPosition to allow you to:
116 * <li>(a) progressively parse through pieces of a string.
117 * <li>(b) align the decimal point and other areas.
120 * It is also possible to change or set the symbols used for a particular
121 * locale like the currency symbol, the grouping seperator , monetary seperator
122 * etc by making use of functions unum_setSymbols() and unum_getSymbols().
125 /** A number formatter.
126 * For usage in C programs.
129 typedef void* UNumberFormat
;
131 /** The possible number format styles.
134 typedef enum UNumberFormatStyle
{
136 * Decimal format defined by pattern
139 UNUM_PATTERN_DECIMAL
=0,
140 /** Decimal format */
142 /** Currency format */
144 /** Percent format */
146 /** Scientific format */
148 /** Spellout rule-based format */
151 * Ordinal rule-based format
156 * Duration rule-based format
161 * Rule-based format defined by pattern
164 UNUM_PATTERN_RULEBASED
,
165 /** Default format */
166 UNUM_DEFAULT
= UNUM_DECIMAL
,
167 /** (Alias for UNUM_PATTERN_DECIMAL) */
168 UNUM_IGNORE
= UNUM_PATTERN_DECIMAL
169 } UNumberFormatStyle
;
171 /** The possible number format rounding modes.
174 typedef enum UNumberFormatRoundingMode
{
180 * Half-even rounding, misspelled name
181 * @deprecated, ICU 3.8
190 UNUM_ROUND_HALFEVEN
= UNUM_FOUND_HALFEVEN
191 } UNumberFormatRoundingMode
;
193 /** The possible number format pad positions.
196 typedef enum UNumberFormatPadPosition
{
197 UNUM_PAD_BEFORE_PREFIX
,
198 UNUM_PAD_AFTER_PREFIX
,
199 UNUM_PAD_BEFORE_SUFFIX
,
200 UNUM_PAD_AFTER_SUFFIX
201 } UNumberFormatPadPosition
;
204 * Create and return a new UNumberFormat for formatting and parsing
205 * numbers. A UNumberFormat may be used to format numbers by calling
206 * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
207 * The caller must call {@link #unum_close } when done to release resources
208 * used by this object.
209 * @param style The type of number format to open: one of
210 * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC, UNUM_SPELLOUT,
211 * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
212 * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
213 * number format is opened using the given pattern, which must conform
214 * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
216 * @param pattern A pattern specifying the format to use.
217 * This parameter is ignored unless the style is
218 * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
219 * @param patternLength The number of characters in the pattern, or -1
220 * if null-terminated. This parameter is ignored unless the style is
222 * @param locale A locale identifier to use to determine formatting
223 * and parsing conventions, or NULL to use the default locale.
224 * @param parseErr A pointer to a UParseError struct to receive the
225 * details of any parsing errors, or NULL if no parsing error details
227 * @param status A pointer to an input-output UErrorCode.
228 * @return A pointer to a newly created UNumberFormat, or NULL if an
234 U_STABLE UNumberFormat
* U_EXPORT2
235 unum_open( UNumberFormatStyle style
,
236 const UChar
* pattern
,
237 int32_t patternLength
,
239 UParseError
* parseErr
,
244 * Close a UNumberFormat.
245 * Once closed, a UNumberFormat may no longer be used.
246 * @param fmt The formatter to close.
249 U_STABLE
void U_EXPORT2
250 unum_close(UNumberFormat
* fmt
);
253 * Open a copy of a UNumberFormat.
254 * This function performs a deep copy.
255 * @param fmt The format to copy
256 * @param status A pointer to an UErrorCode to receive any errors.
257 * @return A pointer to a UNumberFormat identical to fmt.
260 U_STABLE UNumberFormat
* U_EXPORT2
261 unum_clone(const UNumberFormat
*fmt
,
265 * Format an integer using a UNumberFormat.
266 * The integer will be formatted according to the UNumberFormat's locale.
267 * @param fmt The formatter to use.
268 * @param number The number to format.
269 * @param result A pointer to a buffer to receive the formatted number.
270 * @param resultLength The maximum size of result.
271 * @param pos A pointer to a UFieldPosition. On input, position->field
272 * is read. On output, position->beginIndex and position->endIndex indicate
273 * the beginning and ending indices of field number position->field, if such
274 * a field exists. This parameter may be NULL, in which case no field
275 * @param status A pointer to an UErrorCode to receive any errors
276 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
277 * @see unum_formatInt64
278 * @see unum_formatDouble
280 * @see unum_parseInt64
281 * @see unum_parseDouble
282 * @see UFieldPosition
285 U_STABLE
int32_t U_EXPORT2
286 unum_format( const UNumberFormat
* fmt
,
289 int32_t resultLength
,
294 * Format an int64 using a UNumberFormat.
295 * The int64 will be formatted according to the UNumberFormat's locale.
296 * @param fmt The formatter to use.
297 * @param number The number to format.
298 * @param result A pointer to a buffer to receive the formatted number.
299 * @param resultLength The maximum size of result.
300 * @param pos A pointer to a UFieldPosition. On input, position->field
301 * is read. On output, position->beginIndex and position->endIndex indicate
302 * the beginning and ending indices of field number position->field, if such
303 * a field exists. This parameter may be NULL, in which case no field
304 * @param status A pointer to an UErrorCode to receive any errors
305 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
307 * @see unum_formatDouble
309 * @see unum_parseInt64
310 * @see unum_parseDouble
311 * @see UFieldPosition
314 U_STABLE
int32_t U_EXPORT2
315 unum_formatInt64(const UNumberFormat
*fmt
,
318 int32_t resultLength
,
323 * Format a double using a UNumberFormat.
324 * The double will be formatted according to the UNumberFormat's locale.
325 * @param fmt The formatter to use.
326 * @param number The number to format.
327 * @param result A pointer to a buffer to receive the formatted number.
328 * @param resultLength The maximum size of result.
329 * @param pos A pointer to a UFieldPosition. On input, position->field
330 * is read. On output, position->beginIndex and position->endIndex indicate
331 * the beginning and ending indices of field number position->field, if such
332 * a field exists. This parameter may be NULL, in which case no field
333 * @param status A pointer to an UErrorCode to receive any errors
334 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
336 * @see unum_formatInt64
338 * @see unum_parseInt64
339 * @see unum_parseDouble
340 * @see UFieldPosition
343 U_STABLE
int32_t U_EXPORT2
344 unum_formatDouble( const UNumberFormat
* fmt
,
347 int32_t resultLength
,
348 UFieldPosition
*pos
, /* 0 if ignore */
352 * Format a double currency amount using a UNumberFormat.
353 * The double will be formatted according to the UNumberFormat's locale.
354 * @param fmt the formatter to use
355 * @param number the number to format
356 * @param currency the 3-letter null-terminated ISO 4217 currency code
357 * @param result a pointer to the buffer to receive the formatted number
358 * @param resultLength the maximum number of UChars to write to result
359 * @param pos a pointer to a UFieldPosition. On input,
360 * position->field is read. On output, position->beginIndex and
361 * position->endIndex indicate the beginning and ending indices of
362 * field number position->field, if such a field exists. This
363 * parameter may be NULL, in which case it is ignored.
364 * @param status a pointer to an input-output UErrorCode
365 * @return the total buffer size needed; if greater than resultLength,
366 * the output was truncated.
367 * @see unum_formatDouble
368 * @see unum_parseDoubleCurrency
369 * @see UFieldPosition
372 U_STABLE
int32_t U_EXPORT2
373 unum_formatDoubleCurrency(const UNumberFormat
* fmt
,
377 int32_t resultLength
,
378 UFieldPosition
* pos
, /* ignored if 0 */
382 * Parse a string into an integer using a UNumberFormat.
383 * The string will be parsed according to the UNumberFormat's locale.
384 * @param fmt The formatter to use.
385 * @param text The text to parse.
386 * @param textLength The length of text, or -1 if null-terminated.
387 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
388 * to begin parsing. If not 0, on output the offset at which parsing ended.
389 * @param status A pointer to an UErrorCode to receive any errors
390 * @return The value of the parsed integer
391 * @see unum_parseInt64
392 * @see unum_parseDouble
394 * @see unum_formatInt64
395 * @see unum_formatDouble
398 U_STABLE
int32_t U_EXPORT2
399 unum_parse( const UNumberFormat
* fmt
,
402 int32_t *parsePos
/* 0 = start */,
406 * Parse a string into an int64 using a UNumberFormat.
407 * The string will be parsed according to the UNumberFormat's locale.
408 * @param fmt The formatter to use.
409 * @param text The text to parse.
410 * @param textLength The length of text, or -1 if null-terminated.
411 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
412 * to begin parsing. If not 0, on output the offset at which parsing ended.
413 * @param status A pointer to an UErrorCode to receive any errors
414 * @return The value of the parsed integer
416 * @see unum_parseDouble
418 * @see unum_formatInt64
419 * @see unum_formatDouble
422 U_STABLE
int64_t U_EXPORT2
423 unum_parseInt64(const UNumberFormat
* fmt
,
426 int32_t *parsePos
/* 0 = start */,
430 * Parse a string into a double using a UNumberFormat.
431 * The string will be parsed according to the UNumberFormat's locale.
432 * @param fmt The formatter to use.
433 * @param text The text to parse.
434 * @param textLength The length of text, or -1 if null-terminated.
435 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
436 * to begin parsing. If not 0, on output the offset at which parsing ended.
437 * @param status A pointer to an UErrorCode to receive any errors
438 * @return The value of the parsed double
440 * @see unum_parseInt64
442 * @see unum_formatInt64
443 * @see unum_formatDouble
446 U_STABLE
double U_EXPORT2
447 unum_parseDouble( const UNumberFormat
* fmt
,
450 int32_t *parsePos
/* 0 = start */,
454 * Parse a string into a double and a currency using a UNumberFormat.
455 * The string will be parsed according to the UNumberFormat's locale.
456 * @param fmt the formatter to use
457 * @param text the text to parse
458 * @param textLength the length of text, or -1 if null-terminated
459 * @param parsePos a pointer to an offset index into text at which to
460 * begin parsing. On output, *parsePos will point after the last
461 * parsed character. This parameter may be 0, in which case parsing
462 * begins at offset 0.
463 * @param currency a pointer to the buffer to receive the parsed null-
464 * terminated currency. This buffer must have a capacity of at least
466 * @param status a pointer to an input-output UErrorCode
467 * @return the parsed double
468 * @see unum_parseDouble
469 * @see unum_formatDoubleCurrency
472 U_STABLE
double U_EXPORT2
473 unum_parseDoubleCurrency(const UNumberFormat
* fmt
,
476 int32_t* parsePos
, /* 0 = start */
481 * Set the pattern used by a UNumberFormat. This can only be used
482 * on a DecimalFormat, other formats return U_ILLEGAL_ARGUMENT_ERROR
484 * @param format The formatter to set.
485 * @param localized TRUE if the pattern is localized, FALSE otherwise.
486 * @param pattern The new pattern
487 * @param patternLength The length of pattern, or -1 if null-terminated.
488 * @param parseError A pointer to UParseError to recieve information
489 * about errors occurred during parsing, or NULL if no parse error
490 * information is desired.
491 * @param status A pointer to an input-output UErrorCode.
492 * @see unum_toPattern
496 U_STABLE
void U_EXPORT2
497 unum_applyPattern( UNumberFormat
*format
,
499 const UChar
*pattern
,
500 int32_t patternLength
,
501 UParseError
*parseError
,
506 * Get a locale for which decimal formatting patterns are available.
507 * A UNumberFormat in a locale returned by this function will perform the correct
508 * formatting and parsing for the locale. The results of this call are not
509 * valid for rule-based number formats.
510 * @param index The index of the desired locale.
511 * @return A locale for which number formatting patterns are available, or 0 if none.
512 * @see unum_countAvailable
515 U_STABLE
const char* U_EXPORT2
516 unum_getAvailable(int32_t index
);
519 * Determine how many locales have decimal formatting patterns available. The
520 * results of this call are not valid for rule-based number formats.
521 * This function is useful for determining the loop ending condition for
522 * calls to {@link #unum_getAvailable }.
523 * @return The number of locales for which decimal formatting patterns are available.
524 * @see unum_getAvailable
527 U_STABLE
int32_t U_EXPORT2
528 unum_countAvailable(void);
530 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
531 typedef enum UNumberFormatAttribute
{
532 /** Parse integers only */
534 /** Use grouping separator */
536 /** Always show decimal point */
537 UNUM_DECIMAL_ALWAYS_SHOWN
,
538 /** Maximum integer digits */
539 UNUM_MAX_INTEGER_DIGITS
,
540 /** Minimum integer digits */
541 UNUM_MIN_INTEGER_DIGITS
,
542 /** Integer digits */
544 /** Maximum fraction digits */
545 UNUM_MAX_FRACTION_DIGITS
,
546 /** Minimum fraction digits */
547 UNUM_MIN_FRACTION_DIGITS
,
548 /** Fraction digits */
549 UNUM_FRACTION_DIGITS
,
556 /** Rounding increment */
557 UNUM_ROUNDING_INCREMENT
,
558 /** The width to which the output of <code>format()</code> is padded. */
560 /** The position at which padding will take place. */
561 UNUM_PADDING_POSITION
,
562 /** Secondary grouping size */
563 UNUM_SECONDARY_GROUPING_SIZE
,
564 /** Use significant digits
566 UNUM_SIGNIFICANT_DIGITS_USED
,
567 /** Minimum significant digits
569 UNUM_MIN_SIGNIFICANT_DIGITS
,
570 /** Maximum significant digits
572 UNUM_MAX_SIGNIFICANT_DIGITS
,
573 /** Lenient parse mode used by rule-based formats.
577 } UNumberFormatAttribute
;
580 * Get a numeric attribute associated with a UNumberFormat.
581 * An example of a numeric attribute is the number of integer digits a formatter will produce.
582 * @param fmt The formatter to query.
583 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
584 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
585 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
586 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE.
587 * @return The value of attr.
588 * @see unum_setAttribute
589 * @see unum_getDoubleAttribute
590 * @see unum_setDoubleAttribute
591 * @see unum_getTextAttribute
592 * @see unum_setTextAttribute
595 U_STABLE
int32_t U_EXPORT2
596 unum_getAttribute(const UNumberFormat
* fmt
,
597 UNumberFormatAttribute attr
);
600 * Set a numeric attribute associated with a UNumberFormat.
601 * An example of a numeric attribute is the number of integer digits a formatter will produce. If the
602 * formatter does not understand the attribute, the call is ignored. Rule-based formatters only understand
603 * the lenient-parse attribute.
604 * @param fmt The formatter to set.
605 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
606 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
607 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
608 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
609 * or UNUM_LENIENT_PARSE.
610 * @param newValue The new value of attr.
611 * @see unum_getAttribute
612 * @see unum_getDoubleAttribute
613 * @see unum_setDoubleAttribute
614 * @see unum_getTextAttribute
615 * @see unum_setTextAttribute
618 U_STABLE
void U_EXPORT2
619 unum_setAttribute( UNumberFormat
* fmt
,
620 UNumberFormatAttribute attr
,
625 * Get a numeric attribute associated with a UNumberFormat.
626 * An example of a numeric attribute is the number of integer digits a formatter will produce.
627 * If the formatter does not understand the attribute, -1 is returned.
628 * @param fmt The formatter to query.
629 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
630 * @return The value of attr.
631 * @see unum_getAttribute
632 * @see unum_setAttribute
633 * @see unum_setDoubleAttribute
634 * @see unum_getTextAttribute
635 * @see unum_setTextAttribute
638 U_STABLE
double U_EXPORT2
639 unum_getDoubleAttribute(const UNumberFormat
* fmt
,
640 UNumberFormatAttribute attr
);
643 * Set a numeric attribute associated with a UNumberFormat.
644 * An example of a numeric attribute is the number of integer digits a formatter will produce.
645 * If the formatter does not understand the attribute, this call is ignored.
646 * @param fmt The formatter to set.
647 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
648 * @param newValue The new value of attr.
649 * @see unum_getAttribute
650 * @see unum_setAttribute
651 * @see unum_getDoubleAttribute
652 * @see unum_getTextAttribute
653 * @see unum_setTextAttribute
656 U_STABLE
void U_EXPORT2
657 unum_setDoubleAttribute( UNumberFormat
* fmt
,
658 UNumberFormatAttribute attr
,
661 /** The possible UNumberFormat text attributes @stable ICU 2.0*/
662 typedef enum UNumberFormatTextAttribute
{
663 /** Positive prefix */
664 UNUM_POSITIVE_PREFIX
,
665 /** Positive suffix */
666 UNUM_POSITIVE_SUFFIX
,
667 /** Negative prefix */
668 UNUM_NEGATIVE_PREFIX
,
669 /** Negative suffix */
670 UNUM_NEGATIVE_SUFFIX
,
671 /** The character used to pad to the format width. */
672 UNUM_PADDING_CHARACTER
,
673 /** The ISO currency code */
676 * The default rule set. This is only available with rule-based formatters.
679 UNUM_DEFAULT_RULESET
,
681 * The public rule sets. This is only available with rule-based formatters.
682 * This is a read-only attribute. The public rulesets are returned as a
683 * single string, with each ruleset name delimited by ';' (semicolon).
687 } UNumberFormatTextAttribute
;
690 * Get a text attribute associated with a UNumberFormat.
691 * An example of a text attribute is the suffix for positive numbers. If the formatter
692 * does not understand the attributre, U_UNSUPPORTED_ERROR is returned as the status.
693 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
694 * @param fmt The formatter to query.
695 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
696 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
697 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
698 * @param result A pointer to a buffer to receive the attribute.
699 * @param resultLength The maximum size of result.
700 * @param status A pointer to an UErrorCode to receive any errors
701 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
702 * @see unum_setTextAttribute
703 * @see unum_getAttribute
704 * @see unum_setAttribute
707 U_STABLE
int32_t U_EXPORT2
708 unum_getTextAttribute( const UNumberFormat
* fmt
,
709 UNumberFormatTextAttribute tag
,
711 int32_t resultLength
,
715 * Set a text attribute associated with a UNumberFormat.
716 * An example of a text attribute is the suffix for positive numbers. Rule-based formatters
717 * only understand UNUM_DEFAULT_RULESET.
718 * @param fmt The formatter to set.
719 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
720 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
721 * or UNUM_DEFAULT_RULESET.
722 * @param newValue The new value of attr.
723 * @param newValueLength The length of newValue, or -1 if null-terminated.
724 * @param status A pointer to an UErrorCode to receive any errors
725 * @see unum_getTextAttribute
726 * @see unum_getAttribute
727 * @see unum_setAttribute
730 U_STABLE
void U_EXPORT2
731 unum_setTextAttribute( UNumberFormat
* fmt
,
732 UNumberFormatTextAttribute tag
,
733 const UChar
* newValue
,
734 int32_t newValueLength
,
738 * Extract the pattern from a UNumberFormat. The pattern will follow
739 * the DecimalFormat pattern syntax.
740 * @param fmt The formatter to query.
741 * @param isPatternLocalized TRUE if the pattern should be localized,
742 * FALSE otherwise. This is ignored if the formatter is a rule-based
744 * @param result A pointer to a buffer to receive the pattern.
745 * @param resultLength The maximum size of result.
746 * @param status A pointer to an input-output UErrorCode.
747 * @return The total buffer size needed; if greater than resultLength,
748 * the output was truncated.
749 * @see unum_applyPattern
753 U_STABLE
int32_t U_EXPORT2
754 unum_toPattern( const UNumberFormat
* fmt
,
755 UBool isPatternLocalized
,
757 int32_t resultLength
,
762 * Constants for specifying a number format symbol.
765 typedef enum UNumberFormatSymbol
{
766 /** The decimal separator */
767 UNUM_DECIMAL_SEPARATOR_SYMBOL
= 0,
768 /** The grouping separator */
769 UNUM_GROUPING_SEPARATOR_SYMBOL
= 1,
770 /** The pattern separator */
771 UNUM_PATTERN_SEPARATOR_SYMBOL
= 2,
772 /** The percent sign */
773 UNUM_PERCENT_SYMBOL
= 3,
775 UNUM_ZERO_DIGIT_SYMBOL
= 4,
776 /** Character representing a digit in the pattern */
777 UNUM_DIGIT_SYMBOL
= 5,
778 /** The minus sign */
779 UNUM_MINUS_SIGN_SYMBOL
= 6,
781 UNUM_PLUS_SIGN_SYMBOL
= 7,
782 /** The currency symbol */
783 UNUM_CURRENCY_SYMBOL
= 8,
784 /** The international currency symbol */
785 UNUM_INTL_CURRENCY_SYMBOL
= 9,
786 /** The monetary separator */
787 UNUM_MONETARY_SEPARATOR_SYMBOL
= 10,
788 /** The exponential symbol */
789 UNUM_EXPONENTIAL_SYMBOL
= 11,
790 /** Per mill symbol */
791 UNUM_PERMILL_SYMBOL
= 12,
792 /** Escape padding character */
793 UNUM_PAD_ESCAPE_SYMBOL
= 13,
794 /** Infinity symbol */
795 UNUM_INFINITY_SYMBOL
= 14,
797 UNUM_NAN_SYMBOL
= 15,
798 /** Significant digit symbol
800 UNUM_SIGNIFICANT_DIGIT_SYMBOL
= 16,
801 /** The monetary grouping separator
804 UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL
= 17,
805 /** count symbol constants */
806 UNUM_FORMAT_SYMBOL_COUNT
= 18
807 } UNumberFormatSymbol
;
810 * Get a symbol associated with a UNumberFormat.
811 * A UNumberFormat uses symbols to represent the special locale-dependent
812 * characters in a number, for example the percent sign. This API is not
813 * supported for rule-based formatters.
814 * @param fmt The formatter to query.
815 * @param symbol The UNumberFormatSymbol constant for the symbol to get
816 * @param buffer The string buffer that will receive the symbol string;
817 * if it is NULL, then only the length of the symbol is returned
818 * @param size The size of the string buffer
819 * @param status A pointer to an UErrorCode to receive any errors
820 * @return The length of the symbol; the buffer is not modified if
821 * <code>length>=size</code>
822 * @see unum_setSymbol
825 U_STABLE
int32_t U_EXPORT2
826 unum_getSymbol(const UNumberFormat
*fmt
,
827 UNumberFormatSymbol symbol
,
833 * Set a symbol associated with a UNumberFormat.
834 * A UNumberFormat uses symbols to represent the special locale-dependent
835 * characters in a number, for example the percent sign. This API is not
836 * supported for rule-based formatters.
837 * @param fmt The formatter to set.
838 * @param symbol The UNumberFormatSymbol constant for the symbol to set
839 * @param value The string to set the symbol to
840 * @param length The length of the string, or -1 for a zero-terminated string
841 * @param status A pointer to an UErrorCode to receive any errors.
842 * @see unum_getSymbol
845 U_STABLE
void U_EXPORT2
846 unum_setSymbol(UNumberFormat
*fmt
,
847 UNumberFormatSymbol symbol
,
854 * Get the locale for this number format object.
855 * You can choose between valid and actual locale.
856 * @param fmt The formatter to get the locale from
857 * @param type type of the locale we're looking for (valid or actual)
858 * @param status error code for the operation
859 * @return the locale name
862 U_STABLE
const char* U_EXPORT2
863 unum_getLocaleByType(const UNumberFormat
*fmt
,
864 ULocDataLocaleType type
,
867 #endif /* #if !UCONFIG_NO_FORMATTING */