Java Utililty Methods BigDecimal Calculate

List of utility methods to do BigDecimal Calculate

Description

The list of methods to do BigDecimal Calculate are organized into topic(s).

Method

StringcalcBMI(BigDecimal lbs, BigDecimal inches)
Calc BMI consistent with CPRS to two decimal places.
BigDecimal bmi = BigDecimal.valueOf(lbs.doubleValue() / 2.2).divide(
        BigDecimal.valueOf(inches.doubleValue() * inches.doubleValue() / 1550.0031000062), 2,
        BigDecimal.ROUND_HALF_UP);
return bmi.toString();
doublecalcDistance(final BigDecimal x1, final BigDecimal y1, final BigDecimal x2, final BigDecimal y2)
Calculates distance traveled between two sequential messages.
return calcDistance(x1.doubleValue(), y1.doubleValue(), x2.doubleValue(), y2.doubleValue());
intcalcPercentage(int priceInCents, BigDecimal vat)
calc Percentage
return new BigDecimal(priceInCents).multiply(vat.divide(HUNDRED, 5, UP)).setScale(0, HALF_UP)
        .intValueExact();
BigDecimalcalculate(BigDecimal number1, String operator, BigDecimal number2, int decimalPlaces)
calculate
if (number1 == null) {
    number1 = BigDecimal.ZERO;
if (number2 == null) {
    number2 = BigDecimal.ZERO;
switch (operator) {
case ADD:
...
BigDecimalcalculateArithmeticMean(BigDecimal[] values)
Get the arithmetic mean for a set of values.
if (values.length == 1) {
    return values[0].setScale(DECIMAL_SCALE, BigDecimal.ROUND_HALF_UP);
BigDecimal arithmeticMean = BigDecimal.valueOf(0d);
for (BigDecimal value : values) {
    arithmeticMean = arithmeticMean.add(value);
arithmeticMean = arithmeticMean.divide(BigDecimal.valueOf(values.length), DECIMAL_SCALE,
...
BigDecimalcalculateDayRate(BigDecimal rate, BigDecimal money)
calculate Day Rate
rate = rate.divide(new BigDecimal(365), 10, RoundingMode.HALF_UP);
return rate.multiply(money);
doublecalculateDeviation(BigDecimal v1, BigDecimal v2)
calculate Deviation
if (v1 == null || v2 == null) {
    return 0;
double dv1 = v1.doubleValue();
double dv2 = v2.doubleValue();
return calculateDeviation(dv1, dv2);
BigDecimalcalculateDivide(BigDecimal numerator, BigDecimal denominator)
calculate Divide
BigDecimal result = BigDecimal.ZERO;
if (denominator.compareTo(BigDecimal.ZERO) != 0) {
    result = numerator.divide(denominator, 3, BigDecimal.ROUND_HALF_UP);
return result;
BigDecimalcalculateGainPercentage(BigDecimal gain, BigDecimal totalGains)
calculate Gain Percentage
BigDecimal percent = BigDecimal.valueOf(0);
percent = gain.divide(totalGains, 4, RoundingMode.HALF_UP);
percent = percent.multiply(BigDecimal.valueOf(100), new MathContext(4, RoundingMode.HALF_UP));
return percent;
BigDecimalcalculateLHS(BigDecimal a, Vector Bj, Vector Bj1)
calculate LHS
return dotProduct(add(Bj1, scalarMult(a, Bj)));