ICU 63.1 63.1

Public Member Functions | Friends
icu::number::FormattedNumber Class Reference

The result of a number formatting operation. More...

`#include <numberformatter.h>`

Inheritance diagram for icu::number::FormattedNumber:

## Public Member Functions
UnicodeString | toString () const
| Returns a UnicodeString representation of the formatted number. More...
UnicodeString | toString (UErrorCode &status) const
| Returns a UnicodeString representation of the formatted number. More...
Appendable & | appendTo (Appendable &appendable)
| Appends the formatted number to an Appendable. More...
Appendable & | appendTo (Appendable &appendable, UErrorCode &status) const
| Appends the formatted number to an Appendable. More...
void | populateFieldPosition (FieldPosition &fieldPosition, UErrorCode &status)
| Determine the start and end indices of the first occurrence of the given field in the output string. More...
UBool | nextFieldPosition (FieldPosition &fieldPosition, UErrorCode &status) const
| Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given field in the output string. More...
void | populateFieldPositionIterator (FieldPositionIterator &iterator, UErrorCode &status)
| Export the formatted number to a FieldPositionIterator. More...
void | getAllFieldPositions (FieldPositionIterator &iterator, UErrorCode &status) const
| Export the formatted number to a FieldPositionIterator. More...
void | getDecimalQuantity (impl::DecimalQuantity &output, UErrorCode &status) const
| Gets the raw DecimalQuantity for plural rule selection. More...
void | getAllFieldPositionsImpl (FieldPositionIteratorHandler &fpih, UErrorCode &status) const
| Populates the mutable builder type FieldPositionIteratorHandler. More...
| FormattedNumber (const FormattedNumber &)=delete
| Copying not supported; use move constructor instead.
FormattedNumber & | operator= (const FormattedNumber &)=delete
| Copying not supported; use move assignment instead.
| FormattedNumber (FormattedNumber &&src) U_NOEXCEPT
| Move constructor: Leaves the source FormattedNumber in an undefined state. More...
FormattedNumber & | operator= (FormattedNumber &&src) U_NOEXCEPT
| Move assignment: Leaves the source FormattedNumber in an undefined state. More...
| ~FormattedNumber ()
| Destruct an instance of FormattedNumber, cleaning up any memory it might own. More...

## Friends
class | LocalizedNumberFormatter

## Detailed Description

The result of a number formatting operation.

This class allows the result to be exported in several data types, including a UnicodeString and a FieldPositionIterator.

Draft:
  This API may be changed in the future versions and was introduced in ICU 60

Definition at line 2438 of file numberformatter.h.

## Constructor & Destructor Documentation

## ◆ FormattedNumber()

icu::number::FormattedNumber::FormattedNumber | ( | FormattedNumber && | src | ) |

Move constructor: Leaves the source FormattedNumber in an undefined state.

Draft:
  This API may be changed in the future versions and was introduced in ICU 62

## ◆ ~FormattedNumber()

icu::number::FormattedNumber::~FormattedNumber | ( |  | ) |

Destruct an instance of FormattedNumber, cleaning up any memory it might own.

Draft:
  This API may be changed in the future versions and was introduced in ICU 60

## Member Function Documentation

## ◆ appendTo() [1/2]

Appendable& icu::number::FormattedNumber::appendTo | ( | Appendable & | appendable | ) |

Appends the formatted number to an Appendable.

Parameters

  appendable | The Appendable to which to append the formatted number string.

Returns
  The same Appendable, for chaining.

Deprecated:
  ICU 62 Use the version of this method with an error code instead. This method was never

Stable:
  and will be removed in a future release. See http://bugs.icu-project.org/trac/ticket/13746

See also
  Appendable

## ◆ appendTo() [2/2]

Appendable& icu::number::FormattedNumber::appendTo | ( | Appendable & | appendable,
|  | UErrorCode & | status
| ) |  | const

Appends the formatted number to an Appendable.

Parameters

  appendable | The Appendable to which to append the formatted number string.
  status | Set if an error occurs while formatting the number to the Appendable.

Returns
  The same Appendable, for chaining.

Draft:
  This API may be changed in the future versions and was introduced in ICU 62

See also
  Appendable

## ◆ getAllFieldPositions()

void icu::number::FormattedNumber::getAllFieldPositions | ( | FieldPositionIterator & | iterator,
|  | UErrorCode & | status
| ) |  | const

Export the formatted number to a FieldPositionIterator.

This allows you to determine which characters in the output string correspond to which fields, such as the integer part, fraction part, and sign.

If information on only one field is needed, use nextFieldPosition() instead.

Parameters

  iterator | The FieldPositionIterator to populate with all of the fields present in the formatted number.
  status | Set if an error occurs while populating the FieldPositionIterator.

Draft:
  This API may be changed in the future versions and was introduced in ICU 62

See also
  UNumberFormatFields

## ◆ getAllFieldPositionsImpl()

void icu::number::FormattedNumber::getAllFieldPositionsImpl | ( | FieldPositionIteratorHandler & | fpih,
|  | UErrorCode & | status
| ) |  | const

Populates the mutable builder type FieldPositionIteratorHandler.

Internal:
  Do not use. This API is for internal use only.

## ◆ getDecimalQuantity()

void icu::number::FormattedNumber::getDecimalQuantity | ( | impl::DecimalQuantity & | output,
|  | UErrorCode & | status
| ) |  | const

Gets the raw DecimalQuantity for plural rule selection.

Internal:
  Do not use. This API is for internal use only.

## ◆ nextFieldPosition()

UBool icu::number::FormattedNumber::nextFieldPosition | ( | FieldPosition & | fieldPosition,
|  | UErrorCode & | status
| ) |  | const

Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given field in the output string.

This allows you to determine the locations of, for example, the integer part, fraction part, or symbols.

If a field occurs just once, calling this method will find that occurrence and return it. If a field occurs multiple times, this method may be called repeatedly with the following pattern:

    FieldPosition fpos(UNUM_GROUPING_SEPARATOR_FIELD);
    while (formattedNumber.nextFieldPosition(fpos, status)) {
      // do something with fpos.
    }

This method is useful if you know which field to query. If you want all available field position information, use getAllFieldPositions().

Parameters

  fieldPosition | Input+output variable. On input, the "field" property determines which field to look up, and the "beginIndex" and "endIndex" properties determine where to begin the search. On output, the "beginIndex" is set to the beginning of the first occurrence of the field with either begin or end indices after the input indices; "endIndex" is set to the end of that occurrence of the field (exclusive index). If a field position is not found, the method returns FALSE and the FieldPosition may or may not be changed.
  status | Set if an error occurs while populating the FieldPosition.

Returns
  TRUE if a new occurrence of the field was found; FALSE otherwise.

Draft:
  This API may be changed in the future versions and was introduced in ICU 62

See also
  UNumberFormatFields

## ◆ operator=()

FormattedNumber& icu::number::FormattedNumber::operator= | ( | FormattedNumber && | src | ) |

Move assignment: Leaves the source FormattedNumber in an undefined state.

Draft:
  This API may be changed in the future versions and was introduced in ICU 62

## ◆ populateFieldPosition()

void icu::number::FormattedNumber::populateFieldPosition | ( | FieldPosition & | fieldPosition,
|  | UErrorCode & | status
| ) |  |

Determine the start and end indices of the first occurrence of the given field in the output string.

This allows you to determine the locations of the integer part, fraction part, and sign.

If multiple different field attributes are needed, this method can be called repeatedly, or if all field attributes are needed, consider using populateFieldPositionIterator().

If a field occurs multiple times in an output string, such as a grouping separator, this method will only ever return the first occurrence. Use populateFieldPositionIterator() to access all occurrences of an attribute.

Parameters

  fieldPosition | The FieldPosition to populate with the start and end indices of the desired field.
  status | Set if an error occurs while populating the FieldPosition.

Deprecated:
  ICU 62 Use nextFieldPosition instead. This method will be removed in a future release. See http://bugs.icu-project.org/trac/ticket/13746

See also
  UNumberFormatFields

## ◆ populateFieldPositionIterator()

void icu::number::FormattedNumber::populateFieldPositionIterator | ( | FieldPositionIterator & | iterator,
|  | UErrorCode & | status
| ) |  |

Export the formatted number to a FieldPositionIterator.

This allows you to determine which characters in the output string correspond to which fields, such as the integer part, fraction part, and sign.

If information on only one field is needed, consider using populateFieldPosition() instead.

Parameters

  iterator | The FieldPositionIterator to populate with all of the fields present in the formatted number.
  status | Set if an error occurs while populating the FieldPositionIterator.

Deprecated:
  ICU 62 Use getAllFieldPositions instead. This method will be removed in a future release. See http://bugs.icu-project.org/trac/ticket/13746

See also
  UNumberFormatFields

## ◆ toString() [1/2]

UnicodeString icu::number::FormattedNumber::toString | ( |  | ) | const

Returns a UnicodeString representation of the formatted number.

Returns
  a UnicodeString containing the localized number.

Deprecated:
  ICU 62 Use the version of this method with an error code instead. This method was never

Stable:
  and will be removed in a future release. See http://bugs.icu-project.org/trac/ticket/13746

## ◆ toString() [2/2]

UnicodeString icu::number::FormattedNumber::toString | ( | UErrorCode & | status | ) | const

Returns a UnicodeString representation of the formatted number.

Parameters

  status | Set if an error occurs while formatting the number to the UnicodeString.

Returns
  a UnicodeString containing the localized number.

Draft:
  This API may be changed in the future versions and was introduced in ICU 62

The documentation for this class was generated from the following file:

- numberformatter.h