Package org.cyclos.utils
Class BigDecimalHelper
- java.lang.Object
-
- org.cyclos.utils.BigDecimalHelper
-
public class BigDecimalHelper extends Object
Helper class for handlingBigDecimals.
-
-
Field Summary
Fields Modifier and Type Field Description static MathContextMATH_CONTEXTA math context with precision = 15 +MAX_SCALE, withRoundingMode.HALF_UPstatic intMAX_SCALEstatic BigDecimalONE_HUNDRED
-
Constructor Summary
Constructors Constructor Description BigDecimalHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareEquals(BigDecimal bd1, BigDecimal bd2)static booleanareEqualsOrBothNull(BigDecimal bd1, BigDecimal bd2)static intcompareTo(BigDecimal bd1, BigDecimal bd2)static inthashCode(BigDecimal bd1)static booleanisNegative(BigDecimal number)Returns whether the given number is a negative, non-zero number, given a precision deltastatic booleanisNegativeOrZero(BigDecimal number)Returns whether the given number is a negative or zero number, given a precision deltastatic booleanisPositive(BigDecimal number)Returns whether the given number is a positive, non-zero number, given a precision deltastatic booleanisPositiveOrZero(BigDecimal number)Returns whether the given number is a positive or zero number, given a precision deltastatic booleanisZero(BigDecimal number)Returns whether the given number is a negative, non-zero number, given a precision deltastatic BigDecimalmax(BigDecimal bd1, BigDecimal bd2)static BigDecimalmin(BigDecimal bd1, BigDecimal bd2)static BigDecimalnegative(BigDecimal bigDecimal)Returns a negative representation of the given number.static BigDecimalpositive(BigDecimal bigDecimal)Returns a positive representation of the given number.static BigDecimalround(BigDecimal number, int scale)Rounds the given number to the given scalestatic BigDecimaltoBigDecimal(String intPart, String decimalPart)Converts the given integer part and decimal part to a BigDecimal value.static BigDecimalzeroWhenNull(BigDecimal bigDecimal)Returns zero when the given BigDecimal is null
-
-
-
Field Detail
-
ONE_HUNDRED
public static final BigDecimal ONE_HUNDRED
-
MAX_SCALE
public static final int MAX_SCALE
-
MATH_CONTEXT
public static final MathContext MATH_CONTEXT
A math context with precision = 15 +MAX_SCALE, withRoundingMode.HALF_UP
-
-
Method Detail
-
areEquals
public static boolean areEquals(BigDecimal bd1, BigDecimal bd2)
-
areEqualsOrBothNull
public static boolean areEqualsOrBothNull(BigDecimal bd1, BigDecimal bd2)
-
compareTo
public static int compareTo(BigDecimal bd1, BigDecimal bd2)
-
hashCode
public static int hashCode(BigDecimal bd1)
-
isNegative
public static boolean isNegative(BigDecimal number)
Returns whether the given number is a negative, non-zero number, given a precision delta
-
isNegativeOrZero
public static boolean isNegativeOrZero(BigDecimal number)
Returns whether the given number is a negative or zero number, given a precision delta
-
isPositive
public static boolean isPositive(BigDecimal number)
Returns whether the given number is a positive, non-zero number, given a precision delta
-
isPositiveOrZero
public static boolean isPositiveOrZero(BigDecimal number)
Returns whether the given number is a positive or zero number, given a precision delta
-
isZero
public static boolean isZero(BigDecimal number)
Returns whether the given number is a negative, non-zero number, given a precision delta
-
max
public static BigDecimal max(BigDecimal bd1, BigDecimal bd2)
-
min
public static BigDecimal min(BigDecimal bd1, BigDecimal bd2)
-
negative
public static BigDecimal negative(BigDecimal bigDecimal)
Returns a negative representation of the given number. If null or already negative, return as is. Otherwise, returns the negated value.
-
positive
public static BigDecimal positive(BigDecimal bigDecimal)
Returns a positive representation of the given number. If null or already positive, return as is. Otherwise, returns the negated value.
-
round
public static BigDecimal round(BigDecimal number, int scale)
Rounds the given number to the given scale
-
toBigDecimal
public static BigDecimal toBigDecimal(String intPart, String decimalPart)
Converts the given integer part and decimal part to a BigDecimal value. If either is null, returns null.
-
zeroWhenNull
public static BigDecimal zeroWhenNull(BigDecimal bigDecimal)
Returns zero when the given BigDecimal is null
-
-