Java Utililty Methods BigDecimal

List of utility methods to do BigDecimal

Description

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

Method

BigDecimalexp(BigDecimal x, int scale)
Compute e^x to a given scale.
if (x.signum() == 0) {
    return BigDecimal.valueOf(1);
else if (x.signum() == -1) {
    return BigDecimal.valueOf(1).divide(exp(x.negate(), scale), scale, BigDecimal.ROUND_HALF_EVEN);
BigDecimal xWhole = x.setScale(0, BigDecimal.ROUND_DOWN);
if (xWhole.signum() == 0)
...
StringexponentialFormatBigDecimal(BigDecimal bd)
Formats the given BigDecimal value into a floating-point literal (like we find in SQL).
String digits = bd.unscaledValue().abs().toString();
int scale = bd.scale();
int len = digits.length();
while (len > 1 && digits.charAt(len - 1) == '0') {
    --scale;
    --len;
if (len < digits.length()) {
...
BigDecimalexpTaylor(BigDecimal x, int scale)
Compute e^x to a given scale by the Taylor series.
BigDecimal factorial = BigDecimal.valueOf(1);
BigDecimal xPower = x;
BigDecimal sumPrev;
BigDecimal sum = x.add(BigDecimal.valueOf(1));
int i = 2;
do {
    xPower = xPower.multiply(x).setScale(scale, BigDecimal.ROUND_HALF_EVEN);
    factorial = factorial.multiply(BigDecimal.valueOf(i));
...
BigDecimalextractBigDecimal(String value)
Extract a BigDecimal instance.
if (value != null) {
    return new BigDecimal(value);
} else {
    return null;
BigDecimalfirstNonZero(final BigDecimal... values)
first Non Zero
for (BigDecimal value : values) {
    if (value != null && value.compareTo(BigDecimal.ZERO) != 0) {
        return value;
return BigDecimal.ZERO;
floatfloatValue(BigDecimal val)
Berekent float waarde van BigDecimal
float tempFloat = 0.0f;
if (val != null) {
    tempFloat = val.floatValue();
return tempFloat;
BigDecimalfromLongToBigDecimal(long longValue)
from Long To Big Decimal
double doubleValue = ((double) longValue / 100.0);
return new BigDecimal(doubleValue);
BigDecimalgetArcCosineFor(BigDecimal radians)
Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.
return setScale(BigDecimal.valueOf(Math.acos(radians.doubleValue())));
DoublegetAsDouble(BigDecimal value)
Gets the as double.
return value == null ? null : value.doubleValue();
StringgetBalance(BigDecimal balance)
Rounds a balance with 2 digits
return balance.setScale(2, RoundingMode.HALF_EVEN).toString();