ICU 76.1 76.1
Loading...
Searching...
No Matches
Public Member Functions | Friends
icu::number::LocalizedNumberFormatter Class Reference

A NumberFormatter that has a locale associated with it; this means .format() methods are available. More...

#include <numberformatter.h>

Inheritance diagram for icu::number::LocalizedNumberFormatter:
icu::number::NumberFormatterSettings< LocalizedNumberFormatter > icu::UMemory

Public Member Functions

FormattedNumber formatInt (int64_t value, UErrorCode &status) const
 Format the given integer number to a string using the settings specified in the NumberFormatter fluent setting chain.
 
FormattedNumber formatDouble (double value, UErrorCode &status) const
 Format the given float or double to a string using the settings specified in the NumberFormatter fluent setting chain.
 
FormattedNumber formatDecimal (StringPiece value, UErrorCode &status) const
 Format the given decimal number to a string using the settings specified in the NumberFormatter fluent setting chain.
 
const DecimalFormatSymbolsgetDecimalFormatSymbols () const
 
FormattedNumber formatDecimalQuantity (const impl::DecimalQuantity &dq, UErrorCode &status) const
 Internal method.
 
void getAffixImpl (bool isPrefix, bool isNegative, UnicodeString &result, UErrorCode &status) const
 Internal method for DecimalFormat compatibility.
 
const impl::NumberFormatterImpl * getCompiled () const
 Internal method for testing.
 
int32_t getCallCount () const
 Internal method for testing.
 
FormattoFormat (UErrorCode &status) const
 Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use of this number formatter with APIs that need an object of that type, such as MessageFormat.
 
UnlocalizedNumberFormatter withoutLocale () const &
 Disassociate the locale from this formatter.
 
UnlocalizedNumberFormatter withoutLocale () &&
 Overload of withoutLocale() for use on an rvalue reference.
 
 LocalizedNumberFormatter ()=default
 Default constructor: puts the formatter into a valid but undefined state.
 
 LocalizedNumberFormatter (const LocalizedNumberFormatter &other)
 Returns a copy of this LocalizedNumberFormatter.
 
 LocalizedNumberFormatter (LocalizedNumberFormatter &&src) noexcept
 Move constructor: The source LocalizedNumberFormatter will be left in a valid but undefined state.
 
LocalizedNumberFormatteroperator= (const LocalizedNumberFormatter &other)
 Copy assignment operator.
 
LocalizedNumberFormatteroperator= (LocalizedNumberFormatter &&src) noexcept
 Move assignment operator: The source LocalizedNumberFormatter will be left in a valid but undefined state.
 
void formatImpl (impl::UFormattedNumberData *results, UErrorCode &status) const
 This is the core entrypoint to the number formatting pipeline.
 
 ~LocalizedNumberFormatter ()
 Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.
 
- Public Member Functions inherited from icu::number::NumberFormatterSettings< LocalizedNumberFormatter >
LocalizedNumberFormatter notation (const Notation &notation) const &
 Specifies the notation style (simple, scientific, or compact) for rendering numbers.
 
LocalizedNumberFormatter notation (const Notation &notation) &&
 Overload of notation() for use on an rvalue reference.
 
LocalizedNumberFormatter unit (const icu::MeasureUnit &unit) const &
 Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
 
LocalizedNumberFormatter unit (const icu::MeasureUnit &unit) &&
 Overload of unit() for use on an rvalue reference.
 
LocalizedNumberFormatter adoptUnit (icu::MeasureUnit *unit) const &
 Like unit(), but takes ownership of a pointer.
 
LocalizedNumberFormatter adoptUnit (icu::MeasureUnit *unit) &&
 Overload of adoptUnit() for use on an rvalue reference.
 
LocalizedNumberFormatter perUnit (const icu::MeasureUnit &perUnit) const &
 Sets a unit to be used in the denominator.
 
LocalizedNumberFormatter perUnit (const icu::MeasureUnit &perUnit) &&
 Overload of perUnit() for use on an rvalue reference.
 
LocalizedNumberFormatter adoptPerUnit (icu::MeasureUnit *perUnit) const &
 Like perUnit(), but takes ownership of a pointer.
 
LocalizedNumberFormatter adoptPerUnit (icu::MeasureUnit *perUnit) &&
 Overload of adoptPerUnit() for use on an rvalue reference.
 
LocalizedNumberFormatter precision (const Precision &precision) const &
 Specifies the rounding precision to use when formatting numbers.
 
LocalizedNumberFormatter precision (const Precision &precision) &&
 Overload of precision() for use on an rvalue reference.
 
LocalizedNumberFormatter roundingMode (UNumberFormatRoundingMode roundingMode) const &
 Specifies how to determine the direction to round a number when it has more digits than fit in the desired precision.
 
LocalizedNumberFormatter roundingMode (UNumberFormatRoundingMode roundingMode) &&
 Overload of roundingMode() for use on an rvalue reference.
 
LocalizedNumberFormatter grouping (UNumberGroupingStrategy strategy) const &
 Specifies the grouping strategy to use when formatting numbers.
 
LocalizedNumberFormatter grouping (UNumberGroupingStrategy strategy) &&
 Overload of grouping() for use on an rvalue reference.
 
LocalizedNumberFormatter integerWidth (const IntegerWidth &style) const &
 Specifies the minimum and maximum number of digits to render before the decimal mark.
 
LocalizedNumberFormatter integerWidth (const IntegerWidth &style) &&
 Overload of integerWidth() for use on an rvalue reference.
 
LocalizedNumberFormatter symbols (const DecimalFormatSymbols &symbols) const &
 Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.) to use when rendering numbers.
 
LocalizedNumberFormatter symbols (const DecimalFormatSymbols &symbols) &&
 Overload of symbols() for use on an rvalue reference.
 
LocalizedNumberFormatter adoptSymbols (NumberingSystem *symbols) const &
 Specifies that the given numbering system should be used when fetching symbols.
 
LocalizedNumberFormatter adoptSymbols (NumberingSystem *symbols) &&
 Overload of adoptSymbols() for use on an rvalue reference.
 
LocalizedNumberFormatter unitWidth (UNumberUnitWidth width) const &
 Sets the width of the unit (measure unit or currency).
 
LocalizedNumberFormatter unitWidth (UNumberUnitWidth width) &&
 Overload of unitWidth() for use on an rvalue reference.
 
LocalizedNumberFormatter sign (UNumberSignDisplay style) const &
 Sets the plus/minus sign display strategy.
 
LocalizedNumberFormatter sign (UNumberSignDisplay style) &&
 Overload of sign() for use on an rvalue reference.
 
LocalizedNumberFormatter decimal (UNumberDecimalSeparatorDisplay style) const &
 Sets the decimal separator display strategy.
 
LocalizedNumberFormatter decimal (UNumberDecimalSeparatorDisplay style) &&
 Overload of decimal() for use on an rvalue reference.
 
LocalizedNumberFormatter scale (const Scale &scale) const &
 Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.
 
LocalizedNumberFormatter scale (const Scale &scale) &&
 Overload of scale() for use on an rvalue reference.
 
LocalizedNumberFormatter usage (StringPiece usage) const &
 Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall", etc.)
 
LocalizedNumberFormatter usage (StringPiece usage) &&
 Overload of usage() for use on an rvalue reference.
 
LocalizedNumberFormatter displayOptions (const DisplayOptions &displayOptions) const &
 Specifies the DisplayOptions.
 
LocalizedNumberFormatter displayOptions (const DisplayOptions &displayOptions) &&
 Overload of displayOptions() for use on an rvalue reference.
 
LocalizedNumberFormatter unitDisplayCase (StringPiece unitDisplayCase) const &
 NOTE: Use displayOptions instead.
 
LocalizedNumberFormatter unitDisplayCase (StringPiece unitDisplayCase) &&
 NOTE: Use displayOptions instead.
 
LocalizedNumberFormatter padding (const impl::Padder &padder) const &
 Set the padding strategy.
 
LocalizedNumberFormatter padding (const impl::Padder &padder) &&
 
LocalizedNumberFormatter threshold (int32_t threshold) const &
 Internal fluent setter to support a custom regulation threshold.
 
LocalizedNumberFormatter threshold (int32_t threshold) &&
 
LocalizedNumberFormatter macros (const impl::MacroProps &macros) const &
 Internal fluent setter to overwrite the entire macros object.
 
LocalizedNumberFormatter macros (const impl::MacroProps &macros) &&
 
LocalizedNumberFormatter macros (impl::MacroProps &&macros) const &
 
LocalizedNumberFormatter macros (impl::MacroProps &&macros) &&
 
UnicodeString toSkeleton (UErrorCode &status) const
 Creates a skeleton string representation of this number formatter.
 
LocalPointer< LocalizedNumberFormatterclone () const &
 Returns the current (Un)LocalizedNumberFormatter as a LocalPointer wrapping a heap-allocated copy of the current object.
 
LocalPointer< LocalizedNumberFormatterclone () &&
 Overload of clone for use on an rvalue reference.
 
UBool copyErrorTo (UErrorCode &outErrorCode) const
 Sets the UErrorCode if an error occurred in the fluent chain.
 

Friends

class NumberFormatterSettings< UnlocalizedNumberFormatter >
 
class NumberFormatterSettings< LocalizedNumberFormatter >
 
class UnlocalizedNumberFormatter
 

Detailed Description

A NumberFormatter that has a locale associated with it; this means .format() methods are available.

Instances of this class are immutable and thread-safe.

See also
NumberFormatter
Stable:
ICU 60

Definition at line 2520 of file numberformatter.h.

Constructor & Destructor Documentation

◆ LocalizedNumberFormatter() [1/3]

icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter ( )
default

Default constructor: puts the formatter into a valid but undefined state.

Stable:
ICU 62

◆ LocalizedNumberFormatter() [2/3]

icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter ( const LocalizedNumberFormatter other)

Returns a copy of this LocalizedNumberFormatter.

Stable:
ICU 60

◆ LocalizedNumberFormatter() [3/3]

icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter ( LocalizedNumberFormatter &&  src)
noexcept

Move constructor: The source LocalizedNumberFormatter will be left in a valid but undefined state.

Stable:
ICU 62

◆ ~LocalizedNumberFormatter()

icu::number::LocalizedNumberFormatter::~LocalizedNumberFormatter ( )

Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.

Stable:
ICU 60

Member Function Documentation

◆ formatDecimal()

FormattedNumber icu::number::LocalizedNumberFormatter::formatDecimal ( StringPiece  value,
UErrorCode status 
) const

Format the given decimal number to a string using the settings specified in the NumberFormatter fluent setting chain.

The syntax of the unformatted number is a "numeric string" as defined in the Decimal Arithmetic Specification, available at http://speleotrove.com/decimal

Parameters
valueThe number to format.
statusSet to an ErrorCode if one occurred in the setter chain or during formatting.
Returns
A FormattedNumber object; call .toString() to get the string.
Stable:
ICU 60

◆ formatDecimalQuantity()

FormattedNumber icu::number::LocalizedNumberFormatter::formatDecimalQuantity ( const impl::DecimalQuantity &  dq,
UErrorCode status 
) const

Internal method.

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

◆ formatDouble()

FormattedNumber icu::number::LocalizedNumberFormatter::formatDouble ( double  value,
UErrorCode status 
) const

Format the given float or double to a string using the settings specified in the NumberFormatter fluent setting chain.

Parameters
valueThe number to format.
statusSet to an ErrorCode if one occurred in the setter chain or during formatting.
Returns
A FormattedNumber object; call .toString() to get the string.
Stable:
ICU 60

◆ formatImpl()

void icu::number::LocalizedNumberFormatter::formatImpl ( impl::UFormattedNumberData *  results,
UErrorCode status 
) const

This is the core entrypoint to the number formatting pipeline.

It performs self-regulation: a static code path for the first few calls, and compiling a more efficient data structure if called repeatedly.

This function is very hot, being called in every call to the number formatting pipeline.

Parameters
resultsThe results object. This method will mutate it to save the results.
status
Internal:
Do not use. This API is for internal use only.

◆ formatInt()

FormattedNumber icu::number::LocalizedNumberFormatter::formatInt ( int64_t  value,
UErrorCode status 
) const

Format the given integer number to a string using the settings specified in the NumberFormatter fluent setting chain.

Parameters
valueThe number to format.
statusSet to an ErrorCode if one occurred in the setter chain or during formatting.
Returns
A FormattedNumber object; call .toString() to get the string.
Stable:
ICU 60

◆ getAffixImpl()

void icu::number::LocalizedNumberFormatter::getAffixImpl ( bool  isPrefix,
bool  isNegative,
UnicodeString result,
UErrorCode status 
) const

Internal method for DecimalFormat compatibility.

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

◆ getCallCount()

int32_t icu::number::LocalizedNumberFormatter::getCallCount ( ) const

Internal method for testing.

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

◆ getCompiled()

const impl::NumberFormatterImpl * icu::number::LocalizedNumberFormatter::getCompiled ( ) const

Internal method for testing.

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

◆ getDecimalFormatSymbols()

const DecimalFormatSymbols * icu::number::LocalizedNumberFormatter::getDecimalFormatSymbols ( ) const
Internal:
Do not use. This API is for internal use only.

◆ operator=() [1/2]

LocalizedNumberFormatter & icu::number::LocalizedNumberFormatter::operator= ( const LocalizedNumberFormatter other)

Copy assignment operator.

Stable:
ICU 62

◆ operator=() [2/2]

LocalizedNumberFormatter & icu::number::LocalizedNumberFormatter::operator= ( LocalizedNumberFormatter &&  src)
noexcept

Move assignment operator: The source LocalizedNumberFormatter will be left in a valid but undefined state.

Stable:
ICU 62

◆ toFormat()

Format * icu::number::LocalizedNumberFormatter::toFormat ( UErrorCode status) const

Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use of this number formatter with APIs that need an object of that type, such as MessageFormat.

This API is not intended to be used other than for enabling API compatibility. The formatDouble, formatInt, and formatDecimal methods should normally be used when formatting numbers, not the Format object returned by this method.

The caller owns the returned object and must delete it when finished.

Returns
A Format wrapping this LocalizedNumberFormatter.
Stable:
ICU 62

◆ withoutLocale() [1/2]

UnlocalizedNumberFormatter icu::number::LocalizedNumberFormatter::withoutLocale ( ) &&

Overload of withoutLocale() for use on an rvalue reference.

Returns
The fluent chain.
See also
withoutLocale
Draft:
This API may be changed in the future versions and was introduced in ICU 75

◆ withoutLocale() [2/2]

UnlocalizedNumberFormatter icu::number::LocalizedNumberFormatter::withoutLocale ( ) const &

Disassociate the locale from this formatter.

Returns
The fluent chain.
Draft:
This API may be changed in the future versions and was introduced in ICU 75

Friends And Related Symbol Documentation

◆ NumberFormatterSettings< LocalizedNumberFormatter >

Definition at line 2715 of file numberformatter.h.

◆ NumberFormatterSettings< UnlocalizedNumberFormatter >

Definition at line 2715 of file numberformatter.h.

◆ UnlocalizedNumberFormatter

Definition at line 2722 of file numberformatter.h.


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