public class RoundingUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static MathContext |
DEFAULT_MATH_CONTEXT_34_DIGITS
The default MathContext, 34-digit version.
|
static MathContext |
DEFAULT_MATH_CONTEXT_UNLIMITED
The default MathContext, unlimited-precision version.
|
static RoundingMode |
DEFAULT_ROUNDING_MODE
The default rounding mode.
|
static int |
MAX_INT_FRAC_SIG
The maximum number of fraction places, integer numerals, or significant digits.
|
static int |
SECTION_LOWER |
static int |
SECTION_MIDPOINT |
static int |
SECTION_UPPER |
| Constructor and Description |
|---|
RoundingUtils() |
| Modifier and Type | Method and Description |
|---|---|
static MathContext |
getMathContextOr34Digits(DecimalFormatProperties properties)
Gets the user-specified math context out of the property bag.
|
static MathContext |
getMathContextOrUnlimited(DecimalFormatProperties properties)
Gets the user-specified math context out of the property bag.
|
static StandardPlural |
getPluralSafe(Precision rounder,
PluralRules rules,
DecimalQuantity dq)
Computes the plural form after copying the number and applying rounding rules.
|
static boolean |
getRoundingDirection(boolean isEven,
boolean isNegative,
int section,
int roundingMode,
Object reference)
Converts a rounding mode and metadata about the quantity being rounded to a boolean determining
whether the value should be rounded toward infinity or toward zero.
|
static MathContext |
mathContextUnlimited(RoundingMode roundingMode)
Gets a MathContext with unlimited precision and the specified RoundingMode.
|
static boolean |
roundsAtMidpoint(int roundingMode)
Gets whether the given rounding mode's rounding boundary is at the midpoint.
|
static Scale |
scaleFromProperties(DecimalFormatProperties properties) |
public static final int SECTION_LOWER
public static final int SECTION_MIDPOINT
public static final int SECTION_UPPER
public static final RoundingMode DEFAULT_ROUNDING_MODE
public static final int MAX_INT_FRAC_SIG
public static final MathContext DEFAULT_MATH_CONTEXT_UNLIMITED
public static final MathContext DEFAULT_MATH_CONTEXT_34_DIGITS
public static boolean getRoundingDirection(boolean isEven,
boolean isNegative,
int section,
int roundingMode,
Object reference)
The parameters are of type int because benchmarks on an x86-64 processor against OpenJDK showed that ints were demonstrably faster than enums in switch statements.
isEven - Whether the digit immediately before the rounding magnitude is even.isNegative - Whether the quantity is negative.section - Whether the part of the quantity to the right of the rounding magnitude is exactly
halfway between two digits, whether it is in the lower part (closer to zero), or
whether it is in the upper part (closer to infinity). See RoundingUtils.SECTION_LOWER,
RoundingUtils.SECTION_MIDPOINT, and RoundingUtils.SECTION_UPPER.roundingMode - The integer version of the RoundingMode, which you can get via
Enum.ordinal.reference - A reference object to be used when throwing an ArithmeticException.public static boolean roundsAtMidpoint(int roundingMode)
roundingMode - The integer version of the RoundingMode.public static MathContext getMathContextOrUnlimited(DecimalFormatProperties properties)
properties - The property bag.MathContext. Never null.public static MathContext getMathContextOr34Digits(DecimalFormatProperties properties)
properties - The property bag.MathContext. Never null.public static MathContext mathContextUnlimited(RoundingMode roundingMode)
roundingMode - The RoundingMode to use.MathContext.public static Scale scaleFromProperties(DecimalFormatProperties properties)
public static StandardPlural getPluralSafe(Precision rounder, PluralRules rules, DecimalQuantity dq)