ICU 72.1 72.1

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

A class that defines a rounding precision based on a number of fraction places and optionally significant digits to be used when formatting numbers in NumberFormatter. More...

`#include <numberformatter.h>`

Inheritance diagram for icu::number::FractionPrecision:

## Public Member Functions
Precision | withSignificantDigits (int32_t minSignificantDigits, int32_t maxSignificantDigits, UNumberRoundingPriority priority) const
| Override maximum fraction digits with maximum significant digits depending on the magnitude of the number. More...
Precision | withMinDigits (int32_t minSignificantDigits) const
| Ensure that no less than this number of significant digits are retained when rounding according to fraction rules. More...
Precision | withMaxDigits (int32_t maxSignificantDigits) const
| Ensure that no more than this number of significant digits are retained when rounding according to fraction rules. More...
Public Member Functions inherited from icu::number::Precision
Precision | trailingZeroDisplay (UNumberTrailingZeroDisplay trailingZeroDisplay) const
| Configure how trailing zeros are displayed on numbers. More...

## Friends
class | Precision

## Additional Inherited Members
Static Public Member Functions inherited from icu::number::Precision
static Precision | unlimited ()
| Show all available digits to full precision. More...
static FractionPrecision | integer ()
| Show numbers rounded if necessary to the nearest integer. More...
static FractionPrecision | fixedFraction (int32_t minMaxFractionPlaces)
| Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator). More...
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. More...
static FractionPrecision | maxFraction (int32_t maxFractionPlaces)
| Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator). More...
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. More...
static SignificantDigitsPrecision | fixedSignificantDigits (int32_t minMaxSignificantDigits)
| Show numbers rounded if necessary to a certain number of significant digits or significant figures. More...
static SignificantDigitsPrecision | minSignificantDigits (int32_t minSignificantDigits)
| Always show at least a certain number of significant digits/figures, padding with zeros if necessary. More...
static SignificantDigitsPrecision | maxSignificantDigits (int32_t maxSignificantDigits)
| Show numbers rounded if necessary to a certain number of significant digits/figures. More...
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. More...
static IncrementPrecision | increment (double roundingIncrement)
| Show numbers rounded if necessary to the closest multiple of a certain rounding increment. More...
static IncrementPrecision | incrementExact (uint64_t mantissa, int16_t magnitude)
| Version of `Precision::increment()` that takes an integer at a particular power of 10. More...
static CurrencyPrecision | currency (UCurrencyUsage currencyUsage)
| Show numbers rounded and padded according to the rules for the currency unit. More...

## Detailed Description

A class that defines a rounding precision based on a number of fraction places and optionally significant digits to be used when formatting numbers in NumberFormatter.

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

Stable:
  ICU 60

Definition at line 837 of file numberformatter.h.

## Member Function Documentation

## ◆ withMaxDigits()

Precision icu::number::FractionPrecision::withMaxDigits | ( | int32_t | maxSignificantDigits | ) | const

Ensure that no more than this number of significant digits are retained when rounding according to fraction rules.

For example, with integer rounding, the number 123.4 becomes "123". However, with maximum figures set to 2, 123.4 becomes "120" instead.

This setting does not affect the number of trailing zeros. For example, with fixed fraction of 2, 123.4 would become "120.00".

This is equivalent to `withSignificantDigits(1, maxSignificantDigits, STRICT)`.

Parameters

  maxSignificantDigits | Round the number to no more than this number of significant figures.

Returns
  A precision for chaining or passing to the NumberFormatter precision() setter.

Stable:
  ICU 60

## ◆ withMinDigits()

Precision icu::number::FractionPrecision::withMinDigits | ( | int32_t | minSignificantDigits | ) | const

Ensure that no less than this number of significant digits are retained when rounding according to fraction rules.

For example, with integer rounding, the number 3.141 becomes "3". However, with minimum figures set to 2, 3.141 becomes "3.1" instead.

This setting does not affect the number of trailing zeros. For example, 3.01 would print as "3", not "3.0".

This is equivalent to `withSignificantDigits(1, minSignificantDigits, RELAXED)`.

Parameters

  minSignificantDigits | The number of significant figures to guarantee.

Returns
  A precision for chaining or passing to the NumberFormatter precision() setter.

Stable:
  ICU 60

## ◆ withSignificantDigits()

Precision icu::number::FractionPrecision::withSignificantDigits | ( | int32_t | minSignificantDigits,
|  | int32_t | maxSignificantDigits,
|  | UNumberRoundingPriority | priority
| ) |  | const

Override maximum fraction digits with maximum significant digits depending on the magnitude of the number.

See UNumberRoundingPriority.

Parameters

  minSignificantDigits | Pad trailing zeros to achieve this minimum number of significant digits.
  maxSignificantDigits | Round the number to achieve this maximum number of significant digits.
  priority | How to disambiguate between fraction digits and significant digits.

Returns
  A precision for chaining or passing to the NumberFormatter precision() setter.

Stable:
  ICU 69

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

- numberformatter.h