public abstract class Rounder
extends java.lang.Object
implements java.lang.Cloneable
To create a Rounder, use one of the factory methods.
NumberFormatter| Modifier and Type | Method and Description |
|---|---|
abstract void |
apply(com.ibm.icu.impl.number.DecimalQuantity value)
Deprecated.
ICU 60 This API is ICU internal only.
|
java.lang.Object |
clone()
Deprecated.
This API is ICU internal only.
|
static CurrencyRounder |
currency(Currency.CurrencyUsage currencyUsage)
Show numbers rounded and padded according to the rules for the currency unit.
|
static Rounder |
fixedDigits(int minMaxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits or significant
figures.
|
static FractionRounder |
fixedFraction(int minMaxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the
decimal separator).
|
static Rounder |
increment(java.math.BigDecimal roundingIncrement)
Show numbers rounded if necessary to the closest multiple of a certain rounding increment.
|
static FractionRounder |
integer()
Show numbers rounded if necessary to the nearest integer.
|
static Rounder |
maxDigits(int maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures.
|
static FractionRounder |
maxFraction(int maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the
decimal separator).
|
static Rounder |
minDigits(int minSignificantDigits)
Always show at least a certain number of significant digits/figures, padding with zeros if
necessary.
|
static FractionRounder |
minFraction(int minFractionPlaces)
Always show at least a certain number of fraction places after the decimal separator, padding with
zeros if necessary.
|
static Rounder |
minMaxDigits(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 FractionRounder |
minMaxFraction(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 Rounder |
unlimited()
Show all available digits to full precision.
|
Rounder |
withMode(java.math.MathContext mathContext)
Deprecated.
This API is ICU internal only.
|
Rounder |
withMode(java.math.RoundingMode roundingMode)
Sets the
RoundingMode to use when picking the direction to round (up or down). |
public static Rounder unlimited()
NOTE: When formatting a double, this method, along with
minFraction(int) and minDigits(int), 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(int) or maxDigits(int) 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/
NumberFormatterpublic static FractionRounder integer()
NumberFormatterpublic static FractionRounder fixedFraction(int minMaxFractionPlaces)
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(int, int) with both arguments equal.
minMaxFractionPlaces - The minimum and maximum number of numerals to display after the decimal separator
(rounding if too long or padding with zeros if too short).NumberFormatterpublic static FractionRounder minFraction(int minFractionPlaces)
NOTE: If you are formatting doubles, see the performance note in
unlimited().
minFractionPlaces - The minimum number of numerals to display after the decimal separator (padding with
zeros if necessary).NumberFormatterpublic static FractionRounder maxFraction(int maxFractionPlaces)
maxFractionPlaces - The maximum number of numerals to display after the decimal mark (rounding if
necessary).NumberFormatterpublic static FractionRounder minMaxFraction(int minFractionPlaces, int maxFractionPlaces)
minFractionPlaces - The minimum number of numerals to display after the decimal separator (padding with
zeros if necessary).maxFractionPlaces - The maximum number of numerals to display after the decimal separator (rounding if
necessary).NumberFormatterpublic static Rounder fixedDigits(int minMaxSignificantDigits)
This method is equivalent to minMaxDigits(int, int) with both arguments equal.
minMaxSignificantDigits - The minimum and maximum number of significant digits to display (rounding if too long
or padding with zeros if too short).NumberFormatterpublic static Rounder minDigits(int minSignificantDigits)
NOTE: If you are formatting doubles, see the performance note in
unlimited().
minSignificantDigits - The minimum number of significant digits to display (padding with zeros if too short).NumberFormatterpublic static Rounder maxDigits(int maxSignificantDigits)
maxSignificantDigits - The maximum number of significant digits to display (rounding if too long).NumberFormatterpublic static Rounder minMaxDigits(int minSignificantDigits, int maxSignificantDigits)
minSignificantDigits - The minimum number of significant digits to display (padding with zeros if necessary).maxSignificantDigits - The maximum number of significant digits to display (rounding if necessary).NumberFormatterpublic static Rounder increment(java.math.BigDecimal roundingIncrement)
In order to ensure that numbers are padded to the appropriate number of fraction places, set the scale on the rounding increment BigDecimal. 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:
Rounder.increment(new BigDecimal("0.50"))
For more information on the scale of Java BigDecimal, see BigDecimal.scale().
roundingIncrement - The increment to which to round numbers.NumberFormatterpublic static CurrencyRounder currency(Currency.CurrencyUsage currencyUsage)
Rounder.fixedFraction(2),
Rounder.integer(), and Rounder.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.
currencyUsage - Either STANDARD (for digital transactions) or CASH (for transactions where the rounding
increment may be limited by the available denominations of cash or coins).NumberFormatterpublic Rounder withMode(java.math.RoundingMode roundingMode)
RoundingMode to use when picking the direction to round (up or down).
Common values include HALF_EVEN, HALF_UP, and FLOOR. The default is HALF_EVEN.roundingMode - The RoundingMode to use.NumberFormatter@Deprecated public Rounder withMode(java.math.MathContext mathContext)
@Deprecated public java.lang.Object clone()
clone in class java.lang.Object@Deprecated public abstract void apply(com.ibm.icu.impl.number.DecimalQuantity value)
Copyright © 2016 Unicode, Inc. and others.