Java BigDecimal Multiply multiply(BigDecimal amount, BigDecimal multiplicand, int scale)

Here you can find the source of multiply(BigDecimal amount, BigDecimal multiplicand, int scale)

Description

multiply

License

Open Source License

Declaration

public static BigDecimal multiply(BigDecimal amount, BigDecimal multiplicand, int scale) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static BigDecimal multiply(BigDecimal amount, BigDecimal multiplicand, int scale) {
        return roundBigDecimal(amount.multiply(multiplicand), scale);
    }/*from  w  w  w . j av a  2 s.com*/

    public static BigDecimal multiply(BigDecimal... amounts) {
        return multiply(2, amounts);
    }

    public static BigDecimal multiply(int scale, BigDecimal... amounts) {
        BigDecimal result = null;
        for (BigDecimal bigDecimal : amounts) {
            if (bigDecimal != null) {
                result = result == null ? bigDecimal : result.multiply(bigDecimal);
            }
        }
        return roundBigDecimal(result, scale);
    }

    public static BigDecimal roundBigDecimal(BigDecimal num) {
        return roundBigDecimal(num, 2);
    }

    public static BigDecimal roundBigDecimal(BigDecimal num, int scale) {
        if (num != null) {
            return num.setScale(scale, RoundingMode.HALF_UP);
        }
        return num;
    }
}

Related

  1. mul(BigDecimal v1, BigDecimal v2)
  2. mul(BigDecimal v1, BigDecimal v2)
  3. multiple(BigDecimal dividend, int divisor)
  4. multiply(BigDecimal a, BigDecimal b)
  5. multiply(BigDecimal a, int multiplier)
  6. multiply(BigDecimal aValue1, BigDecimal aValue2)
  7. multiply(BigDecimal bigDecimal, BigDecimal bigDecimal2)
  8. multiply(BigDecimal left, BigDecimal right)
  9. multiply(BigDecimal multiplier1, BigDecimal multiplier2, int scale)