Loading...
Searching...
No Matches
icu::number::FormattedNumber Class Reference

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

`#include <formattednumber.h>`

Inheritance diagram for icu::number::FormattedNumber:

## Public Member Functions

| FormattedNumber ()
| Default constructor; makes an empty FormattedNumber.
| FormattedNumber (FormattedNumber &&src) noexcept
| Move constructor: Leaves the source FormattedNumber in an undefined state.
virtual | ~FormattedNumber () override
| Destruct an instance of FormattedNumber.
| FormattedNumber (const FormattedNumber &)=delete
| Copying not supported; use move constructor instead.
FormattedNumber & | operator= (const FormattedNumber &)=delete
| Copying not supported; use move assignment instead.
FormattedNumber & | operator= (FormattedNumber &&src) noexcept
| Move assignment: Leaves the source FormattedNumber in an undefined state.
UnicodeString | toString (UErrorCode &status) const override
| Returns the formatted string as a self-contained UnicodeString.
UnicodeString | toTempString (UErrorCode &status) const override
| Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
Appendable & | appendTo (Appendable &appendable, UErrorCode &status) const override
| Appends the formatted string to an Appendable.
UBool | nextPosition (ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
| Iterates over field positions in the FormattedValue.
template<typename StringClass>
StringClass | toDecimalNumber (UErrorCode &status) const
| Export the formatted number as a "numeric string" conforming to the syntax defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal.
MeasureUnit | getOutputUnit (UErrorCode &status) const
| Gets the resolved output unit.
UDisplayOptionsNounClass | getNounClass (UErrorCode &status) const
| Gets the noun class of the formatted output.
void | getDecimalQuantity (impl::DecimalQuantity &output, UErrorCode &status) const
| Gets the raw DecimalQuantity for plural rule selection.
void | getAllFieldPositionsImpl (FieldPositionIteratorHandler &fpih, UErrorCode &status) const
| Populates the mutable builder type FieldPositionIteratorHandler.
Public Member Functions inherited from icu::FormattedValue
virtual | ~FormattedValue ()

## Friends

class | LocalizedNumberFormatter
class | SimpleNumberFormatter
struct | impl::UFormattedNumberImpl
class | icu::SimpleDateFormat

## 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.

Instances of this class are immutable and thread-safe.

Stable
  ICU 60

Definition at line 48 of file formattednumber.h.

## Constructor & Destructor Documentation

## FormattedNumber() [1/2]

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

inline

Default constructor; makes an empty FormattedNumber.

Stable
  ICU 64

Definition at line 55 of file formattednumber.h.

References U_INVALID_STATE_ERROR.

Referenced by FormattedNumber(), FormattedNumber(), getAllFieldPositionsImpl(), operator=(), and operator=().

## FormattedNumber() [2/2]

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

noexcept

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

Stable
  ICU 62

References FormattedNumber().

## ~FormattedNumber()

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

override virtual

Destruct an instance of FormattedNumber.

Stable
  ICU 60

## Member Function Documentation

## appendTo()

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

override virtual

Appends the formatted string to an Appendable.

For more information, see FormattedValue::appendTo()

Stable
  ICU 62

Implements icu::FormattedValue.

## 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.

References FormattedNumber(), and U_ZERO_ERROR.

## 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.

## getNounClass()

UDisplayOptionsNounClass icu::number::FormattedNumber::getNounClass | ( | UErrorCode & | status | ) | const

Gets the noun class of the formatted output.

Returns UNDEFINED when the noun class is not supported yet.

Returns
  UDisplayOptionsNounClass

Stable
  ICU 72

## getOutputUnit()

MeasureUnit icu::number::FormattedNumber::getOutputUnit | ( | UErrorCode & | status | ) | const

Gets the resolved output unit.

The output unit is dependent upon the localized preferences for the usage specified via NumberFormatterSettings::usage(), and may be a unit with UMEASURE_UNIT_MIXED unit complexity (MeasureUnit::getComplexity()), such as "foot-and-inch" or "hour-and-minute-and-second".

Returns
  MeasureUnit.

Stable
  ICU 68

## nextPosition()

UBool icu::number::FormattedNumber::nextPosition | ( | ConstrainedFieldPosition & | cfpos,
|  | UErrorCode & | status ) const

override virtual

Iterates over field positions in the FormattedValue.

This lets you determine the position of specific types of substrings, like a month or a decimal separator.

To loop over all field positions:

    ConstrainedFieldPosition cfpos;
    while (fmtval.nextPosition(cfpos, status)) {
        // handle the field position; get information from cfpos
    }

Parameters

  cfpos | The object used for iteration state. This can provide constraints to iterate over only one specific category or field; see ConstrainedFieldPosition::constrainCategory and ConstrainedFieldPosition::constrainField.
  status | Set if an error occurs.

Returns
  true if a new occurrence of the field was found; false otherwise or if an error was set.

Stable
  ICU 64

Implements icu::FormattedValue.

References toDecimalNumber().

## operator=()

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

noexcept

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

Stable
  ICU 62

References FormattedNumber().

## toDecimalNumber()

template<typename StringClass>

StringClass icu::number::FormattedNumber::toDecimalNumber | ( | UErrorCode & | status | ) | const

inline

Export the formatted number as a "numeric string" conforming to the syntax defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal.

This endpoint is useful for obtaining the exact number being printed after scaling and rounding have been applied by the number formatter.

Example call site:

    auto decimalNumber = fn.toDecimalNumber<std::string>(status);

Template Parameters

  StringClass | A string class compatible with StringByteSink; for example, std::string.

Parameters

  status | Set if an error occurs.

Returns
  A StringClass containing the numeric string.

Stable
  ICU 65

Definition at line 199 of file formattednumber.h.

References toDecimalNumber().

Referenced by nextPosition(), and toDecimalNumber().

## toString()

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

override virtual

Returns the formatted string as a self-contained UnicodeString.

For more information, see FormattedValue::toString()

Stable
  ICU 62

Implements icu::FormattedValue.

## toTempString()

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

override virtual

Returns the formatted string as a read-only alias to memory owned by the FormattedValue.

The return value is valid only as long as this FormattedValue is present and unchanged in memory. If you need the string outside the current scope, consider toString.

The buffer returned by calling UnicodeString::getBuffer() on the return value is guaranteed to be NUL-terminated.

Parameters

  status | Set if an error occurs.

Returns
  a temporary UnicodeString containing the formatted string.

Stable
  ICU 64

Implements icu::FormattedValue.

## Friends And Related Symbol Documentation

## icu::SimpleDateFormat

friend class icu::SimpleDateFormat

friend

Definition at line 195 of file formattednumber.h.

## impl::UFormattedNumberImpl

friend struct impl::UFormattedNumberImpl

friend

Definition at line 192 of file formattednumber.h.

## LocalizedNumberFormatter

friend class LocalizedNumberFormatter

friend

Definition at line 188 of file formattednumber.h.

## SimpleNumberFormatter

friend class SimpleNumberFormatter

friend

Definition at line 189 of file formattednumber.h.

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

- i18n/unicode/formattednumber.h