Class FractionPrecision
java.lang.Object
com.ibm.icu.number.Precision
com.ibm.icu.number.FractionPrecision
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.
- See Also:
- Status:
- Stable ICU 60.
-
Nested Class Summary
Nested classes/interfaces inherited from class Precision
Precision.BogusRounderModifier and TypeClassDescriptionstatic classDeprecated.This API is ICU internal only. -
Field Summary
Fields inherited from class Precision
BOGUS_PRECISIONModifier and TypeFieldDescriptionstatic final Precision.BogusRounderDeprecated.ICU internal only. -
Method Summary
Modifier and TypeMethodDescriptionwithMaxDigits(int maxSignificantDigits) Ensure that no more than this number of significant digits are retained when rounding according to fraction rules.withMinDigits(int minSignificantDigits) Ensure that no less than this number of significant digits are retained when rounding according to fraction rules.withSignificantDigits(int minSignificantDigits, int maxSignificantDigits, NumberFormatter.RoundingPriority priority) Override maximum fraction digits with maximum significant digits depending on the magnitude of the number.Methods inherited from class Precision
apply, currency, fixedFraction, fixedSignificantDigits, increment, integer, maxFraction, maxSignificantDigits, minFraction, minMaxFraction, minMaxSignificantDigits, minSignificantDigits, trailingZeroDisplay, unlimited, withModeModifier and TypeMethodDescriptionabstract voidapply(com.ibm.icu.impl.number.DecimalQuantity value) Deprecated.ICU 60 This API is ICU internal only.static CurrencyPrecisioncurrency(Currency.CurrencyUsage currencyUsage) Show numbers rounded and padded according to the rules for the currency unit.static FractionPrecisionfixedFraction(int minMaxFractionPlaces) Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).static PrecisionfixedSignificantDigits(int minMaxSignificantDigits) Show numbers rounded if necessary to a certain number of significant digits or significant figures.static Precisionincrement(BigDecimal roundingIncrement) Show numbers rounded if necessary to the closest multiple of a certain rounding increment.static FractionPrecisioninteger()Show numbers rounded if necessary to the nearest integer.static FractionPrecisionmaxFraction(int maxFractionPlaces) Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal separator).static PrecisionmaxSignificantDigits(int maxSignificantDigits) Show numbers rounded if necessary to a certain number of significant digits/figures.static FractionPrecisionminFraction(int minFractionPlaces) Always show at least a certain number of fraction places after the decimal separator, padding with zeros if necessary.static FractionPrecisionminMaxFraction(int minFractionPlaces, int 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 PrecisionminMaxSignificantDigits(int minSignificantDigits, int 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 PrecisionminSignificantDigits(int minSignificantDigits) Always show at least a certain number of significant digits/figures, padding with zeros if necessary.trailingZeroDisplay(NumberFormatter.TrailingZeroDisplay trailingZeroDisplay) Configure how trailing zeros are displayed on numbers.static PrecisionShow all available digits to full precision.withMode(MathContext mathContext) Deprecated.This API is ICU internal only.
-
Method Details
-
withSignificantDigits
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- 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.
- Status:
- Stable ICU 69.
-
withMinDigits
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 rounding() setter.
- Throws:
IllegalArgumentException- if the input number is too big or smaller than 1.- See Also:
- Status:
- Stable ICU 60.
-
withMaxDigits
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 rounding() setter.
- Throws:
IllegalArgumentException- if the input number is too big or smaller than 1.- See Also:
- Status:
- Stable ICU 60.
-