Top Description Fields Constructors Methods
com.ibm.icu.number

public abstract Class FractionPrecision

extends Precision
Class Inheritance
Known Direct Subclasses
com.ibm.icu.number.Precision.FractionRounderImpl
Imports
com.ibm.icu.impl.number.RoundingUtils

A class that defines a rounding strategy 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.

ICU Status
Stable since ICU 60.
See Also
NumberFormatter

Field Summary

Inherited from com.ibm.icu.number.Precision:
BOGUS_PRECISIONCOMPACT_STRATEGYDEFAULT_MAX_FRAC_6FIXED_FRAC_0FIXED_FRAC_2FIXED_SIG_2FIXED_SIG_3mathContextMONETARY_CASHMONETARY_STANDARDNICKELNONERANGE_SIG_2_3trailingZeroDisplay

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Precision

Returns:

A Precision for chaining or passing to the NumberFormatter rounding() setter.
withMaxDigits
(int
Round the number to no more than this number of significant figures.
maxSignificantDigits
)

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

public Precision

Returns:

A Precision for chaining or passing to the NumberFormatter rounding() setter.
withMinDigits
(int
The number of significant figures to guarantee.
minSignificantDigits
)

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

public Precision

Returns:

A precision for chaining or passing to the NumberFormatter precision() setter.
withSignificantDigits
(int
Pad trailing zeros to achieve this minimum number of significant digits.
minSignificantDigits
,
int
Round the number to achieve this maximum number of significant digits.
maxSignificantDigits
,
NumberFormatter.RoundingPriority
How to disambiguate between fraction digits and significant digits.
priority
)

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

Inherited from com.ibm.icu.number.Precision:
applychooseMultiplierAndApplyconstructCurrencyconstructFractionconstructFractionSignificantconstructFromCurrencyconstructIncrementconstructInfiniteconstructSignificantcreateCopycreateCopyHelpercurrencyfixedFractionfixedSignificantDigitsincrementintegermaxFractionmaxSignificantDigitsminFractionminMaxFractionminMaxSignificantDigitsminSignificantDigitssetResolvedMinFractiontrailingZeroDisplayunlimitedwithLocaleDatawithMode

Constructor Detail

FractionPrecisionback to summary
pack-priv FractionPrecision()

Method Detail

withMaxDigitsback to summary
public Precision withMaxDigits(int maxSignificantDigits)

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:int

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

Returns:Precision

A Precision for chaining or passing to the NumberFormatter rounding() setter.

Exceptions
IllegalArgumentException:
if the input number is too big or smaller than 1.
ICU Status
Stable since ICU 60.
See Also
NumberFormatter
withMinDigitsback to summary
public Precision withMinDigits(int minSignificantDigits)

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:int

The number of significant figures to guarantee.

Returns:Precision

A Precision for chaining or passing to the NumberFormatter rounding() setter.

Exceptions
IllegalArgumentException:
if the input number is too big or smaller than 1.
ICU Status
Stable since ICU 60.
See Also
NumberFormatter
withSignificantDigitsback to summary
public Precision withSignificantDigits(int minSignificantDigits, int maxSignificantDigits, NumberFormatter.RoundingPriority priority)

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

Parameters
minSignificantDigits:int

Pad trailing zeros to achieve this minimum number of significant digits.

maxSignificantDigits:int

Round the number to achieve this maximum number of significant digits.

priority:NumberFormatter.RoundingPriority

How to disambiguate between fraction digits and significant digits.

Returns:Precision

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

ICU Status
Stable since ICU 69.