1 // © 2018 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 4 #ifndef __UNUMBERFORMATTER_H__ 5 #define __UNUMBERFORMATTER_H__ 6 7 #include "unicode/utypes.h" 8 9 #if !UCONFIG_NO_FORMATTING 10 11 #include "unicode/parseerr.h" 12 #include "unicode/ufieldpositer.h" 13 #include "unicode/umisc.h" 14 15 16 /** 17 * \file 18 * \brief C API: Localized number formatting; not recommended for C++. 19 * 20 * This is the C-compatible version of the NumberFormatter API introduced in ICU 60. C++ users should 21 * include unicode/numberformatter.h and use the proper C++ APIs. 22 * 23 * The C API accepts a number skeleton string for specifying the settings for formatting, which covers a 24 * very large subset of all possible number formatting features. For more information on number skeleton 25 * strings, see unicode/numberformatter.h. 26 * 27 * When using UNumberFormatter, which is treated as immutable, the results are exported to a mutable 28 * UFormattedNumber object, which you subsequently use for populating your string buffer or iterating over 29 * the fields. 30 * 31 * Example code: 32 * <pre> 33 * // Setup: 34 * UErrorCode ec = U_ZERO_ERROR; 35 * UNumberFormatter* uformatter = unumf_openForSkeletonAndLocale(u"precision-integer", -1, "en", &ec); 36 * UFormattedNumber* uresult = unumf_openResult(&ec); 37 * if (U_FAILURE(ec)) { return; } 38 * 39 * // Format a double: 40 * unumf_formatDouble(uformatter, 5142.3, uresult, &ec); 41 * if (U_FAILURE(ec)) { return; } 42 * 43 * // Export the string to a malloc'd buffer: 44 * int32_t len = unumf_resultToString(uresult, NULL, 0, &ec); 45 * // at this point, ec == U_BUFFER_OVERFLOW_ERROR 46 * ec = U_ZERO_ERROR; 47 * UChar* buffer = (UChar*) malloc((len+1)*sizeof(UChar)); 48 * unumf_resultToString(uresult, buffer, len+1, &ec); 49 * if (U_FAILURE(ec)) { return; } 50 * // buffer should equal "5,142" 51 * 52 * // Cleanup: 53 * unumf_close(uformatter); 54 * unumf_closeResult(uresult); 55 * free(buffer); 56 * </pre> 57 * 58 * If you are a C++ user linking against the C libraries, you can use the LocalPointer versions of these 59 * APIs. The following example uses LocalPointer with the decimal number and field position APIs: 60 * 61 * <pre> 62 * // Setup: 63 * LocalUNumberFormatterPointer uformatter(unumf_openForSkeletonAndLocale(u"percent", -1, "en", &ec)); 64 * LocalUFormattedNumberPointer uresult(unumf_openResult(&ec)); 65 * if (U_FAILURE(ec)) { return; } 66 * 67 * // Format a decimal number: 68 * unumf_formatDecimal(uformatter.getAlias(), "9.87E-3", -1, uresult.getAlias(), &ec); 69 * if (U_FAILURE(ec)) { return; } 70 * 71 * // Get the location of the percent sign: 72 * UFieldPosition ufpos = {UNUM_PERCENT_FIELD, 0, 0}; 73 * unumf_resultNextFieldPosition(uresult.getAlias(), &ufpos, &ec); 74 * // ufpos should contain beginIndex=7 and endIndex=8 since the string is "0.00987%" 75 * 76 * // No need to do any cleanup since we are using LocalPointer. 77 * </pre> 78 */ 79 80 /** 81 * An enum declaring how to resolve conflicts between maximum fraction digits and maximum 82 * significant digits. 83 * 84 * There are two modes, RELAXED and STRICT: 85 * 86 * - RELAXED: Relax one of the two constraints (fraction digits or significant digits) in order 87 * to round the number to a higher level of precision. 88 * - STRICT: Enforce both constraints, resulting in the number being rounded to a lower 89 * level of precision. 90 * 91 * The default settings for compact notation rounding are Max-Fraction = 0 (round to the nearest 92 * integer), Max-Significant = 2 (round to 2 significant digits), and priority RELAXED (choose 93 * the constraint that results in more digits being displayed). 94 * 95 * Conflicting *minimum* fraction and significant digits are always resolved in the direction that 96 * results in more trailing zeros. 97 * 98 * Example 1: Consider the number 3.141, with various different settings: 99 * 100 * - Max-Fraction = 1: "3.1" 101 * - Max-Significant = 3: "3.14" 102 * 103 * The rounding priority determines how to resolve the conflict when both Max-Fraction and 104 * Max-Significant are set. With RELAXED, the less-strict setting (the one that causes more digits 105 * to be displayed) will be used; Max-Significant wins. With STRICT, the more-strict setting (the 106 * one that causes fewer digits to be displayed) will be used; Max-Fraction wins. 107 * 108 * Example 2: Consider the number 8317, with various different settings: 109 * 110 * - Max-Fraction = 1: "8317" 111 * - Max-Significant = 3: "8320" 112 * 113 * Here, RELAXED favors Max-Fraction and STRICT favors Max-Significant. Note that this larger 114 * number caused the two modes to favor the opposite result. 115 * 116 * @stable ICU 69 117 */ 118 typedef enum UNumberRoundingPriority { 119 /** 120 * Favor greater precision by relaxing one of the rounding constraints. 121 * 122 * @stable ICU 69 123 */ 124 UNUM_ROUNDING_PRIORITY_RELAXED, 125 126 /** 127 * Favor adherence to all rounding constraints by producing lower precision. 128 * 129 * @stable ICU 69 130 */ 131 UNUM_ROUNDING_PRIORITY_STRICT, 132 } UNumberRoundingPriority; 133 134 /** 135 * An enum declaring how to render units, including currencies. Example outputs when formatting 123 USD and 123 136 * meters in <em>en-CA</em>: 137 * 138 * <p> 139 * <ul> 140 * <li>NARROW*: "$123.00" and "123 m" 141 * <li>SHORT: "US$ 123.00" and "123 m" 142 * <li>FULL_NAME: "123.00 US dollars" and "123 meters" 143 * <li>ISO_CODE: "USD 123.00" and undefined behavior 144 * <li>HIDDEN: "123.00" and "123" 145 * </ul> 146 * 147 * <p> 148 * This enum is similar to {@link UMeasureFormatWidth}. 149 * 150 * @stable ICU 60 151 */ 152 typedef enum UNumberUnitWidth { 153 /** 154 * Print an abbreviated version of the unit name. Similar to SHORT, but always use the shortest available 155 * abbreviation or symbol. This option can be used when the context hints at the identity of the unit. For more 156 * information on the difference between NARROW and SHORT, see SHORT. 157 * 158 * <p> 159 * In CLDR, this option corresponds to the "Narrow" format for measure units and the "¤¤¤¤¤" placeholder for 160 * currencies. 161 * 162 * @stable ICU 60 163 */ 164 UNUM_UNIT_WIDTH_NARROW = 0, 165 166 /** 167 * Print an abbreviated version of the unit name. Similar to NARROW, but use a slightly wider abbreviation or 168 * symbol when there may be ambiguity. This is the default behavior. 169 * 170 * <p> 171 * For example, in <em>es-US</em>, the SHORT form for Fahrenheit is "{0} °F", but the NARROW form is "{0}°", 172 * since Fahrenheit is the customary unit for temperature in that locale. 173 * 174 * <p> 175 * In CLDR, this option corresponds to the "Short" format for measure units and the "¤" placeholder for 176 * currencies. 177 * 178 * @stable ICU 60 179 */ 180 UNUM_UNIT_WIDTH_SHORT = 1, 181 182 /** 183 * Print the full name of the unit, without any abbreviations. 184 * 185 * <p> 186 * In CLDR, this option corresponds to the default format for measure units and the "¤¤¤" placeholder for 187 * currencies. 188 * 189 * @stable ICU 60 190 */ 191 UNUM_UNIT_WIDTH_FULL_NAME = 2, 192 193 /** 194 * Use the three-digit ISO XXX code in place of the symbol for displaying currencies. The behavior of this 195 * option is currently undefined for use with measure units. 196 * 197 * <p> 198 * In CLDR, this option corresponds to the "¤¤" placeholder for currencies. 199 * 200 * @stable ICU 60 201 */ 202 UNUM_UNIT_WIDTH_ISO_CODE = 3, 203 204 /** 205 * Use the formal variant of the currency symbol; for example, "NT$" for the New Taiwan 206 * dollar in zh-TW. 207 * 208 * <p> 209 * Behavior of this option with non-currency units is not defined at this time. 210 * 211 * @stable ICU 68 212 */ 213 UNUM_UNIT_WIDTH_FORMAL = 4, 214 215 /** 216 * Use the alternate variant of the currency symbol; for example, "TL" for the Turkish 217 * lira (TRY). 218 * 219 * <p> 220 * Behavior of this option with non-currency units is not defined at this time. 221 * 222 * @stable ICU 68 223 */ 224 UNUM_UNIT_WIDTH_VARIANT = 5, 225 226 /** 227 * Format the number according to the specified unit, but do not display the unit. For currencies, apply 228 * monetary symbols and formats as with SHORT, but omit the currency symbol. For measure units, the behavior is 229 * equivalent to not specifying the unit at all. 230 * 231 * @stable ICU 60 232 */ 233 UNUM_UNIT_WIDTH_HIDDEN = 6, 234 235 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, 236 // needed for unconditionalized struct MacroProps 237 /** 238 * One more than the highest UNumberUnitWidth value. 239 * 240 * @internal ICU 60: The numeric value may change over time; see ICU ticket #12420. 241 */ 242 UNUM_UNIT_WIDTH_COUNT = 7 243 } UNumberUnitWidth; 244 245 /** 246 * An enum declaring the strategy for when and how to display grouping separators (i.e., the 247 * separator, often a comma or period, after every 2-3 powers of ten). The choices are several 248 * pre-built strategies for different use cases that employ locale data whenever possible. Example 249 * outputs for 1234 and 1234567 in <em>en-IN</em>: 250 * 251 * <ul> 252 * <li>OFF: 1234 and 12345 253 * <li>MIN2: 1234 and 12,34,567 254 * <li>AUTO: 1,234 and 12,34,567 255 * <li>ON_ALIGNED: 1,234 and 12,34,567 256 * <li>THOUSANDS: 1,234 and 1,234,567 257 * </ul> 258 * 259 * <p> 260 * The default is AUTO, which displays grouping separators unless the locale data says that grouping 261 * is not customary. To force grouping for all numbers greater than 1000 consistently across locales, 262 * use ON_ALIGNED. On the other hand, to display grouping less frequently than the default, use MIN2 263 * or OFF. See the docs of each option for details. 264 * 265 * <p> 266 * Note: This enum specifies the strategy for grouping sizes. To set which character to use as the 267 * grouping separator, use the "symbols" setter. 268 * 269 * @stable ICU 63 270 */ 271 typedef enum UNumberGroupingStrategy { 272 /** 273 * Do not display grouping separators in any locale. 274 * 275 * @stable ICU 61 276 */ 277 UNUM_GROUPING_OFF, 278 279 /** 280 * Display grouping using locale defaults, except do not show grouping on values smaller than 281 * 10000 (such that there is a <em>minimum of two digits</em> before the first separator). 282 * 283 * <p> 284 * Note that locales may restrict grouping separators to be displayed only on 1 million or 285 * greater (for example, ee and hu) or disable grouping altogether (for example, bg currency). 286 * 287 * <p> 288 * Locale data is used to determine whether to separate larger numbers into groups of 2 289 * (customary in South Asia) or groups of 3 (customary in Europe and the Americas). 290 * 291 * @stable ICU 61 292 */ 293 UNUM_GROUPING_MIN2, 294 295 /** 296 * Display grouping using the default strategy for all locales. This is the default behavior. 297 * 298 * <p> 299 * Note that locales may restrict grouping separators to be displayed only on 1 million or 300 * greater (for example, ee and hu) or disable grouping altogether (for example, bg currency). 301 * 302 * <p> 303 * Locale data is used to determine whether to separate larger numbers into groups of 2 304 * (customary in South Asia) or groups of 3 (customary in Europe and the Americas). 305 * 306 * @stable ICU 61 307 */ 308 UNUM_GROUPING_AUTO, 309 310 /** 311 * Always display the grouping separator on values of at least 1000. 312 * 313 * <p> 314 * This option ignores the locale data that restricts or disables grouping, described in MIN2 and 315 * AUTO. This option may be useful to normalize the alignment of numbers, such as in a 316 * spreadsheet. 317 * 318 * <p> 319 * Locale data is used to determine whether to separate larger numbers into groups of 2 320 * (customary in South Asia) or groups of 3 (customary in Europe and the Americas). 321 * 322 * @stable ICU 61 323 */ 324 UNUM_GROUPING_ON_ALIGNED, 325 326 /** 327 * Use the Western defaults: groups of 3 and enabled for all numbers 1000 or greater. Do not use 328 * locale data for determining the grouping strategy. 329 * 330 * @stable ICU 61 331 */ 332 UNUM_GROUPING_THOUSANDS 333 334 #ifndef U_HIDE_INTERNAL_API 335 , 336 /** 337 * One more than the highest UNumberGroupingStrategy value. 338 * 339 * @internal ICU 62: The numeric value may change over time; see ICU ticket #12420. 340 */ 341 UNUM_GROUPING_COUNT 342 #endif /* U_HIDE_INTERNAL_API */ 343 344 } UNumberGroupingStrategy; 345 346 /** 347 * An enum declaring how to denote positive and negative numbers. Example outputs when formatting 348 * 123, 0, and -123 in <em>en-US</em>: 349 * 350 * <ul> 351 * <li>AUTO: "123", "0", and "-123" 352 * <li>ALWAYS: "+123", "+0", and "-123" 353 * <li>NEVER: "123", "0", and "123" 354 * <li>ACCOUNTING: "$123", "$0", and "($123)" 355 * <li>ACCOUNTING_ALWAYS: "+$123", "+$0", and "($123)" 356 * <li>EXCEPT_ZERO: "+123", "0", and "-123" 357 * <li>ACCOUNTING_EXCEPT_ZERO: "+$123", "$0", and "($123)" 358 * </ul> 359 * 360 * <p> 361 * The exact format, including the position and the code point of the sign, differ by locale. 362 * 363 * @stable ICU 60 364 */ 365 typedef enum UNumberSignDisplay { 366 /** 367 * Show the minus sign on negative numbers, and do not show the sign on positive numbers. This is the default 368 * behavior. 369 * 370 * If using this option, a sign will be displayed on negative zero, including negative numbers 371 * that round to zero. To hide the sign on negative zero, use the NEGATIVE option. 372 * 373 * @stable ICU 60 374 */ 375 UNUM_SIGN_AUTO, 376 377 /** 378 * Show the minus sign on negative numbers and the plus sign on positive numbers, including zero. 379 * To hide the sign on zero, see {@link UNUM_SIGN_EXCEPT_ZERO}. 380 * 381 * @stable ICU 60 382 */ 383 UNUM_SIGN_ALWAYS, 384 385 /** 386 * Do not show the sign on positive or negative numbers. 387 * 388 * @stable ICU 60 389 */ 390 UNUM_SIGN_NEVER, 391 392 /** 393 * Use the locale-dependent accounting format on negative numbers, and do not show the sign on positive numbers. 394 * 395 * <p> 396 * The accounting format is defined in CLDR and varies by locale; in many Western locales, the format is a pair 397 * of parentheses around the number. 398 * 399 * <p> 400 * Note: Since CLDR defines the accounting format in the monetary context only, this option falls back to the 401 * AUTO sign display strategy when formatting without a currency unit. This limitation may be lifted in the 402 * future. 403 * 404 * @stable ICU 60 405 */ 406 UNUM_SIGN_ACCOUNTING, 407 408 /** 409 * Use the locale-dependent accounting format on negative numbers, and show the plus sign on 410 * positive numbers, including zero. For more information on the accounting format, see the 411 * ACCOUNTING sign display strategy. To hide the sign on zero, see 412 * {@link UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO}. 413 * 414 * @stable ICU 60 415 */ 416 UNUM_SIGN_ACCOUNTING_ALWAYS, 417 418 /** 419 * Show the minus sign on negative numbers and the plus sign on positive numbers. Do not show a 420 * sign on zero, numbers that round to zero, or NaN. 421 * 422 * @stable ICU 61 423 */ 424 UNUM_SIGN_EXCEPT_ZERO, 425 426 /** 427 * Use the locale-dependent accounting format on negative numbers, and show the plus sign on 428 * positive numbers. Do not show a sign on zero, numbers that round to zero, or NaN. For more 429 * information on the accounting format, see the ACCOUNTING sign display strategy. 430 * 431 * @stable ICU 61 432 */ 433 UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO, 434 435 /** 436 * Same as AUTO, but do not show the sign on negative zero. 437 * 438 * @stable ICU 69 439 */ 440 UNUM_SIGN_NEGATIVE, 441 442 /** 443 * Same as ACCOUNTING, but do not show the sign on negative zero. 444 * 445 * @stable ICU 69 446 */ 447 UNUM_SIGN_ACCOUNTING_NEGATIVE, 448 449 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, 450 // needed for unconditionalized struct MacroProps 451 /** 452 * One more than the highest UNumberSignDisplay value. 453 * 454 * @internal ICU 60: The numeric value may change over time; see ICU ticket #12420. 455 */ 456 UNUM_SIGN_COUNT = 9, 457 } UNumberSignDisplay; 458 459 /** 460 * An enum declaring how to render the decimal separator. 461 * 462 * <p> 463 * <ul> 464 * <li>UNUM_DECIMAL_SEPARATOR_AUTO: "1", "1.1" 465 * <li>UNUM_DECIMAL_SEPARATOR_ALWAYS: "1.", "1.1" 466 * </ul> 467 * 468 * @stable ICU 60 469 */ 470 typedef enum UNumberDecimalSeparatorDisplay { 471 /** 472 * Show the decimal separator when there are one or more digits to display after the separator, and do not show 473 * it otherwise. This is the default behavior. 474 * 475 * @stable ICU 60 476 */ 477 UNUM_DECIMAL_SEPARATOR_AUTO, 478 479 /** 480 * Always show the decimal separator, even if there are no digits to display after the separator. 481 * 482 * @stable ICU 60 483 */ 484 UNUM_DECIMAL_SEPARATOR_ALWAYS, 485 486 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API, 487 // needed for unconditionalized struct MacroProps 488 /** 489 * One more than the highest UNumberDecimalSeparatorDisplay value. 490 * 491 * @internal ICU 60: The numeric value may change over time; see ICU ticket #12420. 492 */ 493 UNUM_DECIMAL_SEPARATOR_COUNT 494 } UNumberDecimalSeparatorDisplay; 495 496 /** 497 * An enum declaring how to render trailing zeros. 498 * 499 * - UNUM_TRAILING_ZERO_AUTO: 0.90, 1.00, 1.10 500 * - UNUM_TRAILING_ZERO_HIDE_IF_WHOLE: 0.90, 1, 1.10 501 * 502 * @stable ICU 69 503 */ 504 typedef enum UNumberTrailingZeroDisplay { 505 /** 506 * Display trailing zeros according to the settings for minimum fraction and significant digits. 507 * 508 * @stable ICU 69 509 */ 510 UNUM_TRAILING_ZERO_AUTO, 511 512 /** 513 * Same as AUTO, but hide trailing zeros after the decimal separator if they are all zero. 514 * 515 * @stable ICU 69 516 */ 517 UNUM_TRAILING_ZERO_HIDE_IF_WHOLE, 518 } UNumberTrailingZeroDisplay; 519 520 struct UNumberFormatter; 521 /** 522 * C-compatible version of icu::number::LocalizedNumberFormatter. 523 * 524 * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead. 525 * 526 * @stable ICU 62 527 */ 528 typedef struct UNumberFormatter UNumberFormatter; 529 530 struct UFormattedNumber; 531 /** 532 * C-compatible version of icu::number::FormattedNumber. 533 * 534 * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead. 535 * 536 * @stable ICU 62 537 */ 538 typedef struct UFormattedNumber UFormattedNumber; 539 540 541 /** 542 * Creates a new UNumberFormatter for the given skeleton string and locale. This is currently the only 543 * method for creating a new UNumberFormatter. 544 * 545 * Objects of type UNumberFormatter returned by this method are threadsafe. 546 * 547 * For more details on skeleton strings, see the documentation in numberformatter.h. For more details on 548 * the usage of this API, see the documentation at the top of unumberformatter.h. 549 * 550 * For more information on number skeleton strings, see: 551 * https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html 552 * 553 * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead. 554 * 555 * @param skeleton The skeleton string, like u"percent precision-integer" 556 * @param skeletonLen The number of UChars in the skeleton string, or -1 if it is NUL-terminated. 557 * @param locale The NUL-terminated locale ID. 558 * @param ec Set if an error occurs. 559 * @stable ICU 62 560 */ 561 U_CAPI UNumberFormatter* U_EXPORT2 562 unumf_openForSkeletonAndLocale(const UChar* skeleton, int32_t skeletonLen, const char* locale, 563 UErrorCode* ec); 564 565 566 /** 567 * Like unumf_openForSkeletonAndLocale, but accepts a UParseError, which will be populated with the 568 * location of a skeleton syntax error if such a syntax error exists. 569 * 570 * For more information on number skeleton strings, see: 571 * https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html 572 * 573 * @param skeleton The skeleton string, like u"percent precision-integer" 574 * @param skeletonLen The number of UChars in the skeleton string, or -1 if it is NUL-terminated. 575 * @param locale The NUL-terminated locale ID. 576 * @param perror A parse error struct populated if an error occurs when parsing. Can be NULL. 577 * If no error occurs, perror->offset will be set to -1. 578 * @param ec Set if an error occurs. 579 * @stable ICU 64 580 */ 581 U_CAPI UNumberFormatter* U_EXPORT2 582 unumf_openForSkeletonAndLocaleWithError( 583 const UChar* skeleton, int32_t skeletonLen, const char* locale, UParseError* perror, UErrorCode* ec); 584 585 586 587 /** 588 * Uses a UNumberFormatter to format an integer to a UFormattedNumber. A string, field position, and other 589 * information can be retrieved from the UFormattedNumber. 590 * 591 * The UNumberFormatter can be shared between threads. Each thread should have its own local 592 * UFormattedNumber, however, for storing the result of the formatting operation. 593 * 594 * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead. 595 * 596 * @param uformatter A formatter object created by unumf_openForSkeletonAndLocale or similar. 597 * @param value The number to be formatted. 598 * @param uresult The object that will be mutated to store the result; see unumf_openResult. 599 * @param ec Set if an error occurs. 600 * @stable ICU 62 601 */ 602 U_CAPI void U_EXPORT2 603 unumf_formatInt(const UNumberFormatter* uformatter, int64_t value, UFormattedNumber* uresult, 604 UErrorCode* ec); 605 606 607 /** 608 * Uses a UNumberFormatter to format a double to a UFormattedNumber. A string, field position, and other 609 * information can be retrieved from the UFormattedNumber. 610 * 611 * The UNumberFormatter can be shared between threads. Each thread should have its own local 612 * UFormattedNumber, however, for storing the result of the formatting operation. 613 * 614 * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead. 615 * 616 * @param uformatter A formatter object created by unumf_openForSkeletonAndLocale or similar. 617 * @param value The number to be formatted. 618 * @param uresult The object that will be mutated to store the result; see unumf_openResult. 619 * @param ec Set if an error occurs. 620 * @stable ICU 62 621 */ 622 U_CAPI void U_EXPORT2 623 unumf_formatDouble(const UNumberFormatter* uformatter, double value, UFormattedNumber* uresult, 624 UErrorCode* ec); 625 626 627 /** 628 * Uses a UNumberFormatter to format a decimal number to a UFormattedNumber. A string, field position, and 629 * other information can be retrieved from the UFormattedNumber. 630 * 631 * The UNumberFormatter can be shared between threads. Each thread should have its own local 632 * UFormattedNumber, however, for storing the result of the formatting operation. 633 * 634 * The syntax of the unformatted number is a "numeric string" as defined in the Decimal Arithmetic 635 * Specification, available at http://speleotrove.com/decimal 636 * 637 * NOTE: This is a C-compatible API; C++ users should build against numberformatter.h instead. 638 * 639 * @param uformatter A formatter object created by unumf_openForSkeletonAndLocale or similar. 640 * @param value The numeric string to be formatted. 641 * @param valueLen The length of the numeric string, or -1 if it is NUL-terminated. 642 * @param uresult The object that will be mutated to store the result; see unumf_openResult. 643 * @param ec Set if an error occurs. 644 * @stable ICU 62 645 */ 646 U_CAPI void U_EXPORT2 647 unumf_formatDecimal(const UNumberFormatter* uformatter, const char* value, int32_t valueLen, 648 UFormattedNumber* uresult, UErrorCode* ec); 649 650 651 652 653 654 655 /** 656 * Releases the UNumberFormatter created by unumf_openForSkeletonAndLocale(). 657 * 658 * @param uformatter An object created by unumf_openForSkeletonAndLocale(). 659 * @stable ICU 62 660 */ 661 U_CAPI void U_EXPORT2 662 unumf_close(UNumberFormatter* uformatter); 663 664 665 666 #if U_SHOW_CPLUSPLUS_API 667 U_NAMESPACE_BEGIN 668 669 /** 670 * \class LocalUNumberFormatterPointer 671 * "Smart pointer" class; closes a UNumberFormatter via unumf_close(). 672 * For most methods see the LocalPointerBase base class. 673 * 674 * Usage: 675 * <pre> 676 * LocalUNumberFormatterPointer uformatter(unumf_openForSkeletonAndLocale(...)); 677 * // no need to explicitly call unumf_close() 678 * </pre> 679 * 680 * @see LocalPointerBase 681 * @see LocalPointer 682 * @stable ICU 62 683 */ 684 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberFormatterPointer, UNumberFormatter, unumf_close); 685 686 /** 687 * \class LocalUFormattedNumberPointer 688 * "Smart pointer" class; closes a UFormattedNumber via unumf_closeResult(). 689 * For most methods see the LocalPointerBase base class. 690 * 691 * Usage: 692 * <pre> 693 * LocalUFormattedNumberPointer uformatter(unumf_openResult(...)); 694 * // no need to explicitly call unumf_closeResult() 695 * </pre> 696 * 697 * @see LocalPointerBase 698 * @see LocalPointer 699 * @stable ICU 62 700 */ 701 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFormattedNumberPointer, UFormattedNumber, unumf_closeResult); 702 703 U_NAMESPACE_END 704 #endif // U_SHOW_CPLUSPLUS_API 705 706 #endif /* #if !UCONFIG_NO_FORMATTING */ 707 #endif //__UNUMBERFORMATTER_H__ 708