List of utility methods to do BigDecimal Calculate
BigDecimal | calculateMonthCapital(BigDecimal eachIssueMoney, BigDecimal eachMonthInterest) calculate Month Capital return eachIssueMoney.subtract(eachMonthInterest);
|
BigDecimal | calculateMonthInterest(Float interestRate, BigDecimal investmoney) calculate Month Interest return investmoney.multiply(new BigDecimal(Float.toString(interestRate))) .multiply(BigDecimal.ONE.divide(new BigDecimal(12), 10, RoundingMode.HALF_UP)); |
BigDecimal | calculatePercentChange(BigDecimal from, BigDecimal to) calculate Percent Change BigDecimal difference = to.subtract(from);
return difference.divide(from, 8, RoundingMode.HALF_UP).multiply(CENT);
|
BigDecimal | calculateProfit(BigDecimal totalAmt, Integer duration, BigDecimal rate) calculate Profit Calendar cal = Calendar.getInstance(); int maxDayNum = cal.getActualMaximum(Calendar.DAY_OF_YEAR); return totalAmt.multiply(new BigDecimal(duration)).multiply(rate).divide(new BigDecimal(maxDayNum * 100), 2, RoundingMode.CEILING); |
BigDecimal | calculateRatioInDecimal(BigDecimal numberA, BigDecimal numberB) berechnet das prozentuelle verhaeltnis von 2 Zahlen BigDecimal result = null; if (numberA.compareTo(numberB) < 0) { result = new BigDecimal(1).subtract(numberA.divide(numberB, BigDecimal.ROUND_HALF_EVEN)); } else if (numberA.compareTo(numberB) == 0) { result = new BigDecimal(0); } else { result = new BigDecimal(1).subtract(numberB.divide(numberA, BigDecimal.ROUND_HALF_EVEN)); return result.multiply(new BigDecimal(100.0)); |
BigDecimal | coerce(BigDecimal val, int targetPrecision, int targetScale) Attempts to coerce a big decimal to a target precision and scale and returns the result. if (val.scale() != targetScale) { try { val = val.setScale(targetScale, RoundingMode.UNNECESSARY); } catch (ArithmeticException ex) { throw new IllegalArgumentException( "Value scale " + val.scale() + " can't be coerced to target scale " + targetScale + ". "); if (val.precision() > targetPrecision) { throw new IllegalArgumentException("Value precision " + val.precision() + " (after scale coercion) can't be coerced to target precision " + targetPrecision + ". "); return val; |
BigDecimal | cosh(final BigDecimal dec, final int scale, final RoundingMode mode) This method calculates the cosh using a series expansion. This method uses the #factorial(int) method for demoninators, and #power(BigDecimal,long) for exponents. This expansion ceases execution when the next component in the series is equal to zero for the given scale. BigDecimal value = BigDecimal.ONE; int nextIndex = 1; do { final int exponent = nextIndex++ << 1; final BigDecimal entry = power(dec, exponent) .divide(new BigDecimal(factorial(exponent)), scale, mode); if (entry.unscaledValue().equals(BigInteger.ZERO)) break; ... |
BigDecimal | cosine(BigDecimal x) cosine BigDecimal currentValue = BigDecimal.ONE; BigDecimal lastVal = currentValue.add(BigDecimal.ONE); BigDecimal xSquared = x.multiply(x); BigDecimal numerator = BigDecimal.ONE; BigDecimal denominator = BigDecimal.ONE; int i = 0; while (lastVal.compareTo(currentValue) != 0) { lastVal = currentValue; ... |