ICU 73.2  73.2
Data Structures | Public Member Functions | Static Public Member Functions | Friends
icu::number::Precision Class Reference

A class that defines the rounding precision to be used when formatting numbers in NumberFormatter. More...

#include <numberformatter.h>

Inheritance diagram for icu::number::Precision:
icu::UMemory icu::number::CurrencyPrecision icu::number::FractionPrecision icu::number::IncrementPrecision

Data Structures

union  PrecisionUnion

Public Member Functions

Precision trailingZeroDisplay (UNumberTrailingZeroDisplay trailingZeroDisplay) const
 Configure how trailing zeros are displayed on numbers.

Static Public Member Functions

static Precision unlimited ()
 Show all available digits to full precision.
static FractionPrecision integer ()
 Show numbers rounded if necessary to the nearest integer.
static FractionPrecision fixedFraction (int32_t minMaxFractionPlaces)
 Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).
static FractionPrecision minFraction (int32_t minFractionPlaces)
 Always show at least a certain number of fraction places after the decimal separator, padding with zeros if necessary.
static FractionPrecision maxFraction (int32_t maxFractionPlaces)
 Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).
static FractionPrecision minMaxFraction (int32_t minFractionPlaces, int32_t maxFractionPlaces)
 Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator); in addition, always show at least a certain number of places after the decimal separator, padding with zeros if necessary.
static SignificantDigitsPrecision fixedSignificantDigits (int32_t minMaxSignificantDigits)
 Show numbers rounded if necessary to a certain number of significant digits or significant figures.
static SignificantDigitsPrecision minSignificantDigits (int32_t minSignificantDigits)
 Always show at least a certain number of significant digits/figures, padding with zeros if necessary.
static SignificantDigitsPrecision maxSignificantDigits (int32_t maxSignificantDigits)
 Show numbers rounded if necessary to a certain number of significant digits/figures.
static SignificantDigitsPrecision minMaxSignificantDigits (int32_t minSignificantDigits, int32_t maxSignificantDigits)
 Show numbers rounded if necessary to a certain number of significant digits/figures; in addition, always show at least a certain number of significant digits, padding with zeros if necessary.
static IncrementPrecision increment (double roundingIncrement)
 Show numbers rounded if necessary to the closest multiple of a certain rounding increment.
static IncrementPrecision incrementExact (uint64_t mantissa, int16_t magnitude)
 Version of `Precision::increment()` that takes an integer at a particular power of 10.
static CurrencyPrecision currency (UCurrencyUsage currencyUsage)
 Show numbers rounded and padded according to the rules for the currency unit.

Friends

struct impl::MacroProps
struct impl::MicroProps
class impl::NumberFormatterImpl
class impl::NumberPropertyMapper
class impl::RoundingImpl
class FractionPrecision
class CurrencyPrecision
class IncrementPrecision
class impl::GeneratorHelpers
class units::UnitsRouter

Detailed Description

A class that defines the rounding precision to be used when formatting numbers in NumberFormatter.

To create a Precision, use one of the factory methods.

Stable:
ICU 60

Definition at line 473 of file numberformatter.h.


Member Function Documentation

Show numbers rounded and padded according to the rules for the currency unit.

The most common rounding precision settings for currencies include Precision::fixedFraction(2), Precision::integer(), and Precision::increment(0.05) for cash transactions ("nickel rounding").

The exact rounding details will be resolved at runtime based on the currency unit specified in the NumberFormatter chain. To round according to the rules for one currency while displaying the symbol for another currency, the withCurrency() method can be called on the return value of this method.

Parameters:
currencyUsageEither STANDARD (for digital transactions) or CASH (for transactions where the rounding increment may be limited by the available denominations of cash or coins).
Returns:
A CurrencyPrecision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static FractionPrecision icu::number::Precision::fixedFraction ( int32_t  minMaxFractionPlaces) [static]

Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).

Additionally, pad with zeros to ensure that this number of places are always shown.

Example output with minMaxFractionPlaces = 3:

87,650.000
8,765.000
876.500
87.650
8.765
0.876
0.088
0.009
0.000 (zero)

This method is equivalent to minMaxFraction with both arguments equal.

Parameters:
minMaxFractionPlacesThe minimum and maximum number of numerals to display after the decimal separator (rounding if too long or padding with zeros if too short).
Returns:
A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static SignificantDigitsPrecision icu::number::Precision::fixedSignificantDigits ( int32_t  minMaxSignificantDigits) [static]

Show numbers rounded if necessary to a certain number of significant digits or significant figures.

Additionally, pad with zeros to ensure that this number of significant digits/figures are always shown.

This method is equivalent to minMaxSignificantDigits with both arguments equal.

Parameters:
minMaxSignificantDigitsThe minimum and maximum number of significant digits to display (rounding if too long or padding with zeros if too short).
Returns:
A precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 62
static IncrementPrecision icu::number::Precision::increment ( double  roundingIncrement) [static]

Show numbers rounded if necessary to the closest multiple of a certain rounding increment.

For example, if the rounding increment is 0.5, then round 1.2 to 1 and round 1.3 to 1.5.

In order to ensure that numbers are padded to the appropriate number of fraction places, call withMinFraction() on the return value of this method. For example, to round to the nearest 0.5 and always display 2 numerals after the decimal separator (to display 1.2 as "1.00" and 1.3 as "1.50"), you can run:

 Precision::increment(0.5).withMinFraction(2)
 
Parameters:
roundingIncrementThe increment to which to round numbers.
Returns:
A precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static IncrementPrecision icu::number::Precision::incrementExact ( uint64_t  mantissa,
int16_t  magnitude 
) [static]

Version of `Precision::increment()` that takes an integer at a particular power of 10.

To round to the nearest 0.5 and display 2 fraction digits, with this function, you should write one of the following:

 Precision::incrementExact(5, -1).withMinFraction(2)
 Precision::incrementExact(50, -2).withMinFraction(2)
 Precision::incrementExact(50, -2)
 

This is analagous to ICU4J `Precision.increment(new BigDecimal("0.50"))`.

This behavior is modeled after ECMA-402. For more information, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingincrement

Parameters:
mantissaThe increment to which to round numbers.
magnitudeThe power of 10 of the ones digit of the mantissa.
Returns:
A precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 71

Show numbers rounded if necessary to the nearest integer.

Returns:
A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static FractionPrecision icu::number::Precision::maxFraction ( int32_t  maxFractionPlaces) [static]

Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).

Unlike the other fraction rounding strategies, this strategy does not pad zeros to the end of the number.

Parameters:
maxFractionPlacesThe maximum number of numerals to display after the decimal mark (rounding if necessary).
Returns:
A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static SignificantDigitsPrecision icu::number::Precision::maxSignificantDigits ( int32_t  maxSignificantDigits) [static]

Show numbers rounded if necessary to a certain number of significant digits/figures.

Parameters:
maxSignificantDigitsThe maximum number of significant digits to display (rounding if too long).
Returns:
A precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 62
static FractionPrecision icu::number::Precision::minFraction ( int32_t  minFractionPlaces) [static]

Always show at least a certain number of fraction places after the decimal separator, padding with zeros if necessary.

Do not perform rounding (display numbers to their full precision).

NOTE: If you are formatting doubles, see the performance note in unlimited.

Parameters:
minFractionPlacesThe minimum number of numerals to display after the decimal separator (padding with zeros if necessary).
Returns:
A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static FractionPrecision icu::number::Precision::minMaxFraction ( int32_t  minFractionPlaces,
int32_t  maxFractionPlaces 
) [static]

Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator); in addition, always show at least a certain number of places after the decimal separator, padding with zeros if necessary.

Parameters:
minFractionPlacesThe minimum number of numerals to display after the decimal separator (padding with zeros if necessary).
maxFractionPlacesThe maximum number of numerals to display after the decimal separator (rounding if necessary).
Returns:
A FractionPrecision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60
static SignificantDigitsPrecision icu::number::Precision::minMaxSignificantDigits ( int32_t  minSignificantDigits,
int32_t  maxSignificantDigits 
) [static]

Show numbers rounded if necessary to a certain number of significant digits/figures; in addition, always show at least a certain number of significant digits, padding with zeros if necessary.

Parameters:
minSignificantDigitsThe minimum number of significant digits to display (padding with zeros if necessary).
maxSignificantDigitsThe maximum number of significant digits to display (rounding if necessary).
Returns:
A precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 62
static SignificantDigitsPrecision icu::number::Precision::minSignificantDigits ( int32_t  minSignificantDigits) [static]

Always show at least a certain number of significant digits/figures, padding with zeros if necessary.

Do not perform rounding (display numbers to their full precision).

NOTE: If you are formatting doubles, see the performance note in unlimited.

Parameters:
minSignificantDigitsThe minimum number of significant digits to display (padding with zeros if too short).
Returns:
A precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 62

Configure how trailing zeros are displayed on numbers.

For example, to hide trailing zeros when the number is an integer, use UNUM_TRAILING_ZERO_HIDE_IF_WHOLE.

Parameters:
trailingZeroDisplayOption to configure the display of trailing zeros.
Stable:
ICU 69

Show all available digits to full precision.

NOTE: When formatting a double, this method, along with minFraction and minSignificantDigits, will trigger complex algorithm similar to Dragon4 to determine the low-order digits and the number of digits to display based on the value of the double. If the number of fraction places or significant digits can be bounded, consider using maxFraction or maxSignificantDigits instead to maximize performance. For more information, read the following blog post.

http://www.serpentine.com/blog/2011/06/29/here-be-dragons-advances-in-problems-you-didnt-even-know-you-had/

Returns:
A Precision for chaining or passing to the NumberFormatter precision() setter.
Stable:
ICU 60

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