public final class BigDecimalUtil extends Object
Modifier and Type | Method and Description |
---|---|
static BigDecimal |
abs(BigDecimal value)
Returns the ABS of the value, handles null.
|
static int |
absCompareTo(BigDecimal v1,
BigDecimal v2) |
static BigDecimal |
absDiff(BigDecimal v1,
BigDecimal v2) |
static BigDecimal |
add(BigDecimal start,
BigDecimal... values)
Add n BigDecimal safely (i.e.
|
static BigDecimal |
addWeightedConstituent(BigDecimal runningWeightedVal,
BigDecimal valueToAdd,
BigDecimal weightForValueToAdd,
BigDecimal totalWeight)
Calculate the weight of the constituent and add it to the running weighted value.
|
static boolean |
allNullOrZero(BigDecimal... values) |
static BigDecimal |
assignNonNull(BigDecimal o1,
BigDecimal fallBack) |
static BigDecimal |
bd(String val)
Convenience method to create a BigDecimal with a String, can be statically imported.
|
static BigDecimal |
bigSqrt(BigDecimal c)
Uses Newton Raphson to compute the square root of a BigDecimal.
|
static BigDecimal |
calculateWeight(BigDecimal value,
BigDecimal total) |
static int |
compareTo(BigDecimal v1,
BigDecimal v2) |
static BigDecimal |
decimalPart(BigDecimal val)
Return the decimal part of the value.
|
static BigDecimal |
divide(BigDecimal numerator,
BigDecimal denominator,
int rounding) |
static BigDecimal |
divide(BigDecimal numerator,
BigDecimal denominator,
int scale,
int rounding) |
static BigDecimal |
divide(int numeratorScale,
BigDecimal numerator,
BigDecimal denominator,
int rounding) |
static double |
doubleValue(BigDecimal val) |
static BigDecimal |
ensureMin(BigDecimal minimum,
BigDecimal value)
Return minimum if the value is < minimum.
|
static BigDecimal |
forceNegative(BigDecimal amount)
Return a negative amount based on amount.
|
static BigDecimal |
forceNegativeIfTrue(boolean condition,
BigDecimal amount)
Return a negative amount based on amount if true, otherwise return the ABS.
|
static String |
format(BigDecimal bd)
return a Number formatted or empty string if null.
|
static boolean |
hasSignedChanged(BigDecimal v1,
BigDecimal v2) |
static boolean |
hasSignedFlippedAndNotZero(BigDecimal v1,
BigDecimal v2) |
static boolean |
ifNotNull(BigDecimal bd,
Consumer<BigDecimal> consumer)
If the BigDecimal is not null call the consumer (depends on JDK8+)
|
static BigDecimal |
inverse(BigDecimal value)
Return the inverse of value if no tnull of zero
|
static BigDecimal |
inverse(BigDecimal value,
int scale)
Return the inverse of value if not null or zero, using scale.
|
static BigDecimal |
inverse(BigDecimal value,
int scale,
int rounding)
Return the inverse of value if not null or zero, using scale.
|
static boolean |
isDiffMoreThanAbsThreshold(BigDecimal v1,
BigDecimal v2,
BigDecimal threshold) |
static boolean |
isInsideInclusiveRange(BigDecimal bd,
BigDecimal lowerLimit,
BigDecimal upperLimit) |
static boolean |
isNegative(BigDecimal value) |
static boolean |
isNotSameAbsValue(BigDecimal v1,
BigDecimal v2)
Check ABS values of v1 and v2.
|
static boolean |
isNotSameValue(BigDecimal v1,
BigDecimal v2)
Check values of v1 and v2.
|
static boolean |
isNotZero(BigDecimal value) |
static boolean |
isNullOrZero(BigDecimal value) |
static boolean |
isOutsideRange(BigDecimal bd,
BigDecimal lowerLimit,
BigDecimal upperLimit) |
static boolean |
isSameAbsValue(BigDecimal v1,
BigDecimal v2)
Check ABS values of v1 and v2.
|
static boolean |
isSameSignum(BigDecimal v1,
BigDecimal v2) |
static boolean |
isSameValue(BigDecimal val1,
BigDecimal val2) |
static boolean |
isSameValueTreatNullAsZero(BigDecimal val1,
BigDecimal val2) |
static boolean |
isStrictlyPositive(BigDecimal value) |
static boolean |
isZero(BigDecimal value) |
static boolean |
isZeroOrLess(BigDecimal value) |
static long |
longForFraction(BigDecimal v)
Move by 2 DEC place to the left and take the long value, this
takes care of values like 0.18 in fractions.
|
static BigDecimal |
max(BigDecimal... v1) |
static BigDecimal |
min(BigDecimal v1,
BigDecimal v2) |
static boolean |
movedInsideThresholdPercentage(BigDecimal startValue,
BigDecimal newValue,
BigDecimal thresholdPercent)
true if ABS((startValue-newValue)/startValue) <= abs(thresholdPercent)
|
static boolean |
movedStrictlyOutsideThresholdPercentage(BigDecimal startValue,
BigDecimal newValue,
BigDecimal thresholdPercent)
true if ABS((startValue-newValue)/startValue) > abs(thresholdPercent)
|
static BigDecimal |
movePoint(BigDecimal v1,
int shift)
Safe shift (check for null), shift RIGHT if shift>0.
|
static BigDecimal |
multiply(BigDecimal value,
BigDecimal... multiplicand) |
static BigDecimal |
multiply(BigDecimal value,
BigDecimal multiplicand) |
static BigDecimal |
negate(BigDecimal value)
Returns the negate of the value, handles null.
|
static BigDecimal |
negateIfTrue(boolean condition,
BigDecimal value)
Returns the negate of the value if condition is true, handles null.
|
static String |
percentFormat(BigDecimal bd)
return a Number formatted or empty string if null.
|
static BigDecimal |
roundDown(BigDecimal n,
int p)
Returns a value rounded to p digits after decimal.
|
static BigDecimal |
roundDownForIncrement(BigDecimal n,
BigDecimal increment) |
static BigDecimal |
roundTo(BigDecimal bd,
int numberOfDecPlaces,
int finalScale)
returns a new BigDecimal with correct scale after being round to n dec places.
|
static BigDecimal |
roundUp(BigDecimal n,
int p)
Returns a value rounded-up to p digits after decimal.
|
static BigDecimal |
roundUpForIncrement(BigDecimal n,
BigDecimal increment) |
static BigDecimal |
setScale(BigDecimal bd,
int scale)
returns a new BigDecimal with correct scale.
|
static BigDecimal |
setScale(BigDecimal bd,
Integer scale)
returns a new BigDecimal with correct Scale.
|
static BigDecimal |
setScale(BigDecimal bd,
Integer scale,
int rounding)
returns a new BigDecimal with correct Scales.PERCENT_SCALE.
|
static int |
signum(BigDecimal value)
If value is null return 0 otherwise the signum().
|
static BigDecimal |
subtract(BigDecimal start,
BigDecimal... values)
Subtract n BigDecimal safely from the start value (i.e.
|
public static boolean ifNotNull(BigDecimal bd, Consumer<BigDecimal> consumer)
bd
- the BigDecimalconsumer
- of the value, called if not nullpublic static BigDecimal bd(String val)
val
- a string representing the BigDecimalpublic static BigDecimal inverse(BigDecimal value, int scale)
value
- the nullable BigDecimalscale
- scale for the result if value is not nullpublic static BigDecimal inverse(BigDecimal value, int scale, int rounding)
value
- the nullable BigDecimalscale
- scale for the result if value is not nullrounding
- the rounding (see BigDecimal)public static BigDecimal inverse(BigDecimal value)
value
- the nullable BigDecimalpublic static boolean isNotZero(BigDecimal value)
value
- the nullable BigDecimalpublic static boolean isZero(BigDecimal value)
value
- the nullable BigDecimalpublic static boolean isNegative(BigDecimal value)
value
- the nullable BigDecimalpublic static boolean isStrictlyPositive(BigDecimal value)
value
- the nullable BigDecimalpublic static boolean isNullOrZero(BigDecimal value)
value
- the nullable BigDecimalpublic static boolean isSameValue(BigDecimal val1, BigDecimal val2)
val1
- the nullable BigDecimalval2
- the nullable BigDecimalpublic static boolean isSameValueTreatNullAsZero(BigDecimal val1, BigDecimal val2)
val1
- the nullable BigDecimalval2
- the nullable BigDecimalpublic static BigDecimal add(BigDecimal start, BigDecimal... values)
start
- initial BigDecimalvalues
- series of BigDecimals can be null/emptypublic static BigDecimal subtract(BigDecimal start, BigDecimal... values)
start
- starting point, if null, use 0values
- series of BigDecimal to subtract from start, can be null / emptypublic static BigDecimal divide(BigDecimal numerator, BigDecimal denominator, int rounding)
public static BigDecimal calculateWeight(BigDecimal value, BigDecimal total)
public static BigDecimal divide(int numeratorScale, BigDecimal numerator, BigDecimal denominator, int rounding)
public static BigDecimal divide(BigDecimal numerator, BigDecimal denominator, int scale, int rounding)
public static BigDecimal multiply(BigDecimal value, BigDecimal multiplicand)
public static BigDecimal multiply(BigDecimal value, BigDecimal... multiplicand)
public static BigDecimal abs(BigDecimal value)
value
- nullable BigDecimalpublic static BigDecimal negate(BigDecimal value)
value
- nullable BigDecimalpublic static BigDecimal negateIfTrue(boolean condition, BigDecimal value)
condition
- triggers negatevalue
- nullable BigDecimalpublic static boolean isNotSameAbsValue(BigDecimal v1, BigDecimal v2)
v1
- nullable BigDecimalv2
- nullable BigDecimalpublic static boolean isNotSameValue(BigDecimal v1, BigDecimal v2)
v1
- nullable BigDecimalv2
- nullable BigDecimalpublic static boolean isSameAbsValue(BigDecimal v1, BigDecimal v2)
v1
- nullable BigDecimalv2
- nullable BigDecimalpublic static int compareTo(BigDecimal v1, BigDecimal v2)
public static int absCompareTo(BigDecimal v1, BigDecimal v2)
public static BigDecimal absDiff(BigDecimal v1, BigDecimal v2)
public static BigDecimal movePoint(BigDecimal v1, int shift)
public static BigDecimal roundTo(BigDecimal bd, int numberOfDecPlaces, int finalScale)
bd
- valuenumberOfDecPlaces
- number of dec place to round tofinalScale
- final scale of result (typically numberOfDecPlaces < finalScale);public static BigDecimal setScale(BigDecimal bd, int scale)
bd
- public static BigDecimal setScale(BigDecimal bd, Integer scale)
bd
- public static BigDecimal setScale(BigDecimal bd, Integer scale, int rounding)
bd
- public static int signum(BigDecimal value)
value
- public static boolean isSameSignum(BigDecimal v1, BigDecimal v2)
public static boolean hasSignedFlippedAndNotZero(BigDecimal v1, BigDecimal v2)
public static boolean hasSignedChanged(BigDecimal v1, BigDecimal v2)
public static boolean isOutsideRange(BigDecimal bd, BigDecimal lowerLimit, BigDecimal upperLimit)
bd
- lowerLimit
- upperLimit
- public static boolean isInsideInclusiveRange(BigDecimal bd, BigDecimal lowerLimit, BigDecimal upperLimit)
bd
- lowerLimit
- upperLimit
- public static BigDecimal assignNonNull(BigDecimal o1, BigDecimal fallBack)
public static BigDecimal addWeightedConstituent(BigDecimal runningWeightedVal, BigDecimal valueToAdd, BigDecimal weightForValueToAdd, BigDecimal totalWeight)
runningWeightedVal
- valueToAdd
- weightForValueToAdd
- totalWeight
- public static boolean allNullOrZero(BigDecimal... values)
public static String format(BigDecimal bd)
bd
- public static String percentFormat(BigDecimal bd)
bd
- public static boolean movedInsideThresholdPercentage(BigDecimal startValue, BigDecimal newValue, BigDecimal thresholdPercent)
startValue
- newValue
- thresholdPercent
- public static boolean movedStrictlyOutsideThresholdPercentage(BigDecimal startValue, BigDecimal newValue, BigDecimal thresholdPercent)
startValue
- newValue
- thresholdPercent
- public static BigDecimal roundUp(BigDecimal n, int p)
If n is negative, the resulting value is obtained as the round-up value of absolute value of n multiplied by the sign value of n (@see MathX.sign(double d)). Thus, -0.2 rounded-up to p=0 will give -1 not 0.
If n is NaN, returned value is NaN.
n
- p
- public static BigDecimal roundDown(BigDecimal n, int p)
If n is negative, the resulting value is obtained as the round-up value of absolute value of n multiplied by the sign value of n (@see MathX.sign(double d)). Thus, -0.8 rounded-down to p=0 will give 0 not -1.
If n is NaN, returned value is NaN.
n
- p
- public static BigDecimal roundUpForIncrement(BigDecimal n, BigDecimal increment)
public static BigDecimal roundDownForIncrement(BigDecimal n, BigDecimal increment)
public static BigDecimal ensureMin(BigDecimal minimum, BigDecimal value)
public static BigDecimal forceNegative(BigDecimal amount)
public static BigDecimal forceNegativeIfTrue(boolean condition, BigDecimal amount)
public static BigDecimal min(BigDecimal v1, BigDecimal v2)
public static BigDecimal max(BigDecimal... v1)
public static long longForFraction(BigDecimal v)
public static boolean isDiffMoreThanAbsThreshold(BigDecimal v1, BigDecimal v2, BigDecimal threshold)
public static double doubleValue(BigDecimal val)
public static boolean isZeroOrLess(BigDecimal value)
public static BigDecimal decimalPart(BigDecimal val)
val
- public static BigDecimal bigSqrt(BigDecimal c)
c
- the BigDecimal for which we want the SQRT.Copyright © 2006–2022 Appendium - Portfolio Financing Platform. All rights reserved.