icu::number::NumberFormatterSettings< Derived > Class Template Reference

An abstract base class for specifying settings related to number formatting. More...

#include <numberformatter.h>

Public Member Functions

Derived notation (const Notation &notation) const
 Specifies the notation style (simple, scientific, or compact) for rendering numbers.
Derived unit (const icu::MeasureUnit &unit) const
 Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
Derived adoptUnit (const icu::MeasureUnit *unit) const
 Like unit(), but takes ownership of a pointer.
Derived rounding (const Rounder &rounder) const
 Specifies the rounding strategy to use when formatting numbers.
Derived grouping (const Grouper &grouper) const
 Specifies the grouping strategy to use when formatting numbers.
Derived integerWidth (const IntegerWidth &style) const
 Specifies the minimum and maximum number of digits to render before the decimal mark.
Derived symbols (const DecimalFormatSymbols &symbols) const
 Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.
Derived adoptSymbols (const NumberingSystem *symbols) const
 Specifies that the given numbering system should be used when fetching symbols.
Derived unitWidth (const UNumberUnitWidth &width) const
 Sets the width of the unit (measure unit or currency).
Derived sign (const UNumberSignDisplay &width) const
 Sets the plus/minus sign display strategy.
Derived decimal (const UNumberDecimalSeparatorDisplay &width) const
 Sets the decimal separator display strategy.
Derived padding (const impl::Padder &padder) const
 Set the padding strategy.
Derived threshold (int32_t threshold) const
 Internal fluent setter to support a custom regulation threshold.
UBool copyErrorTo (UErrorCode &outErrorCode) const
 Sets the UErrorCode if an error occurred in the fluent chain.

Protected Attributes

impl::MacroProps fMacros

Friends

class LocalizedNumberFormatter
class UnlocalizedNumberFormatter

Detailed Description

template<typename Derived>
class icu::number::NumberFormatterSettings< Derived >

An abstract base class for specifying settings related to number formatting.

This class is implemented by UnlocalizedNumberFormatter and LocalizedNumberFormatter.

Definition at line 1337 of file numberformatter.h.


Member Function Documentation

template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::adoptSymbols ( const NumberingSystem symbols  )  const

Specifies that the given numbering system should be used when fetching symbols.

  • Latin numbering system: "12,345"
  • Myanmar numbering system: "၁၂,၃၄၅"
  • Math Sans Bold numbering system: "𝟭𝟮,𝟯𝟰𝟱"

Pass this method an instance of NumberingSystem. For example, to force the locale to always use the Latin alphabet numbering system (ASCII digits):

 NumberFormatter::with().adoptSymbols(NumberingSystem::createInstanceByName("latn", status))
 

Note: Calling this method will override the DecimalFormatSymbols previously specified in symbols(DecimalFormatSymbols).

The default is to choose the best numbering system for the locale.

This method takes ownership of a pointer in order to work nicely with the NumberingSystem factory methods.

Parameters:
symbols The NumberingSystem to use.
Returns:
The fluent chain.
See also:
NumberingSystem
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::adoptUnit ( const icu::MeasureUnit unit  )  const

Like unit(), but takes ownership of a pointer.

Convenient for use with the MeasureFormat factory methods, which return pointers that need ownership.

Parameters:
unit The unit to render.
Returns:
The fluent chain.
See also:
unit
MeasureUnit
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
UBool icu::number::NumberFormatterSettings< Derived >::copyErrorTo ( UErrorCode outErrorCode  )  const [inline]

Sets the UErrorCode if an error occurred in the fluent chain.

Preserves older error codes in the outErrorCode.

Returns:
TRUE if U_FAILURE(outErrorCode)
Draft:
This API may be changed in the future versions and was introduced in ICU 60

Definition at line 1705 of file numberformatter.h.

template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::decimal ( const UNumberDecimalSeparatorDisplay width  )  const

Sets the decimal separator display strategy.

This affects integer numbers with no fraction part. Most common values:

  • Auto: "1"
  • Always: "1."

Pass an element from the UNumberDecimalSeparatorDisplay enum to this setter. For example:

 NumberFormatter::with().decimal(UNumberDecimalSeparatorDisplay::UNUM_DECIMAL_SEPARATOR_ALWAYS)
 

The default is AUTO decimal separator display.

Parameters:
width The decimal separator display strategy to use when rendering numbers.
Returns:
The fluent chain
See also:
UNumberDecimalSeparatorDisplay This API might change or be removed in a future release.
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::grouping ( const Grouper grouper  )  const

Specifies the grouping strategy to use when formatting numbers.

  • Default grouping: "12,300" and "1,230"
  • Grouping with at least 2 digits: "12,300" and "1230"
  • No grouping: "12300" and "1230"

The exact grouping widths will be chosen based on the locale.

Pass this method the return value of one of the factory methods on Grouper. For example:

 NumberFormatter::with().grouping(Grouper::min2())
 

The default is to perform grouping without concern for the minimum grouping digits.

Parameters:
grouper The grouping strategy to use.
Returns:
The fluent chain.
See also:
Grouper
Notation
Internal:

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

Do not use. This API is for internal use only. ICU 60: This API is technical preview.

template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::integerWidth ( const IntegerWidth style  )  const

Specifies the minimum and maximum number of digits to render before the decimal mark.

  • Zero minimum integer digits: ".08"
  • One minimum integer digit: "0.08"
  • Two minimum integer digits: "00.08"

Pass this method the return value of IntegerWidth#zeroFillTo(int). For example:

 NumberFormatter::with().integerWidth(IntegerWidth::zeroFillTo(2))
 

The default is to have one minimum integer digit.

Parameters:
style The integer width to use.
Returns:
The fluent chain.
See also:
IntegerWidth
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::notation ( const Notation notation  )  const

Specifies the notation style (simple, scientific, or compact) for rendering numbers.

  • Simple notation: "12,300"
  • Scientific notation: "1.23E4"
  • Compact notation: "12K"

All notation styles will be properly localized with locale data, and all notation styles are compatible with units, rounding strategies, and other number formatter settings.

Pass this method the return value of a Notation factory method. For example:

 NumberFormatter::with().notation(Notation::compactShort())
 

The default is to use simple notation.

Parameters:
notation The notation strategy to use.
Returns:
The fluent chain.
See also:
Notation
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::padding ( const impl::Padder padder  )  const

Set the padding strategy.

May be added to ICU 61; see #13338.

Internal:
Do not use. This API is for internal use only. ICU 60: This API is ICU internal only.
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::rounding ( const Rounder rounder  )  const

Specifies the rounding strategy to use when formatting numbers.

  • Round to 3 decimal places: "3.142"
  • Round to 3 significant figures: "3.14"
  • Round to the closest nickel: "3.15"
  • Do not perform rounding: "3.1415926..."

Pass this method the return value of one of the factory methods on Rounder. For example:

 NumberFormatter::with().rounding(Rounder::fixedFraction(2))
 

In most cases, the default rounding strategy is to round to 6 fraction places; i.e., Rounder.maxFraction(6). The exceptions are if compact notation is being used, then the compact notation rounding strategy is used (see Notation#compactShort for details), or if the unit is a currency, then standard currency rounding is used, which varies from currency to currency (see Rounder#currency for details).

Parameters:
rounder The rounding strategy to use.
Returns:
The fluent chain.
See also:
Rounder This API might change or be removed in a future release.
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::sign ( const UNumberSignDisplay width  )  const

Sets the plus/minus sign display strategy.

Most common values:

  • Auto: "123", "-123"
  • Always: "+123", "-123"
  • Accounting: "$123", "($123)"

Pass an element from the UNumberSignDisplay enum to this setter. For example:

 NumberFormatter::with().sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS)
 

The default is AUTO sign display.

Parameters:
width The sign display strategy to use when rendering numbers.
Returns:
The fluent chain
See also:
UNumberSignDisplay This API might change or be removed in a future release.
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::symbols ( const DecimalFormatSymbols symbols  )  const

Specifies the symbols (decimal separator, grouping separator, percent sign, numerals, etc.

) to use when rendering numbers.

  • en_US symbols: "12,345.67"
  • fr_FR symbols: "12&nbsp;345,67"
  • de_CH symbols: "12’345.67"
  • my_MY symbols: "၁၂,၃၄၅.၆၇"

Pass this method an instance of DecimalFormatSymbols. For example:

 NumberFormatter::with().symbols(DecimalFormatSymbols(Locale("de_CH"), status))
 

Note: DecimalFormatSymbols automatically chooses the best numbering system based on the locale. In the examples above, the first three are using the Latin numbering system, and the fourth is using the Myanmar numbering system.

Note: The instance of DecimalFormatSymbols will be copied: changes made to the symbols object after passing it into the fluent chain will not be seen.

Note: Calling this method will override the NumberingSystem previously specified in symbols(NumberingSystem).

The default is to choose the symbols based on the locale specified in the fluent chain.

Parameters:
symbols The DecimalFormatSymbols to use.
Returns:
The fluent chain.
See also:
DecimalFormatSymbols
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::threshold ( int32_t  threshold  )  const

Internal fluent setter to support a custom regulation threshold.

A threshold of 1 causes the data structures to be built right away. A threshold of 0 prevents the data structures from being built.

Internal:
Do not use. This API is for internal use only. ICU 60: This API is ICU internal only.
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::unit ( const icu::MeasureUnit unit  )  const

Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.

  • Unit of measure: "12.3 meters"
  • Currency: "$12.30"
  • Percent: "12.3%"

All units will be properly localized with locale data, and all units are compatible with notation styles, rounding strategies, and other number formatter settings.

Pass this method any instance of MeasureUnit. For units of measure:

 NumberFormatter.with().adoptUnit(MeasureUnit::createMeter(status))
 

Currency:

 NumberFormatter.with()unit(CurrencyUnit(u"USD", status))
 

Percent:

 NumberFormatter.with()unit(NoUnit.percent())
 

The default is to render without units (equivalent to NoUnit.base()).

Parameters:
unit The unit to render.
Returns:
The fluent chain.
See also:
MeasureUnit
Currency
NoUnit
Draft:
This API may be changed in the future versions and was introduced in ICU 60
template<typename Derived>
Derived icu::number::NumberFormatterSettings< Derived >::unitWidth ( const UNumberUnitWidth width  )  const

Sets the width of the unit (measure unit or currency).

Most common values:

  • Short: "$12.00", "12 m"
  • ISO Code: "USD 12.00"
  • Full name: "12.00 US dollars", "12 meters"

Pass an element from the UNumberUnitWidth enum to this setter. For example:

 NumberFormatter::with().unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME)
 

The default is the SHORT width.

Parameters:
width The width to use when rendering numbers.
Returns:
The fluent chain
See also:
UNumberUnitWidth
Draft:
This API may be changed in the future versions and was introduced in ICU 60

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

Generated on 15 Dec 2017 for ICU 60.1 by  doxygen 1.6.1