• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
6 * All Rights Reserved.
7 * Modification History:
8 *
9 *   Date        Name        Description
10 *   06/24/99    helena      Integrated Alan's NF enhancements and Java2 bug fixes
11 *******************************************************************************
12 */
13 
14 #ifndef _UNUM
15 #define _UNUM
16 
17 #include "unicode/utypes.h"
18 
19 #if !UCONFIG_NO_FORMATTING
20 
21 #include "unicode/uloc.h"
22 #include "unicode/ucurr.h"
23 #include "unicode/umisc.h"
24 #include "unicode/parseerr.h"
25 #include "unicode/uformattable.h"
26 #include "unicode/udisplaycontext.h"
27 #include "unicode/ufieldpositer.h"
28 
29 #if U_SHOW_CPLUSPLUS_API
30 #include "unicode/localpointer.h"
31 #endif   // U_SHOW_CPLUSPLUS_API
32 
33 /**
34  * \file
35  * \brief C API: Compatibility APIs for number formatting.
36  *
37  * <h2> Number Format C API </h2>
38  *
39  * <p><strong>IMPORTANT:</strong> New users with are strongly encouraged to
40  * see if unumberformatter.h fits their use case.  Although not deprecated,
41  * this header is provided for backwards compatibility only.
42  *
43  * Number Format C API  Provides functions for
44  * formatting and parsing a number.  Also provides methods for
45  * determining which locales have number formats, and what their names
46  * are.
47  * <P>
48  * UNumberFormat helps you to format and parse numbers for any locale.
49  * Your code can be completely independent of the locale conventions
50  * for decimal points, thousands-separators, or even the particular
51  * decimal digits used, or whether the number format is even decimal.
52  * There are different number format styles like decimal, currency,
53  * percent and spellout.
54  * <P>
55  * To format a number for the current Locale, use one of the static
56  * factory methods:
57  * <pre>
58  * \code
59  *    UChar myString[20];
60  *    double myNumber = 7.0;
61  *    UErrorCode status = U_ZERO_ERROR;
62  *    UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
63  *    unum_formatDouble(nf, myNumber, myString, 20, NULL, &status);
64  *    printf(" Example 1: %s\n", austrdup(myString) ); //austrdup( a function used to convert UChar* to char*)
65  * \endcode
66  * </pre>
67  * If you are formatting multiple numbers, it is more efficient to get
68  * the format and use it multiple times so that the system doesn't
69  * have to fetch the information about the local language and country
70  * conventions multiple times.
71  * <pre>
72  * \code
73  * uint32_t i, resultlength, reslenneeded;
74  * UErrorCode status = U_ZERO_ERROR;
75  * UFieldPosition pos;
76  * uint32_t a[] = { 123, 3333, -1234567 };
77  * const uint32_t a_len = sizeof(a) / sizeof(a[0]);
78  * UNumberFormat* nf;
79  * UChar* result = NULL;
80  *
81  * nf = unum_open(UNUM_DEFAULT, NULL, -1, NULL, NULL, &status);
82  * for (i = 0; i < a_len; i++) {
83  *    resultlength=0;
84  *    reslenneeded=unum_format(nf, a[i], NULL, resultlength, &pos, &status);
85  *    result = NULL;
86  *    if(status==U_BUFFER_OVERFLOW_ERROR){
87  *       status=U_ZERO_ERROR;
88  *       resultlength=reslenneeded+1;
89  *       result=(UChar*)malloc(sizeof(UChar) * resultlength);
90  *       unum_format(nf, a[i], result, resultlength, &pos, &status);
91  *    }
92  *    printf( " Example 2: %s\n", austrdup(result));
93  *    free(result);
94  * }
95  * \endcode
96  * </pre>
97  * To format a number for a different Locale, specify it in the
98  * call to unum_open().
99  * <pre>
100  * \code
101  *     UNumberFormat* nf = unum_open(UNUM_DEFAULT, NULL, -1, "fr_FR", NULL, &success)
102  * \endcode
103  * </pre>
104  * You can use a NumberFormat API unum_parse() to parse.
105  * <pre>
106  * \code
107  *    UErrorCode status = U_ZERO_ERROR;
108  *    int32_t pos=0;
109  *    int32_t num;
110  *    num = unum_parse(nf, str, u_strlen(str), &pos, &status);
111  * \endcode
112  * </pre>
113  * Use UNUM_DECIMAL to get the normal number format for that country.
114  * There are other static options available.  Use UNUM_CURRENCY
115  * to get the currency number format for that country.  Use UNUM_PERCENT
116  * to get a format for displaying percentages. With this format, a
117  * fraction from 0.53 is displayed as 53%.
118  * <P>
119  * Use a pattern to create either a DecimalFormat or a RuleBasedNumberFormat
120  * formatter.  The pattern must conform to the syntax defined for those
121  * formatters.
122  * <P>
123  * You can also control the display of numbers with such function as
124  * unum_getAttributes() and unum_setAttributes(), which let you set the
125  * minimum fraction digits, grouping, etc.
126  * @see UNumberFormatAttributes for more details
127  * <P>
128  * You can also use forms of the parse and format methods with
129  * ParsePosition and UFieldPosition to allow you to:
130  * <ul type=round>
131  *   <li>(a) progressively parse through pieces of a string.
132  *   <li>(b) align the decimal point and other areas.
133  * </ul>
134  * <p>
135  * It is also possible to change or set the symbols used for a particular
136  * locale like the currency symbol, the grouping separator , monetary separator
137  * etc by making use of functions unum_setSymbols() and unum_getSymbols().
138  */
139 
140 /** A number formatter.
141  *  For usage in C programs.
142  *  @stable ICU 2.0
143  */
144 typedef void* UNumberFormat;
145 
146 /** The possible number format styles.
147  *  @stable ICU 2.0
148  */
149 typedef enum UNumberFormatStyle {
150     /**
151      * Decimal format defined by a pattern string.
152      * @stable ICU 3.0
153      */
154     UNUM_PATTERN_DECIMAL=0,
155     /**
156      * Decimal format ("normal" style).
157      * @stable ICU 2.0
158      */
159     UNUM_DECIMAL=1,
160     /**
161      * Currency format (generic).
162      * Defaults to UNUM_CURRENCY_STANDARD style
163      * (using currency symbol, e.g., "$1.00", with non-accounting
164      * style for negative values e.g. using minus sign).
165      * The specific style may be specified using the -cf- locale key.
166      * @stable ICU 2.0
167      */
168     UNUM_CURRENCY=2,
169     /**
170      * Percent format
171      * @stable ICU 2.0
172      */
173     UNUM_PERCENT=3,
174     /**
175      * Scientific format
176      * @stable ICU 2.1
177      */
178     UNUM_SCIENTIFIC=4,
179     /**
180      * Spellout rule-based format. The default ruleset can be specified/changed using
181      * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets
182      * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
183      * @stable ICU 2.0
184      */
185     UNUM_SPELLOUT=5,
186     /**
187      * Ordinal rule-based format . The default ruleset can be specified/changed using
188      * unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets
189      * can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
190      * @stable ICU 3.0
191      */
192     UNUM_ORDINAL=6,
193     /**
194      * Duration rule-based format
195      * @stable ICU 3.0
196      */
197     UNUM_DURATION=7,
198     /**
199      * Numbering system rule-based format
200      * @stable ICU 4.2
201      */
202     UNUM_NUMBERING_SYSTEM=8,
203     /**
204      * Rule-based format defined by a pattern string.
205      * @stable ICU 3.0
206      */
207     UNUM_PATTERN_RULEBASED=9,
208     /**
209      * Currency format with an ISO currency code, e.g., "USD1.00".
210      * @stable ICU 4.8
211      */
212     UNUM_CURRENCY_ISO=10,
213     /**
214      * Currency format with a pluralized currency name,
215      * e.g., "1.00 US dollar" and "3.00 US dollars".
216      * @stable ICU 4.8
217      */
218     UNUM_CURRENCY_PLURAL=11,
219     /**
220      * Currency format for accounting, e.g., "($3.00)" for
221      * negative currency amount instead of "-$3.00" ({@link #UNUM_CURRENCY}).
222      * Overrides any style specified using -cf- key in locale.
223      * @stable ICU 53
224      */
225     UNUM_CURRENCY_ACCOUNTING=12,
226     /**
227      * Currency format with a currency symbol given CASH usage, e.g.,
228      * "NT$3" instead of "NT$3.23".
229      * @stable ICU 54
230      */
231     UNUM_CASH_CURRENCY=13,
232     /**
233      * Decimal format expressed using compact notation
234      * (short form, corresponds to UNumberCompactStyle=UNUM_SHORT)
235      * e.g. "23K", "45B"
236      * @stable ICU 56
237      */
238     UNUM_DECIMAL_COMPACT_SHORT=14,
239     /**
240      * Decimal format expressed using compact notation
241      * (long form, corresponds to UNumberCompactStyle=UNUM_LONG)
242      * e.g. "23 thousand", "45 billion"
243      * @stable ICU 56
244      */
245     UNUM_DECIMAL_COMPACT_LONG=15,
246     /**
247      * Currency format with a currency symbol, e.g., "$1.00",
248      * using non-accounting style for negative values (e.g. minus sign).
249      * Overrides any style specified using -cf- key in locale.
250      * @stable ICU 56
251      */
252     UNUM_CURRENCY_STANDARD=16,
253 
254 #ifndef U_HIDE_DEPRECATED_API
255     /**
256      * One more than the highest normal UNumberFormatStyle value.
257      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
258      */
259     UNUM_FORMAT_STYLE_COUNT=17,
260 #endif  /* U_HIDE_DEPRECATED_API */
261 
262     /**
263      * Default format
264      * @stable ICU 2.0
265      */
266     UNUM_DEFAULT = UNUM_DECIMAL,
267     /**
268      * Alias for UNUM_PATTERN_DECIMAL
269      * @stable ICU 3.0
270      */
271     UNUM_IGNORE = UNUM_PATTERN_DECIMAL
272 } UNumberFormatStyle;
273 
274 /** The possible number format rounding modes.
275  *
276  * <p>
277  * For more detail on rounding modes, see:
278  * https://unicode-org.github.io/icu/userguide/format_parse/numbers/rounding-modes
279  *
280  * @stable ICU 2.0
281  */
282 typedef enum UNumberFormatRoundingMode {
283     UNUM_ROUND_CEILING,
284     UNUM_ROUND_FLOOR,
285     UNUM_ROUND_DOWN,
286     UNUM_ROUND_UP,
287     /**
288      * Half-even rounding
289      * @stable, ICU 3.8
290      */
291     UNUM_ROUND_HALFEVEN,
292 #ifndef U_HIDE_DEPRECATED_API
293     /**
294      * Half-even rounding, misspelled name
295      * @deprecated, ICU 3.8
296      */
297     UNUM_FOUND_HALFEVEN = UNUM_ROUND_HALFEVEN,
298 #endif  /* U_HIDE_DEPRECATED_API */
299     UNUM_ROUND_HALFDOWN = UNUM_ROUND_HALFEVEN + 1,
300     UNUM_ROUND_HALFUP,
301     /**
302       * ROUND_UNNECESSARY reports an error if formatted result is not exact.
303       * @stable ICU 4.8
304       */
305     UNUM_ROUND_UNNECESSARY,
306 #ifndef U_HIDE_DRAFT_API
307     /**
308      * Rounds ties toward the odd number.
309      * @draft ICU 69
310      */
311     UNUM_ROUND_HALF_ODD,
312     /**
313      * Rounds ties toward +∞.
314      * @draft ICU 69
315      */
316     UNUM_ROUND_HALF_CEILING,
317     /**
318      * Rounds ties toward -∞.
319      * @draft ICU 69
320      */
321     UNUM_ROUND_HALF_FLOOR,
322 #endif  // U_HIDE_DRAFT_API
323 } UNumberFormatRoundingMode;
324 
325 /** The possible number format pad positions.
326  *  @stable ICU 2.0
327  */
328 typedef enum UNumberFormatPadPosition {
329     UNUM_PAD_BEFORE_PREFIX,
330     UNUM_PAD_AFTER_PREFIX,
331     UNUM_PAD_BEFORE_SUFFIX,
332     UNUM_PAD_AFTER_SUFFIX
333 } UNumberFormatPadPosition;
334 
335 /**
336  * Constants for specifying short or long format.
337  * @stable ICU 51
338  */
339 typedef enum UNumberCompactStyle {
340   /** @stable ICU 51 */
341   UNUM_SHORT,
342   /** @stable ICU 51 */
343   UNUM_LONG
344   /** @stable ICU 51 */
345 } UNumberCompactStyle;
346 
347 /**
348  * Constants for specifying currency spacing
349  * @stable ICU 4.8
350  */
351 enum UCurrencySpacing {
352     /** @stable ICU 4.8 */
353     UNUM_CURRENCY_MATCH,
354     /** @stable ICU 4.8 */
355     UNUM_CURRENCY_SURROUNDING_MATCH,
356     /** @stable ICU 4.8 */
357     UNUM_CURRENCY_INSERT,
358 
359     /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
360      * it is needed for layout of DecimalFormatSymbols object. */
361 #ifndef U_FORCE_HIDE_DEPRECATED_API
362     /**
363      * One more than the highest normal UCurrencySpacing value.
364      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
365      */
366     UNUM_CURRENCY_SPACING_COUNT
367 #endif  // U_FORCE_HIDE_DEPRECATED_API
368 };
369 typedef enum UCurrencySpacing UCurrencySpacing; /**< @stable ICU 4.8 */
370 
371 
372 /**
373  * FieldPosition and UFieldPosition selectors for format fields
374  * defined by NumberFormat and UNumberFormat.
375  * @stable ICU 49
376  */
377 typedef enum UNumberFormatFields {
378     /** @stable ICU 49 */
379     UNUM_INTEGER_FIELD,
380     /** @stable ICU 49 */
381     UNUM_FRACTION_FIELD,
382     /** @stable ICU 49 */
383     UNUM_DECIMAL_SEPARATOR_FIELD,
384     /** @stable ICU 49 */
385     UNUM_EXPONENT_SYMBOL_FIELD,
386     /** @stable ICU 49 */
387     UNUM_EXPONENT_SIGN_FIELD,
388     /** @stable ICU 49 */
389     UNUM_EXPONENT_FIELD,
390     /** @stable ICU 49 */
391     UNUM_GROUPING_SEPARATOR_FIELD,
392     /** @stable ICU 49 */
393     UNUM_CURRENCY_FIELD,
394     /** @stable ICU 49 */
395     UNUM_PERCENT_FIELD,
396     /** @stable ICU 49 */
397     UNUM_PERMILL_FIELD,
398     /** @stable ICU 49 */
399     UNUM_SIGN_FIELD,
400     /** @stable ICU 64 */
401     UNUM_MEASURE_UNIT_FIELD,
402     /** @stable ICU 64 */
403     UNUM_COMPACT_FIELD,
404 
405 #ifndef U_HIDE_DEPRECATED_API
406     /**
407      * One more than the highest normal UNumberFormatFields value.
408      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
409      */
410     UNUM_FIELD_COUNT = UNUM_SIGN_FIELD + 3
411 #endif  /* U_HIDE_DEPRECATED_API */
412 } UNumberFormatFields;
413 
414 
415 #ifndef U_HIDE_DRAFT_API
416 /**
417  * Selectors with special numeric values to use locale default minimum grouping
418  * digits for the DecimalFormat/UNumberFormat setMinimumGroupingDigits method.
419  * Do not use these constants with the [U]NumberFormatter API.
420  *
421  * @draft ICU 68
422  */
423 typedef enum UNumberFormatMinimumGroupingDigits {
424     /**
425      * Display grouping using the default strategy for all locales.
426      * @draft ICU 68
427      */
428     UNUM_MINIMUM_GROUPING_DIGITS_AUTO = -2,
429     /**
430      * Display grouping using locale defaults, except do not show grouping on
431      * values smaller than 10000 (such that there is a minimum of two digits
432      * before the first separator).
433      * @draft ICU 68
434      */
435     UNUM_MINIMUM_GROUPING_DIGITS_MIN2 = -3,
436 } UNumberFormatMinimumGroupingDigits;
437 #endif  // U_HIDE_DRAFT_API
438 
439 /**
440  * Create and return a new UNumberFormat for formatting and parsing
441  * numbers.  A UNumberFormat may be used to format numbers by calling
442  * {@link #unum_format }, and to parse numbers by calling {@link #unum_parse }.
443  * The caller must call {@link #unum_close } when done to release resources
444  * used by this object.
445  * @param style The type of number format to open: one of
446  * UNUM_DECIMAL, UNUM_CURRENCY, UNUM_PERCENT, UNUM_SCIENTIFIC,
447  * UNUM_CURRENCY_ISO, UNUM_CURRENCY_PLURAL, UNUM_SPELLOUT,
448  * UNUM_ORDINAL, UNUM_DURATION, UNUM_NUMBERING_SYSTEM,
449  * UNUM_PATTERN_DECIMAL, UNUM_PATTERN_RULEBASED, or UNUM_DEFAULT.
450  * If UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED is passed then the
451  * number format is opened using the given pattern, which must conform
452  * to the syntax described in DecimalFormat or RuleBasedNumberFormat,
453  * respectively.
454  *
455  * <p><strong>NOTE::</strong> New users with are strongly encouraged to
456  * use unumf_openForSkeletonAndLocale instead of unum_open.
457  *
458  * @param pattern A pattern specifying the format to use.
459  * This parameter is ignored unless the style is
460  * UNUM_PATTERN_DECIMAL or UNUM_PATTERN_RULEBASED.
461  * @param patternLength The number of characters in the pattern, or -1
462  * if null-terminated. This parameter is ignored unless the style is
463  * UNUM_PATTERN.
464  * @param locale A locale identifier to use to determine formatting
465  * and parsing conventions, or NULL to use the default locale.
466  * @param parseErr A pointer to a UParseError struct to receive the
467  * details of any parsing errors, or NULL if no parsing error details
468  * are desired.
469  * @param status A pointer to an input-output UErrorCode.
470  * @return A pointer to a newly created UNumberFormat, or NULL if an
471  * error occurred.
472  * @see unum_close
473  * @see DecimalFormat
474  * @stable ICU 2.0
475  */
476 U_CAPI UNumberFormat* U_EXPORT2
477 unum_open(  UNumberFormatStyle    style,
478             const    UChar*    pattern,
479             int32_t            patternLength,
480             const    char*     locale,
481             UParseError*       parseErr,
482             UErrorCode*        status);
483 
484 
485 /**
486 * Close a UNumberFormat.
487 * Once closed, a UNumberFormat may no longer be used.
488 * @param fmt The formatter to close.
489 * @stable ICU 2.0
490 */
491 U_CAPI void U_EXPORT2
492 unum_close(UNumberFormat* fmt);
493 
494 #if U_SHOW_CPLUSPLUS_API
495 
496 U_NAMESPACE_BEGIN
497 
498 /**
499  * \class LocalUNumberFormatPointer
500  * "Smart pointer" class, closes a UNumberFormat via unum_close().
501  * For most methods see the LocalPointerBase base class.
502  *
503  * @see LocalPointerBase
504  * @see LocalPointer
505  * @stable ICU 4.4
506  */
507 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatPointer, UNumberFormat, unum_close);
508 
509 U_NAMESPACE_END
510 
511 #endif
512 
513 /**
514  * Open a copy of a UNumberFormat.
515  * This function performs a deep copy.
516  * @param fmt The format to copy
517  * @param status A pointer to an UErrorCode to receive any errors.
518  * @return A pointer to a UNumberFormat identical to fmt.
519  * @stable ICU 2.0
520  */
521 U_CAPI UNumberFormat* U_EXPORT2
522 unum_clone(const UNumberFormat *fmt,
523        UErrorCode *status);
524 
525 /**
526 * Format an integer using a UNumberFormat.
527 * The integer will be formatted according to the UNumberFormat's locale.
528 * @param fmt The formatter to use.
529 * @param number The number to format.
530 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
531 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
532 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
533 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
534 * @param resultLength The maximum size of result.
535 * @param pos    A pointer to a UFieldPosition.  On input, position->field
536 * is read.  On output, position->beginIndex and position->endIndex indicate
537 * the beginning and ending indices of field number position->field, if such
538 * a field exists.  This parameter may be NULL, in which case no field
539 * @param status A pointer to an UErrorCode to receive any errors
540 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
541 * @see unum_formatInt64
542 * @see unum_formatDouble
543 * @see unum_parse
544 * @see unum_parseInt64
545 * @see unum_parseDouble
546 * @see UFieldPosition
547 * @stable ICU 2.0
548 */
549 U_CAPI int32_t U_EXPORT2
550 unum_format(    const    UNumberFormat*    fmt,
551         int32_t            number,
552         UChar*            result,
553         int32_t            resultLength,
554         UFieldPosition    *pos,
555         UErrorCode*        status);
556 
557 /**
558 * Format an int64 using a UNumberFormat.
559 * The int64 will be formatted according to the UNumberFormat's locale.
560 * @param fmt The formatter to use.
561 * @param number The number to format.
562 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
563 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
564 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
565 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
566 * @param resultLength The maximum size of result.
567 * @param pos    A pointer to a UFieldPosition.  On input, position->field
568 * is read.  On output, position->beginIndex and position->endIndex indicate
569 * the beginning and ending indices of field number position->field, if such
570 * a field exists.  This parameter may be NULL, in which case no field
571 * @param status A pointer to an UErrorCode to receive any errors
572 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
573 * @see unum_format
574 * @see unum_formatDouble
575 * @see unum_parse
576 * @see unum_parseInt64
577 * @see unum_parseDouble
578 * @see UFieldPosition
579 * @stable ICU 2.0
580 */
581 U_CAPI int32_t U_EXPORT2
582 unum_formatInt64(const UNumberFormat *fmt,
583         int64_t         number,
584         UChar*          result,
585         int32_t         resultLength,
586         UFieldPosition *pos,
587         UErrorCode*     status);
588 
589 /**
590 * Format a double using a UNumberFormat.
591 * The double will be formatted according to the UNumberFormat's locale.
592 * @param fmt The formatter to use.
593 * @param number The number to format.
594 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
595 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
596 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
597 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
598 * @param resultLength The maximum size of result.
599 * @param pos    A pointer to a UFieldPosition.  On input, position->field
600 * is read.  On output, position->beginIndex and position->endIndex indicate
601 * the beginning and ending indices of field number position->field, if such
602 * a field exists.  This parameter may be NULL, in which case no field
603 * @param status A pointer to an UErrorCode to receive any errors
604 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
605 * @see unum_format
606 * @see unum_formatInt64
607 * @see unum_parse
608 * @see unum_parseInt64
609 * @see unum_parseDouble
610 * @see UFieldPosition
611 * @stable ICU 2.0
612 */
613 U_CAPI int32_t U_EXPORT2
614 unum_formatDouble(    const    UNumberFormat*  fmt,
615             double          number,
616             UChar*          result,
617             int32_t         resultLength,
618             UFieldPosition  *pos, /* 0 if ignore */
619             UErrorCode*     status);
620 
621 /**
622 * Format a double using a UNumberFormat according to the UNumberFormat's locale,
623 * and initialize a UFieldPositionIterator that enumerates the subcomponents of
624 * the resulting string.
625 *
626 * @param format
627 *          The formatter to use.
628 * @param number
629 *          The number to format.
630 * @param result
631 *          A pointer to a buffer to receive the NULL-terminated formatted
632 *          number. If the formatted number fits into dest but cannot be
633 *          NULL-terminated (length == resultLength) then the error code is set
634 *          to U_STRING_NOT_TERMINATED_WARNING. If the formatted number doesn't
635 *          fit into result then the error code is set to
636 *          U_BUFFER_OVERFLOW_ERROR.
637 * @param resultLength
638 *          The maximum size of result.
639 * @param fpositer
640 *          A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
641 *          (may be NULL if field position information is not needed, but in this
642 *          case it's preferable to use {@link #unum_formatDouble}). Iteration
643 *          information already present in the UFieldPositionIterator is deleted,
644 *          and the iterator is reset to apply to the fields in the formatted
645 *          string created by this function call. The field values and indexes
646 *          returned by {@link #ufieldpositer_next} represent fields denoted by
647 *          the UNumberFormatFields enum. Fields are not returned in a guaranteed
648 *          order. Fields cannot overlap, but they may nest. For example, 1234
649 *          could format as "1,234" which might consist of a grouping separator
650 *          field for ',' and an integer field encompassing the entire string.
651 * @param status
652 *          A pointer to an UErrorCode to receive any errors
653 * @return
654 *          The total buffer size needed; if greater than resultLength, the
655 *          output was truncated.
656 * @see unum_formatDouble
657 * @see unum_parse
658 * @see unum_parseDouble
659 * @see UFieldPositionIterator
660 * @see UNumberFormatFields
661 * @stable ICU 59
662 */
663 U_CAPI int32_t U_EXPORT2
664 unum_formatDoubleForFields(const UNumberFormat* format,
665                            double number,
666                            UChar* result,
667                            int32_t resultLength,
668                            UFieldPositionIterator* fpositer,
669                            UErrorCode* status);
670 
671 
672 /**
673 * Format a decimal number using a UNumberFormat.
674 * The number will be formatted according to the UNumberFormat's locale.
675 * The syntax of the input number is a "numeric string"
676 * as defined in the Decimal Arithmetic Specification, available at
677 * http://speleotrove.com/decimal
678 * @param fmt The formatter to use.
679 * @param number The number to format.
680 * @param length The length of the input number, or -1 if the input is nul-terminated.
681 * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
682 * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
683 * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
684 * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
685 * @param resultLength The maximum size of result.
686 * @param pos    A pointer to a UFieldPosition.  On input, position->field
687 *               is read.  On output, position->beginIndex and position->endIndex indicate
688 *               the beginning and ending indices of field number position->field, if such
689 *               a field exists.  This parameter may be NULL, in which case it is ignored.
690 * @param status A pointer to an UErrorCode to receive any errors
691 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
692 * @see unum_format
693 * @see unum_formatInt64
694 * @see unum_parse
695 * @see unum_parseInt64
696 * @see unum_parseDouble
697 * @see UFieldPosition
698 * @stable ICU 4.4
699 */
700 U_CAPI int32_t U_EXPORT2
701 unum_formatDecimal(    const    UNumberFormat*  fmt,
702             const char *    number,
703             int32_t         length,
704             UChar*          result,
705             int32_t         resultLength,
706             UFieldPosition  *pos, /* 0 if ignore */
707             UErrorCode*     status);
708 
709 /**
710  * Format a double currency amount using a UNumberFormat.
711  * The double will be formatted according to the UNumberFormat's locale.
712  *
713  * To format an exact decimal value with a currency, use
714  * `unum_setTextAttribute(UNUM_CURRENCY_CODE, ...)` followed by unum_formatDecimal.
715  * Your UNumberFormat must be created with the UNUM_CURRENCY style. Alternatively,
716  * consider using unumf_openForSkeletonAndLocale.
717  *
718  * @param fmt the formatter to use
719  * @param number the number to format
720  * @param currency the 3-letter null-terminated ISO 4217 currency code
721  * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
722  * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
723  * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
724  * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
725  * @param resultLength the maximum number of UChars to write to result
726  * @param pos a pointer to a UFieldPosition.  On input,
727  * position->field is read.  On output, position->beginIndex and
728  * position->endIndex indicate the beginning and ending indices of
729  * field number position->field, if such a field exists.  This
730  * parameter may be NULL, in which case it is ignored.
731  * @param status a pointer to an input-output UErrorCode
732  * @return the total buffer size needed; if greater than resultLength,
733  * the output was truncated.
734  * @see unum_formatDouble
735  * @see unum_parseDoubleCurrency
736  * @see UFieldPosition
737  * @stable ICU 3.0
738  */
739 U_CAPI int32_t U_EXPORT2
740 unum_formatDoubleCurrency(const UNumberFormat* fmt,
741                           double number,
742                           UChar* currency,
743                           UChar* result,
744                           int32_t resultLength,
745                           UFieldPosition* pos,
746                           UErrorCode* status);
747 
748 /**
749  * Format a UFormattable into a string.
750  * @param fmt the formatter to use
751  * @param number the number to format, as a UFormattable
752  * @param result A pointer to a buffer to receive the NULL-terminated formatted number. If
753  * the formatted number fits into dest but cannot be NULL-terminated (length == resultLength)
754  * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the formatted number
755  * doesn't fit into result then the error code is set to U_BUFFER_OVERFLOW_ERROR.
756  * @param resultLength the maximum number of UChars to write to result
757  * @param pos a pointer to a UFieldPosition.  On input,
758  * position->field is read.  On output, position->beginIndex and
759  * position->endIndex indicate the beginning and ending indices of
760  * field number position->field, if such a field exists.  This
761  * parameter may be NULL, in which case it is ignored.
762  * @param status a pointer to an input-output UErrorCode
763  * @return the total buffer size needed; if greater than resultLength,
764  * the output was truncated. Will return 0 on error.
765  * @see unum_parseToUFormattable
766  * @stable ICU 52
767  */
768 U_CAPI int32_t U_EXPORT2
769 unum_formatUFormattable(const UNumberFormat* fmt,
770                         const UFormattable *number,
771                         UChar *result,
772                         int32_t resultLength,
773                         UFieldPosition *pos,
774                         UErrorCode *status);
775 
776 /**
777 * Parse a string into an integer using a UNumberFormat.
778 * The string will be parsed according to the UNumberFormat's locale.
779 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
780 * and UNUM_DECIMAL_COMPACT_LONG.
781 * @param fmt The formatter to use.
782 * @param text The text to parse.
783 * @param textLength The length of text, or -1 if null-terminated.
784 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
785 * to begin parsing.  If not NULL, on output the offset at which parsing ended.
786 * @param status A pointer to an UErrorCode to receive any errors
787 * @return The value of the parsed integer
788 * @see unum_parseInt64
789 * @see unum_parseDouble
790 * @see unum_format
791 * @see unum_formatInt64
792 * @see unum_formatDouble
793 * @stable ICU 2.0
794 */
795 U_CAPI int32_t U_EXPORT2
796 unum_parse(    const   UNumberFormat*  fmt,
797         const   UChar*          text,
798         int32_t         textLength,
799         int32_t         *parsePos /* 0 = start */,
800         UErrorCode      *status);
801 
802 /**
803 * Parse a string into an int64 using a UNumberFormat.
804 * The string will be parsed according to the UNumberFormat's locale.
805 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
806 * and UNUM_DECIMAL_COMPACT_LONG.
807 * @param fmt The formatter to use.
808 * @param text The text to parse.
809 * @param textLength The length of text, or -1 if null-terminated.
810 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
811 * to begin parsing.  If not NULL, on output the offset at which parsing ended.
812 * @param status A pointer to an UErrorCode to receive any errors
813 * @return The value of the parsed integer
814 * @see unum_parse
815 * @see unum_parseDouble
816 * @see unum_format
817 * @see unum_formatInt64
818 * @see unum_formatDouble
819 * @stable ICU 2.8
820 */
821 U_CAPI int64_t U_EXPORT2
822 unum_parseInt64(const UNumberFormat*  fmt,
823         const UChar*  text,
824         int32_t       textLength,
825         int32_t       *parsePos /* 0 = start */,
826         UErrorCode    *status);
827 
828 /**
829 * Parse a string into a double using a UNumberFormat.
830 * The string will be parsed according to the UNumberFormat's locale.
831 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
832 * and UNUM_DECIMAL_COMPACT_LONG.
833 * @param fmt The formatter to use.
834 * @param text The text to parse.
835 * @param textLength The length of text, or -1 if null-terminated.
836 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
837 * to begin parsing.  If not NULL, on output the offset at which parsing ended.
838 * @param status A pointer to an UErrorCode to receive any errors
839 * @return The value of the parsed double
840 * @see unum_parse
841 * @see unum_parseInt64
842 * @see unum_format
843 * @see unum_formatInt64
844 * @see unum_formatDouble
845 * @stable ICU 2.0
846 */
847 U_CAPI double U_EXPORT2
848 unum_parseDouble(    const   UNumberFormat*  fmt,
849             const   UChar*          text,
850             int32_t         textLength,
851             int32_t         *parsePos /* 0 = start */,
852             UErrorCode      *status);
853 
854 
855 /**
856 * Parse a number from a string into an unformatted numeric string using a UNumberFormat.
857 * The input string will be parsed according to the UNumberFormat's locale.
858 * The syntax of the output is a "numeric string"
859 * as defined in the Decimal Arithmetic Specification, available at
860 * http://speleotrove.com/decimal
861 * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
862 * and UNUM_DECIMAL_COMPACT_LONG.
863 * @param fmt The formatter to use.
864 * @param text The text to parse.
865 * @param textLength The length of text, or -1 if null-terminated.
866 * @param parsePos If not NULL, on input a pointer to an integer specifying the offset at which
867 *                 to begin parsing.  If not NULL, on output the offset at which parsing ended.
868 * @param outBuf A (char *) buffer to receive the parsed number as a string.  The output string
869 *               will be nul-terminated if there is sufficient space.
870 * @param outBufLength The size of the output buffer.  May be zero, in which case
871 *               the outBuf pointer may be NULL, and the function will return the
872 *               size of the output string.
873 * @param status A pointer to an UErrorCode to receive any errors
874 * @return the length of the output string, not including any terminating nul.
875 * @see unum_parse
876 * @see unum_parseInt64
877 * @see unum_format
878 * @see unum_formatInt64
879 * @see unum_formatDouble
880 * @stable ICU 4.4
881 */
882 U_CAPI int32_t U_EXPORT2
883 unum_parseDecimal(const   UNumberFormat*  fmt,
884                  const   UChar*          text,
885                          int32_t         textLength,
886                          int32_t         *parsePos /* 0 = start */,
887                          char            *outBuf,
888                          int32_t         outBufLength,
889                          UErrorCode      *status);
890 
891 /**
892  * Parse a string into a double and a currency using a UNumberFormat.
893  * The string will be parsed according to the UNumberFormat's locale.
894  * @param fmt the formatter to use
895  * @param text the text to parse
896  * @param textLength the length of text, or -1 if null-terminated
897  * @param parsePos a pointer to an offset index into text at which to
898  * begin parsing. On output, *parsePos will point after the last
899  * parsed character.  This parameter may be NULL, in which case parsing
900  * begins at offset 0.
901  * @param currency a pointer to the buffer to receive the parsed null-
902  * terminated currency.  This buffer must have a capacity of at least
903  * 4 UChars.
904  * @param status a pointer to an input-output UErrorCode
905  * @return the parsed double
906  * @see unum_parseDouble
907  * @see unum_formatDoubleCurrency
908  * @stable ICU 3.0
909  */
910 U_CAPI double U_EXPORT2
911 unum_parseDoubleCurrency(const UNumberFormat* fmt,
912                          const UChar* text,
913                          int32_t textLength,
914                          int32_t* parsePos, /* 0 = start */
915                          UChar* currency,
916                          UErrorCode* status);
917 
918 /**
919  * Parse a UChar string into a UFormattable.
920  * Example code:
921  * \snippet test/cintltst/cnumtst.c unum_parseToUFormattable
922  * Note: parsing is not supported for styles UNUM_DECIMAL_COMPACT_SHORT
923  * and UNUM_DECIMAL_COMPACT_LONG.
924  * @param fmt the formatter to use
925  * @param result the UFormattable to hold the result. If NULL, a new UFormattable will be allocated (which the caller must close with ufmt_close).
926  * @param text the text to parse
927  * @param textLength the length of text, or -1 if null-terminated
928  * @param parsePos a pointer to an offset index into text at which to
929  * begin parsing. On output, *parsePos will point after the last
930  * parsed character.  This parameter may be NULL in which case parsing
931  * begins at offset 0.
932  * @param status a pointer to an input-output UErrorCode
933  * @return the UFormattable.  Will be ==result unless NULL was passed in for result, in which case it will be the newly opened UFormattable.
934  * @see ufmt_getType
935  * @see ufmt_close
936  * @stable ICU 52
937  */
938 U_CAPI UFormattable* U_EXPORT2
939 unum_parseToUFormattable(const UNumberFormat* fmt,
940                          UFormattable *result,
941                          const UChar* text,
942                          int32_t textLength,
943                          int32_t* parsePos, /* 0 = start */
944                          UErrorCode* status);
945 
946 /**
947  * Set the pattern used by a UNumberFormat.  This can only be used
948  * on a DecimalFormat, other formats return U_UNSUPPORTED_ERROR
949  * in the status.
950  * @param format The formatter to set.
951  * @param localized true if the pattern is localized, false otherwise.
952  * @param pattern The new pattern
953  * @param patternLength The length of pattern, or -1 if null-terminated.
954  * @param parseError A pointer to UParseError to receive information
955  * about errors occurred during parsing, or NULL if no parse error
956  * information is desired.
957  * @param status A pointer to an input-output UErrorCode.
958  * @see unum_toPattern
959  * @see DecimalFormat
960  * @stable ICU 2.0
961  */
962 U_CAPI void U_EXPORT2
963 unum_applyPattern(          UNumberFormat  *format,
964                             UBool          localized,
965                     const   UChar          *pattern,
966                             int32_t         patternLength,
967                             UParseError    *parseError,
968                             UErrorCode     *status
969                                     );
970 
971 /**
972 * Get a locale for which decimal formatting patterns are available.
973 * A UNumberFormat in a locale returned by this function will perform the correct
974 * formatting and parsing for the locale.  The results of this call are not
975 * valid for rule-based number formats.
976 * @param localeIndex The index of the desired locale.
977 * @return A locale for which number formatting patterns are available, or 0 if none.
978 * @see unum_countAvailable
979 * @stable ICU 2.0
980 */
981 U_CAPI const char* U_EXPORT2
982 unum_getAvailable(int32_t localeIndex);
983 
984 /**
985 * Determine how many locales have decimal formatting patterns available.  The
986 * results of this call are not valid for rule-based number formats.
987 * This function is useful for determining the loop ending condition for
988 * calls to {@link #unum_getAvailable }.
989 * @return The number of locales for which decimal formatting patterns are available.
990 * @see unum_getAvailable
991 * @stable ICU 2.0
992 */
993 U_CAPI int32_t U_EXPORT2
994 unum_countAvailable(void);
995 
996 #if UCONFIG_HAVE_PARSEALLINPUT
997 /* The UNumberFormatAttributeValue type cannot be #ifndef U_HIDE_INTERNAL_API, needed for .h variable declaration */
998 /**
999  * @internal
1000  */
1001 typedef enum UNumberFormatAttributeValue {
1002 #ifndef U_HIDE_INTERNAL_API
1003   /** @internal */
1004   UNUM_NO = 0,
1005   /** @internal */
1006   UNUM_YES = 1,
1007   /** @internal */
1008   UNUM_MAYBE = 2
1009 #else
1010   /** @internal */
1011   UNUM_FORMAT_ATTRIBUTE_VALUE_HIDDEN
1012 #endif /* U_HIDE_INTERNAL_API */
1013 } UNumberFormatAttributeValue;
1014 #endif
1015 
1016 /** The possible UNumberFormat numeric attributes @stable ICU 2.0 */
1017 typedef enum UNumberFormatAttribute {
1018   /** Parse integers only */
1019   UNUM_PARSE_INT_ONLY,
1020   /** Use grouping separator */
1021   UNUM_GROUPING_USED,
1022   /** Always show decimal point */
1023   UNUM_DECIMAL_ALWAYS_SHOWN,
1024   /** Maximum integer digits */
1025   UNUM_MAX_INTEGER_DIGITS,
1026   /** Minimum integer digits */
1027   UNUM_MIN_INTEGER_DIGITS,
1028   /** Integer digits */
1029   UNUM_INTEGER_DIGITS,
1030   /** Maximum fraction digits */
1031   UNUM_MAX_FRACTION_DIGITS,
1032   /** Minimum fraction digits */
1033   UNUM_MIN_FRACTION_DIGITS,
1034   /** Fraction digits */
1035   UNUM_FRACTION_DIGITS,
1036   /** Multiplier */
1037   UNUM_MULTIPLIER,
1038   /** Grouping size */
1039   UNUM_GROUPING_SIZE,
1040   /** Rounding Mode */
1041   UNUM_ROUNDING_MODE,
1042   /** Rounding increment */
1043   UNUM_ROUNDING_INCREMENT,
1044   /** The width to which the output of <code>format()</code> is padded. */
1045   UNUM_FORMAT_WIDTH,
1046   /** The position at which padding will take place. */
1047   UNUM_PADDING_POSITION,
1048   /** Secondary grouping size */
1049   UNUM_SECONDARY_GROUPING_SIZE,
1050   /** Use significant digits
1051    * @stable ICU 3.0 */
1052   UNUM_SIGNIFICANT_DIGITS_USED,
1053   /** Minimum significant digits
1054    * @stable ICU 3.0 */
1055   UNUM_MIN_SIGNIFICANT_DIGITS,
1056   /** Maximum significant digits
1057    * @stable ICU 3.0 */
1058   UNUM_MAX_SIGNIFICANT_DIGITS,
1059   /** Lenient parse mode used by rule-based formats.
1060    * @stable ICU 3.0
1061    */
1062   UNUM_LENIENT_PARSE,
1063 #if UCONFIG_HAVE_PARSEALLINPUT
1064   /** Consume all input. (may use fastpath). Set to UNUM_YES (require fastpath), UNUM_NO (skip fastpath), or UNUM_MAYBE (heuristic).
1065    * This is an internal ICU API. Do not use.
1066    * @internal
1067    */
1068   UNUM_PARSE_ALL_INPUT = 20,
1069 #endif
1070   /**
1071     * Scale, which adjusts the position of the
1072     * decimal point when formatting.  Amounts will be multiplied by 10 ^ (scale)
1073     * before they are formatted.  The default value for the scale is 0 ( no adjustment ).
1074     *
1075     * <p>Example: setting the scale to 3, 123 formats as "123,000"
1076     * <p>Example: setting the scale to -4, 123 formats as "0.0123"
1077     *
1078     * This setting is analogous to getMultiplierScale() and setMultiplierScale() in decimfmt.h.
1079     *
1080    * @stable ICU 51 */
1081   UNUM_SCALE = 21,
1082 
1083   /**
1084    * Minimum grouping digits; most commonly set to 2 to print "1000" instead of "1,000".
1085    * See DecimalFormat::getMinimumGroupingDigits().
1086    *
1087    * For better control over grouping strategies, use UNumberFormatter.
1088    *
1089    * @stable ICU 64
1090    */
1091   UNUM_MINIMUM_GROUPING_DIGITS = 22,
1092 
1093   /**
1094    * if this attribute is set to 0, it is set to UNUM_CURRENCY_STANDARD purpose,
1095    * otherwise it is UNUM_CURRENCY_CASH purpose
1096    * Default: 0 (UNUM_CURRENCY_STANDARD purpose)
1097    * @stable ICU 54
1098    */
1099   UNUM_CURRENCY_USAGE = 23,
1100 
1101 #ifndef U_HIDE_INTERNAL_API
1102   /** One below the first bitfield-boolean item.
1103    * All items after this one are stored in boolean form.
1104    * @internal */
1105   UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF,
1106 #endif /* U_HIDE_INTERNAL_API */
1107 
1108   /** If 1, specifies that if setting the "max integer digits" attribute would truncate a value, set an error status rather than silently truncating.
1109    * For example,  formatting the value 1234 with 4 max int digits would succeed, but formatting 12345 would fail. There is no effect on parsing.
1110    * Default: 0 (not set)
1111    * @stable ICU 50
1112    */
1113   UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000,
1114   /**
1115    * if this attribute is set to 1, specifies that, if the pattern doesn't contain an exponent, the exponent will not be parsed. If the pattern does contain an exponent, this attribute has no effect.
1116    * Has no effect on formatting.
1117    * Default: 0 (unset)
1118    * @stable ICU 50
1119    */
1120   UNUM_PARSE_NO_EXPONENT = 0x1001,
1121 
1122   /**
1123    * if this attribute is set to 1, specifies that, if the pattern contains a
1124    * decimal mark the input is required to have one. If this attribute is set to 0,
1125    * specifies that input does not have to contain a decimal mark.
1126    * Has no effect on formatting.
1127    * Default: 0 (unset)
1128    * @stable ICU 54
1129    */
1130   UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002,
1131 
1132   /**
1133    * Parsing: if set to 1, parsing is sensitive to case (lowercase/uppercase).
1134    *
1135    * @stable ICU 64
1136    */
1137   UNUM_PARSE_CASE_SENSITIVE = 0x1003,
1138 
1139   /**
1140    * Formatting: if set to 1, whether to show the plus sign on non-negative numbers.
1141    *
1142    * For better control over sign display, use UNumberFormatter.
1143    *
1144    * @stable ICU 64
1145    */
1146   UNUM_SIGN_ALWAYS_SHOWN = 0x1004,
1147 
1148 #ifndef U_HIDE_INTERNAL_API
1149   /** Limit of boolean attributes. (value should
1150    * not depend on U_HIDE conditionals)
1151    * @internal */
1152   UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1005,
1153 #endif /* U_HIDE_INTERNAL_API */
1154 
1155 } UNumberFormatAttribute;
1156 
1157 /**
1158 * Get a numeric attribute associated with a UNumberFormat.
1159 * An example of a numeric attribute is the number of integer digits a formatter will produce.
1160 * @param fmt The formatter to query.
1161 * @param attr The attribute to query; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
1162 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
1163 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
1164 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
1165 * UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
1166 * @return The value of attr.
1167 * @see unum_setAttribute
1168 * @see unum_getDoubleAttribute
1169 * @see unum_setDoubleAttribute
1170 * @see unum_getTextAttribute
1171 * @see unum_setTextAttribute
1172 * @stable ICU 2.0
1173 */
1174 U_CAPI int32_t U_EXPORT2
1175 unum_getAttribute(const UNumberFormat*          fmt,
1176           UNumberFormatAttribute  attr);
1177 
1178 /**
1179 * Set a numeric attribute associated with a UNumberFormat.
1180 * An example of a numeric attribute is the number of integer digits a formatter will produce.  If the
1181 * formatter does not understand the attribute, the call is ignored.  Rule-based formatters only understand
1182 * the lenient-parse attribute.
1183 * @param fmt The formatter to set.
1184 * @param attr The attribute to set; one of UNUM_PARSE_INT_ONLY, UNUM_GROUPING_USED,
1185 * UNUM_DECIMAL_ALWAYS_SHOWN, UNUM_MAX_INTEGER_DIGITS, UNUM_MIN_INTEGER_DIGITS, UNUM_INTEGER_DIGITS,
1186 * UNUM_MAX_FRACTION_DIGITS, UNUM_MIN_FRACTION_DIGITS, UNUM_FRACTION_DIGITS, UNUM_MULTIPLIER,
1187 * UNUM_GROUPING_SIZE, UNUM_ROUNDING_MODE, UNUM_FORMAT_WIDTH, UNUM_PADDING_POSITION, UNUM_SECONDARY_GROUPING_SIZE,
1188 * UNUM_LENIENT_PARSE, UNUM_SCALE, UNUM_MINIMUM_GROUPING_DIGITS.
1189 * @param newValue The new value of attr.
1190 * @see unum_getAttribute
1191 * @see unum_getDoubleAttribute
1192 * @see unum_setDoubleAttribute
1193 * @see unum_getTextAttribute
1194 * @see unum_setTextAttribute
1195 * @stable ICU 2.0
1196 */
1197 U_CAPI void U_EXPORT2
1198 unum_setAttribute(    UNumberFormat*          fmt,
1199             UNumberFormatAttribute  attr,
1200             int32_t                 newValue);
1201 
1202 
1203 /**
1204 * Get a numeric attribute associated with a UNumberFormat.
1205 * An example of a numeric attribute is the number of integer digits a formatter will produce.
1206 * If the formatter does not understand the attribute, -1 is returned.
1207 * @param fmt The formatter to query.
1208 * @param attr The attribute to query; e.g. UNUM_ROUNDING_INCREMENT.
1209 * @return The value of attr.
1210 * @see unum_getAttribute
1211 * @see unum_setAttribute
1212 * @see unum_setDoubleAttribute
1213 * @see unum_getTextAttribute
1214 * @see unum_setTextAttribute
1215 * @stable ICU 2.0
1216 */
1217 U_CAPI double U_EXPORT2
1218 unum_getDoubleAttribute(const UNumberFormat*          fmt,
1219           UNumberFormatAttribute  attr);
1220 
1221 /**
1222 * Set a numeric attribute associated with a UNumberFormat.
1223 * An example of a numeric attribute is the number of integer digits a formatter will produce.
1224 * If the formatter does not understand the attribute, this call is ignored.
1225 * @param fmt The formatter to set.
1226 * @param attr The attribute to set; e.g. UNUM_ROUNDING_INCREMENT.
1227 * @param newValue The new value of attr.
1228 * @see unum_getAttribute
1229 * @see unum_setAttribute
1230 * @see unum_getDoubleAttribute
1231 * @see unum_getTextAttribute
1232 * @see unum_setTextAttribute
1233 * @stable ICU 2.0
1234 */
1235 U_CAPI void U_EXPORT2
1236 unum_setDoubleAttribute(    UNumberFormat*          fmt,
1237             UNumberFormatAttribute  attr,
1238             double                 newValue);
1239 
1240 /** The possible UNumberFormat text attributes @stable ICU 2.0*/
1241 typedef enum UNumberFormatTextAttribute {
1242   /** Positive prefix */
1243   UNUM_POSITIVE_PREFIX,
1244   /** Positive suffix */
1245   UNUM_POSITIVE_SUFFIX,
1246   /** Negative prefix */
1247   UNUM_NEGATIVE_PREFIX,
1248   /** Negative suffix */
1249   UNUM_NEGATIVE_SUFFIX,
1250   /** The character used to pad to the format width. */
1251   UNUM_PADDING_CHARACTER,
1252   /** The ISO currency code */
1253   UNUM_CURRENCY_CODE,
1254   /**
1255    * The default rule set, such as "%spellout-numbering-year:", "%spellout-cardinal:",
1256    * "%spellout-ordinal-masculine-plural:", "%spellout-ordinal-feminine:", or
1257    * "%spellout-ordinal-neuter:". The available public rulesets can be listed using
1258    * unum_getTextAttribute with UNUM_PUBLIC_RULESETS. This is only available with
1259    * rule-based formatters.
1260    * @stable ICU 3.0
1261    */
1262   UNUM_DEFAULT_RULESET,
1263   /**
1264    * The public rule sets.  This is only available with rule-based formatters.
1265    * This is a read-only attribute.  The public rulesets are returned as a
1266    * single string, with each ruleset name delimited by ';' (semicolon). See the
1267    * CLDR LDML spec for more information about RBNF rulesets:
1268    * http://www.unicode.org/reports/tr35/tr35-numbers.html#Rule-Based_Number_Formatting
1269    * @stable ICU 3.0
1270    */
1271   UNUM_PUBLIC_RULESETS
1272 } UNumberFormatTextAttribute;
1273 
1274 /**
1275 * Get a text attribute associated with a UNumberFormat.
1276 * An example of a text attribute is the suffix for positive numbers.  If the formatter
1277 * does not understand the attribute, U_UNSUPPORTED_ERROR is returned as the status.
1278 * Rule-based formatters only understand UNUM_DEFAULT_RULESET and UNUM_PUBLIC_RULESETS.
1279 * @param fmt The formatter to query.
1280 * @param tag The attribute to query; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
1281 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
1282 * UNUM_DEFAULT_RULESET, or UNUM_PUBLIC_RULESETS.
1283 * @param result A pointer to a buffer to receive the attribute.
1284 * @param resultLength The maximum size of result.
1285 * @param status A pointer to an UErrorCode to receive any errors
1286 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1287 * @see unum_setTextAttribute
1288 * @see unum_getAttribute
1289 * @see unum_setAttribute
1290 * @stable ICU 2.0
1291 */
1292 U_CAPI int32_t U_EXPORT2
1293 unum_getTextAttribute(    const    UNumberFormat*                    fmt,
1294             UNumberFormatTextAttribute      tag,
1295             UChar*                            result,
1296             int32_t                            resultLength,
1297             UErrorCode*                        status);
1298 
1299 /**
1300 * Set a text attribute associated with a UNumberFormat.
1301 * An example of a text attribute is the suffix for positive numbers.  Rule-based formatters
1302 * only understand UNUM_DEFAULT_RULESET.
1303 * @param fmt The formatter to set.
1304 * @param tag The attribute to set; one of UNUM_POSITIVE_PREFIX, UNUM_POSITIVE_SUFFIX,
1305 * UNUM_NEGATIVE_PREFIX, UNUM_NEGATIVE_SUFFIX, UNUM_PADDING_CHARACTER, UNUM_CURRENCY_CODE,
1306 * or UNUM_DEFAULT_RULESET.
1307 * @param newValue The new value of attr.
1308 * @param newValueLength The length of newValue, or -1 if null-terminated.
1309 * @param status A pointer to an UErrorCode to receive any errors
1310 * @see unum_getTextAttribute
1311 * @see unum_getAttribute
1312 * @see unum_setAttribute
1313 * @stable ICU 2.0
1314 */
1315 U_CAPI void U_EXPORT2
1316 unum_setTextAttribute(    UNumberFormat*                    fmt,
1317             UNumberFormatTextAttribute      tag,
1318             const    UChar*                            newValue,
1319             int32_t                            newValueLength,
1320             UErrorCode                        *status);
1321 
1322 /**
1323  * Extract the pattern from a UNumberFormat.  The pattern will follow
1324  * the DecimalFormat pattern syntax.
1325  * @param fmt The formatter to query.
1326  * @param isPatternLocalized true if the pattern should be localized,
1327  * false otherwise.  This is ignored if the formatter is a rule-based
1328  * formatter.
1329  * @param result A pointer to a buffer to receive the pattern.
1330  * @param resultLength The maximum size of result.
1331  * @param status A pointer to an input-output UErrorCode.
1332  * @return The total buffer size needed; if greater than resultLength,
1333  * the output was truncated.
1334  * @see unum_applyPattern
1335  * @see DecimalFormat
1336  * @stable ICU 2.0
1337  */
1338 U_CAPI int32_t U_EXPORT2
1339 unum_toPattern(    const    UNumberFormat*          fmt,
1340         UBool                  isPatternLocalized,
1341         UChar*                  result,
1342         int32_t                 resultLength,
1343         UErrorCode*             status);
1344 
1345 
1346 /**
1347  * Constants for specifying a number format symbol.
1348  * @stable ICU 2.0
1349  */
1350 typedef enum UNumberFormatSymbol {
1351   /** The decimal separator */
1352   UNUM_DECIMAL_SEPARATOR_SYMBOL = 0,
1353   /** The grouping separator */
1354   UNUM_GROUPING_SEPARATOR_SYMBOL = 1,
1355   /** The pattern separator */
1356   UNUM_PATTERN_SEPARATOR_SYMBOL = 2,
1357   /** The percent sign */
1358   UNUM_PERCENT_SYMBOL = 3,
1359   /** Zero*/
1360   UNUM_ZERO_DIGIT_SYMBOL = 4,
1361   /** Character representing a digit in the pattern */
1362   UNUM_DIGIT_SYMBOL = 5,
1363   /** The minus sign */
1364   UNUM_MINUS_SIGN_SYMBOL = 6,
1365   /** The plus sign */
1366   UNUM_PLUS_SIGN_SYMBOL = 7,
1367   /** The currency symbol */
1368   UNUM_CURRENCY_SYMBOL = 8,
1369   /** The international currency symbol */
1370   UNUM_INTL_CURRENCY_SYMBOL = 9,
1371   /** The monetary separator */
1372   UNUM_MONETARY_SEPARATOR_SYMBOL = 10,
1373   /** The exponential symbol */
1374   UNUM_EXPONENTIAL_SYMBOL = 11,
1375   /** Per mill symbol */
1376   UNUM_PERMILL_SYMBOL = 12,
1377   /** Escape padding character */
1378   UNUM_PAD_ESCAPE_SYMBOL = 13,
1379   /** Infinity symbol */
1380   UNUM_INFINITY_SYMBOL = 14,
1381   /** Nan symbol */
1382   UNUM_NAN_SYMBOL = 15,
1383   /** Significant digit symbol
1384    * @stable ICU 3.0 */
1385   UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16,
1386   /** The monetary grouping separator
1387    * @stable ICU 3.6
1388    */
1389   UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17,
1390   /** One
1391    * @stable ICU 4.6
1392    */
1393   UNUM_ONE_DIGIT_SYMBOL = 18,
1394   /** Two
1395    * @stable ICU 4.6
1396    */
1397   UNUM_TWO_DIGIT_SYMBOL = 19,
1398   /** Three
1399    * @stable ICU 4.6
1400    */
1401   UNUM_THREE_DIGIT_SYMBOL = 20,
1402   /** Four
1403    * @stable ICU 4.6
1404    */
1405   UNUM_FOUR_DIGIT_SYMBOL = 21,
1406   /** Five
1407    * @stable ICU 4.6
1408    */
1409   UNUM_FIVE_DIGIT_SYMBOL = 22,
1410   /** Six
1411    * @stable ICU 4.6
1412    */
1413   UNUM_SIX_DIGIT_SYMBOL = 23,
1414   /** Seven
1415     * @stable ICU 4.6
1416    */
1417   UNUM_SEVEN_DIGIT_SYMBOL = 24,
1418   /** Eight
1419    * @stable ICU 4.6
1420    */
1421   UNUM_EIGHT_DIGIT_SYMBOL = 25,
1422   /** Nine
1423    * @stable ICU 4.6
1424    */
1425   UNUM_NINE_DIGIT_SYMBOL = 26,
1426 
1427   /** Multiplication sign
1428    * @stable ICU 54
1429    */
1430   UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27,
1431 
1432 #ifndef U_HIDE_DEPRECATED_API
1433     /**
1434      * One more than the highest normal UNumberFormatSymbol value.
1435      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
1436      */
1437   UNUM_FORMAT_SYMBOL_COUNT = 28
1438 #endif  /* U_HIDE_DEPRECATED_API */
1439 } UNumberFormatSymbol;
1440 
1441 /**
1442 * Get a symbol associated with a UNumberFormat.
1443 * A UNumberFormat uses symbols to represent the special locale-dependent
1444 * characters in a number, for example the percent sign. This API is not
1445 * supported for rule-based formatters.
1446 * @param fmt The formatter to query.
1447 * @param symbol The UNumberFormatSymbol constant for the symbol to get
1448 * @param buffer The string buffer that will receive the symbol string;
1449 *               if it is NULL, then only the length of the symbol is returned
1450 * @param size The size of the string buffer
1451 * @param status A pointer to an UErrorCode to receive any errors
1452 * @return The length of the symbol; the buffer is not modified if
1453 *         <code>length&gt;=size</code>
1454 * @see unum_setSymbol
1455 * @stable ICU 2.0
1456 */
1457 U_CAPI int32_t U_EXPORT2
1458 unum_getSymbol(const UNumberFormat *fmt,
1459                UNumberFormatSymbol symbol,
1460                UChar *buffer,
1461                int32_t size,
1462                UErrorCode *status);
1463 
1464 /**
1465 * Set a symbol associated with a UNumberFormat.
1466 * A UNumberFormat uses symbols to represent the special locale-dependent
1467 * characters in a number, for example the percent sign.  This API is not
1468 * supported for rule-based formatters.
1469 * @param fmt The formatter to set.
1470 * @param symbol The UNumberFormatSymbol constant for the symbol to set
1471 * @param value The string to set the symbol to
1472 * @param length The length of the string, or -1 for a zero-terminated string
1473 * @param status A pointer to an UErrorCode to receive any errors.
1474 * @see unum_getSymbol
1475 * @stable ICU 2.0
1476 */
1477 U_CAPI void U_EXPORT2
1478 unum_setSymbol(UNumberFormat *fmt,
1479                UNumberFormatSymbol symbol,
1480                const UChar *value,
1481                int32_t length,
1482                UErrorCode *status);
1483 
1484 
1485 /**
1486  * Get the locale for this number format object.
1487  * You can choose between valid and actual locale.
1488  * @param fmt The formatter to get the locale from
1489  * @param type type of the locale we're looking for (valid or actual)
1490  * @param status error code for the operation
1491  * @return the locale name
1492  * @stable ICU 2.8
1493  */
1494 U_CAPI const char* U_EXPORT2
1495 unum_getLocaleByType(const UNumberFormat *fmt,
1496                      ULocDataLocaleType type,
1497                      UErrorCode* status);
1498 
1499 /**
1500  * Set a particular UDisplayContext value in the formatter, such as
1501  * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1502  * @param fmt The formatter for which to set a UDisplayContext value.
1503  * @param value The UDisplayContext value to set.
1504  * @param status A pointer to an UErrorCode to receive any errors
1505  * @stable ICU 53
1506  */
1507 U_CAPI void U_EXPORT2
1508 unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status);
1509 
1510 /**
1511  * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1512  * such as UDISPCTX_TYPE_CAPITALIZATION.
1513  * @param fmt The formatter to query.
1514  * @param type The UDisplayContextType whose value to return
1515  * @param status A pointer to an UErrorCode to receive any errors
1516  * @return The UDisplayContextValue for the specified type.
1517  * @stable ICU 53
1518  */
1519 U_CAPI UDisplayContext U_EXPORT2
1520 unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status);
1521 
1522 #endif /* #if !UCONFIG_NO_FORMATTING */
1523 
1524 #endif
1525