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

BigDecimalgetPercentage(BigDecimal amount, BigDecimal percent)
get Percentage
return divide(amount.multiply(percent), ONE_HUNDRED);
BigDecimalgetPercentageValue(BigDecimal price, double amount)
get Percentage Value
return price.multiply(new BigDecimal(amount / 100));
BigDecimalgetProfit(BigDecimal ask, BigDecimal bid, BigDecimal fee)
Get the profit of an operation from its ask/bid and fees values
BigDecimal one = new BigDecimal(1);
BigDecimal oneMinusFee = one.subtract(fee);
BigDecimal omfPow = oneMinusFee.multiply(oneMinusFee);
BigDecimal profit = ask.divide(bid, 8, RoundingMode.FLOOR).multiply(omfPow).subtract(one);
return profit;
BigDecimalgetProzentWert(BigDecimal zahl, BigDecimal prozentsatz, int nachkommastellen)
Den Wert eines Prozentsatzes einer Zahl berechnen, kaufmaennisch auf n Nachkommastellen gerundet.
BigDecimal prozentsatz2 = prozentsatz.movePointLeft(2);
BigDecimal result = zahl.multiply(prozentsatz2);
return rundeKaufmaennisch(result, nachkommastellen);
BigDecimalgetRandomBigDecimal(BigDecimal a, BigDecimal b)
get Random Big Decimal
double randomNum = Math.random();
return a.add((b.subtract(a)).multiply(new BigDecimal(randomNum)));
BigDecimalgetRandomBigDecimal(int maxValue, int scale)
get Random Big Decimal
Random generator = new Random();
double d = (double) generator.nextInt(maxValue) + generator.nextDouble();
BigDecimal decimal = new BigDecimal(d);
BigDecimal result = decimal.setScale(scale, RoundingMode.FLOOR);
return result;
BigDecimalgetRandomPriceChangeFactor(BigDecimal currentPrice)
get Random Price Change Factor
if (currentPrice.compareTo(PENNY_STOCK_P) == -1 || currentPrice.compareTo(PENNY_STOCK_P) == 0) {
    return JUNK_STOCK_MIRACLE_MULTIPLIER;
} else if (currentPrice.compareTo(STOCK_P_HIGH_BAR) == 1 || currentPrice.compareTo(STOCK_P_HIGH_BAR) == 0) {
    return STOCK_P_HIGH_BAR_CRASH;
BigDecimal factor = BigDecimal.valueOf(0);
Random rand = new Random();
int y = rand.nextInt(STOCK_CHANGE_MAX_PERCENT.subtract(BigDecimal.ONE).intValue());
...
intgetRecordSize(List> columnBaseData)
get Record Size
if (columnBaseData == null || columnBaseData.size() == 0) {
    return 0;
if (columnBaseData.get(0) == null) {
    return 0;
return columnBaseData.get(0).size();
doublegetRSBigDecimal(Object object)
getRSBigDecimal, get fields value from a object
if (object == null)
    return (double) 0;
return ((BigDecimal) object).doubleValue();
intgetScale(BigDecimal bd1, BigDecimal bd2)
get Scale
int scale1 = 0;
int scale2 = 0;
if (bd1 != null) {
    scale1 = bd1.scale();
if (bd2 != null) {
    scale2 = bd2.scale();
return (scale1 > scale2 ? scale1 : scale2);