Class MathUtil
java.lang.Object
com.bluebell.greenhouse.platform.util.math.MathUtil
General arithmetic and number formatting service.
- Version:
- 2.0.2
- Author:
- Stephen Prizio
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleadd(double a, double b) Performs a basic sum.static BigDecimaladd(BigDecimal a, BigDecimal b) Performs a basicBigDecimalsum.static intclamp(int value, int min, int max) Clamps a number between a minimum and maximum value.static doublecomputeIncrement(double a, double b, boolean absolute) Computes the increment change on a by b.static doubledelta(double a, double b) Obtains the percentage change rounded to a number larger than 1 Example: 9 / 87 would normally be 0.103448, this method would return 10.34.static doubledivide(double a, double b) Performs a basic divide with safe dividend.static BigDecimaldivide(BigDecimal a, BigDecimal b) Performs a safeBigDecimaldivide.static BigDecimaldivide(BigDecimal a, BigDecimal b, int scale, RoundingMode roundingMode) Performs a safeBigDecimaldivide.static doublegetDouble(double d) Gets a roundedDoubleto 2 decimal places.static intgetInteger(double d) Gets a roundedInteger.static longgetLong(double d) Gets a roundedLong.static BigDecimalmax(BigDecimal... values) Returns the maximum value.static doublemultiply(double a, double b) Performs a basic multiply.static BigDecimalmultiply(BigDecimal a, BigDecimal b) Performs a basicBigDecimalmultiply.static BigDecimalorZero(BigDecimal value) Returns zero when the value is null.static doublepercentageChange(double a, double b) Obtains the percentage change between 2 numbers.static intpercentagePosition(BigDecimal value, BigDecimal min, BigDecimal max) Resolves a value's position in a range as a 0 to 100 percentage.static doublesubtract(double a, double b) Performs a basic difference.static BigDecimalsubtract(BigDecimal a, BigDecimal b) Performs a basicBigDecimaldifference.static doubletoDouble(BigDecimal value) Converts aBigDecimalinto a rounded double.static inttoPercentage(BigDecimal value) Converts a fractional score into a whole-number percentage.static inttoWholeNumber(BigDecimal value) Rounds to the nearest whole number.static doubleweightedAverage(double a, double countA, double b, double countB) Computes the average of 2 different averages.static intwholePercentage(double a, double b) Obtains a whole percentage rounded to the nearest integer Example : 3 / 10 = 33.
-
Method Details
-
getDouble
-
getInteger
-
getLong
-
toDouble
Converts aBigDecimalinto a rounded double.- Parameters:
value- value- Returns:
- rounded double
-
orZero
Returns zero when the value is null.- Parameters:
value- value- Returns:
- non-null value
-
max
Returns the maximum value.- Parameters:
values- values- Returns:
- maximum value
-
toWholeNumber
Rounds to the nearest whole number.- Parameters:
value- value- Returns:
- rounded number
-
toPercentage
Converts a fractional score into a whole-number percentage.- Parameters:
value- fractional score- Returns:
- percentage
-
clamp
public static int clamp(int value, int min, int max) Clamps a number between a minimum and maximum value.- Parameters:
value- valuemin- minimum valuemax- maximum value- Returns:
- clamped value
-
percentagePosition
Resolves a value's position in a range as a 0 to 100 percentage.- Parameters:
value- valuemin- minimum range valuemax- maximum range value- Returns:
- percentage position
-
add
Performs a basicBigDecimalsum.- Parameters:
a- first valueb- second value- Returns:
- sum
-
subtract
Performs a basicBigDecimaldifference.- Parameters:
a- first valueb- second value- Returns:
- difference
-
multiply
Performs a basicBigDecimalmultiply.- Parameters:
a- first valueb- second value- Returns:
- product
-
divide
Performs a safeBigDecimaldivide.- Parameters:
a- dividendb- divisor- Returns:
- quotient
-
divide
Performs a safeBigDecimaldivide.- Parameters:
a- dividendb- divisorscale- result scaleroundingMode- rounding mode- Returns:
- quotient
-
add
-
subtract
-
divide
-
multiply
-
delta
-
wholePercentage
-
computeIncrement
-
percentageChange
-
weightedAverage
public static double weightedAverage(double a, double countA, double b, double countB) Computes the average of 2 different averages.- Parameters:
a- first averagecountA- count ab- second averagecountB- count b- Returns:
- average of both averages
-