public final class BigDecimalTools
extends java.lang.Object
BigDecimal
and related objects.Constructor and Description |
---|
BigDecimalTools() |
Modifier and Type | Method and Description |
---|---|
static boolean |
equalsByCompare(java.math.BigDecimal[] a,
java.math.BigDecimal[] b)
Returns true if the two specified arrays of BigDecimals are equal to one another.
|
static int |
getOrderOfMagnitude(java.math.BigDecimal bd)
Returns the order of magnitude, i.e., the nearest power of ten, for the given BigDecimal.
|
static boolean |
isWithinTolerance(java.math.BigDecimal number,
java.math.BigDecimal centralValue,
java.math.BigDecimal tolerance)
Checks whether a given BigDecimal is within a specified tolerance or margin of error from a central value.
|
static boolean |
liesInInterval(java.math.BigDecimal n,
java.math.BigDecimal lowerBound,
java.math.BigDecimal upperBound)
Returns true if
n is in the closed interval [lowerBound , upperBound ]. |
static boolean |
liesInInterval(java.math.BigDecimal n,
java.math.BigDecimal lowerBound,
java.math.BigDecimal upperBound,
boolean excludingLeft)
Returns true if
n is in the closed interval [lowerBound , upperBound ]. |
static boolean |
liesInInterval(java.math.BigDecimal n,
java.math.BigDecimal lowerBound,
java.math.BigDecimal upperBound,
boolean excludingLeft,
boolean excludingRight)
Returns true if
n is in the closed interval [lowerBound , upperBound ]. |
static boolean |
liesInLeftOpenInterval(java.math.BigDecimal n,
java.math.BigDecimal lowerBound,
java.math.BigDecimal upperBound)
Returns true if
n is in the left open interval (lowerBound , upperBound ]. |
static boolean |
liesInOpenInterval(java.math.BigDecimal n,
java.math.BigDecimal lowerBound,
java.math.BigDecimal upperBound)
Returns true if
n is in the open interval (lowerBound , upperBound ). |
static boolean |
liesInRightOpenInterval(java.math.BigDecimal n,
java.math.BigDecimal lowerBound,
java.math.BigDecimal upperBound)
Returns true if
n is in the right open interval [lowerBound , upperBound ). |
static java.math.BigDecimal |
normalize(java.math.BigDecimal val)
Caps the scale of the passed
BigDecimal (rounding with ROUND_HALF_UP)
and removes any trailing zeros. |
static java.math.BigDecimal |
normalize(java.math.BigDecimal val,
int maxScale)
Caps the scale of the passed
BigDecimal (rounding with ROUND_HALF_UP)
and removes any trailing zeros. |
static java.math.BigDecimal |
roundToNearestOrderOfMagnitude(java.math.BigDecimal bd)
Rounds the passed BigDecimal to the nearest order of magnitude, i.e., power of ten.
|
static java.math.BigDecimal |
roundToNextOrderOfMagnitude(java.math.BigDecimal bd)
Rounds the passed BigDecimal to the next order of magnitude, i.e., power of ten.
|
static java.math.BigDecimal |
roundUpToGivenFraction(java.math.BigDecimal val,
java.math.BigDecimal ceiling)
Rounds the provided value
val to the specified ceiling . |
static java.math.BigDecimal |
sqrt(java.math.BigDecimal value)
Calculates an approximation of the square root for the passed BigDecimal to a precision of around 30 total digits.
|
static java.math.BigDecimal |
sum(java.math.BigDecimal[] array) |
static java.math.BigDecimal |
sum(java.lang.Iterable<java.math.BigDecimal> iter) |
static java.math.BigDecimal |
toBigDecimal(java.lang.Number number)
Creates a BigDecimal from a Number.
|
public static final java.math.BigDecimal toBigDecimal(java.lang.Number number)
number
- the Number to generate the BigDecimal frompublic static final boolean equalsByCompare(java.math.BigDecimal[] a, java.math.BigDecimal[] b)
Arrays.equals(Object[], Object[])
, only that it uses BigDecimal.compareTo(java.math.BigDecimal)
for the equality check.a
- one array tested for compare equality, nullable.b
- the other array tested for compare equality, nullable.public static final java.math.BigDecimal sum(java.math.BigDecimal[] array)
public static final java.math.BigDecimal sum(java.lang.Iterable<java.math.BigDecimal> iter)
public static final boolean isWithinTolerance(java.math.BigDecimal number, java.math.BigDecimal centralValue, java.math.BigDecimal tolerance)
number
- the BigDecimal to check.centralValue
- the central value to use as a reference point.tolerance
- the tolerance value that determines the allowed deviation from the central value.java.lang.IllegalArgumentException
- if the number, centralValue, or tolerance parameters are null or the tolerance parameter is negative.public static final boolean liesInInterval(java.math.BigDecimal n, java.math.BigDecimal lowerBound, java.math.BigDecimal upperBound)
n
is in the closed interval [lowerBound
, upperBound
].
Null values for lowerBound
or upperBound
represent infinity.n
- the BigDecimal to checklowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervaln
is in the specified intervaljava.lang.IllegalArgumentException
- if the input is invalidpublic static final boolean liesInInterval(java.math.BigDecimal n, java.math.BigDecimal lowerBound, java.math.BigDecimal upperBound, boolean excludingLeft)
n
is in the closed interval [lowerBound
, upperBound
].
Null values for lowerBound
or upperBound
represent infinity.n
- the BigDecimal to checklowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervalexcludingLeft
- whether to exclude the left endpointn
is in the specified intervaljava.lang.IllegalArgumentException
- if the input is invalidpublic static final boolean liesInInterval(java.math.BigDecimal n, java.math.BigDecimal lowerBound, java.math.BigDecimal upperBound, boolean excludingLeft, boolean excludingRight)
n
is in the closed interval [lowerBound
, upperBound
].
Null values for lowerBound
or upperBound
represent infinity.n
- the BigDecimal to checklowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervalexcludingLeft
- whether to exclude the left endpointexcludingRight
- whether to exclude the right endpointn
is in the specified intervaljava.lang.IllegalArgumentException
- if the input is invalidpublic static final boolean liesInOpenInterval(java.math.BigDecimal n, java.math.BigDecimal lowerBound, java.math.BigDecimal upperBound)
n
is in the open interval (lowerBound
, upperBound
).
Null values for lowerBound
or upperBound
represent infinity.n
- the BigDecimal to checklowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervaln
is in the specified open intervalpublic static final boolean liesInLeftOpenInterval(java.math.BigDecimal n, java.math.BigDecimal lowerBound, java.math.BigDecimal upperBound)
n
is in the left open interval (lowerBound
, upperBound
].
Null values for lowerBound
or upperBound
represent infinity.n
- the BigDecimal to checklowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervaln
is in the specified left open intervalpublic static final boolean liesInRightOpenInterval(java.math.BigDecimal n, java.math.BigDecimal lowerBound, java.math.BigDecimal upperBound)
n
is in the right open interval [lowerBound
, upperBound
).
Null values for lowerBound
or upperBound
represent infinity.n
- the BigDecimal to checklowerBound
- the lower bound of the intervalupperBound
- the upper bound of the intervaln
is in the specified right open intervalpublic static final java.math.BigDecimal sqrt(java.math.BigDecimal value)
value
- the BigDecimal for which to calculate the square rootpublic static final java.math.BigDecimal roundUpToGivenFraction(java.math.BigDecimal val, java.math.BigDecimal ceiling)
val
to the specified ceiling
.val
- the value to round upceiling
- the ceiling to round up tojava.lang.IllegalStateException
- if the input value is negativepublic static final int getOrderOfMagnitude(java.math.BigDecimal bd)
bd
- the BigDecimal for which to determine the order of magnitudejava.lang.IllegalArgumentException
- if the input is negativepublic static final java.math.BigDecimal roundToNearestOrderOfMagnitude(java.math.BigDecimal bd)
bd
- the BigDecimal to roundpublic static final java.math.BigDecimal roundToNextOrderOfMagnitude(java.math.BigDecimal bd)
bd
- the BigDecimal to roundpublic static final java.math.BigDecimal normalize(java.math.BigDecimal val)
BigDecimal
(rounding with ROUND_HALF_UP)
and removes any trailing zeros.val
- the BigDecimal to normalizepublic static final java.math.BigDecimal normalize(java.math.BigDecimal val, int maxScale)
BigDecimal
(rounding with ROUND_HALF_UP)
and removes any trailing zeros.val
- the BigDecimal to normalizemaxScale
- the maximum scale to setCopyright © 2000-2024 OAshi S.à r.l. All Rights Reserved.