Example usage for java.math BigDecimal multiply

List of usage examples for java.math BigDecimal multiply

Introduction

In this page you can find the example usage for java.math BigDecimal multiply.

Prototype

private static long multiply(long x, long y) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    MathContext mc = new MathContext(4); // 4 precision

    BigDecimal bg1 = new BigDecimal("1.230");
    BigDecimal bg2 = new BigDecimal("4.560");

    // multiply bg1 with bg2 using mc
    BigDecimal bg3 = bg1.multiply(bg2, mc);

    System.out.println(bg3);/*from w ww  . j  av a2  s.co  m*/
}

From source file:org.kuali.kpme.core.util.TKUtils.java

public static long convertHoursToMillis(BigDecimal hours) {
    return hours.multiply(HrConstants.BIG_DECIMAL_MS_IN_H, HrConstants.MATH_CONTEXT).longValue();
}

From source file:org.multibit.utils.CSMiscUtils.java

@Deprecated
public static BigInteger calcRawPercentageCharge(CSAsset asset, BigInteger transferAmount) {
    CoinSparkGenesis genesis = asset.getGenesis();
    int chargeBasisPoints = genesis.getChargeBasisPoints();
    if (chargeBasisPoints == 0)
        return BigInteger.ZERO;
    BigDecimal d = new BigDecimal(chargeBasisPoints);
    d = d.movePointLeft(2 + 2); // 2 to get whole percent number, another 2 to get fraction
    d = d.multiply(new BigDecimal(transferAmount), MathContext.UNLIMITED);
    return d.toBigInteger();
}

From source file:com.idylwood.utils.MathUtils.java

static final double multiplyAndSumSlow(final double[] values, final double scale) {
    BigDecimal ret = new BigDecimal(0);
    for (double x : values)
        ret = ret.add(new BigDecimal(x), MathContext.UNLIMITED);
    return ret.multiply(new BigDecimal(scale), MathContext.UNLIMITED).doubleValue();
}

From source file:org.mifosplatform.portfolio.loanaccount.domain.LoanCharge.java

public static BigDecimal percentageOf(final BigDecimal value, final BigDecimal percentage) {

    BigDecimal percentageOf = BigDecimal.ZERO;

    if (isGreaterThanZero(value)) {
        final MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN);
        final BigDecimal multiplicand = percentage.divide(BigDecimal.valueOf(100l), mc);
        percentageOf = value.multiply(multiplicand, mc);
    }/*from  w w w  .  j  av  a  2 s .  co m*/
    return percentageOf;
}

From source file:org.apache.fineract.portfolio.loanaccount.domain.LoanCharge.java

public static BigDecimal percentageOf(final BigDecimal value, final BigDecimal percentage) {

    BigDecimal percentageOf = BigDecimal.ZERO;

    if (isGreaterThanZero(value)) {
        final MathContext mc = new MathContext(8, MoneyHelper.getRoundingMode());
        final BigDecimal multiplicand = percentage.divide(BigDecimal.valueOf(100l), mc);
        percentageOf = value.multiply(multiplicand, mc);
    }/*from   w  w w. j  av a2 s.  co  m*/
    return percentageOf;
}

From source file:com.qcadoo.mes.operationTimeCalculations.OrderRealizationTimeServiceImpl.java

private BigDecimal getQuantityCyclesNeededToProducedNextOperationAfterProducedQuantity(
        final Entity operationComponent, final BigDecimal nextOperationAfterProducedQuantity) {
    MathContext mc = numberService.getMathContext();
    Entity technology = operationComponent.getBelongsToField("technology");

    Map<Long, BigDecimal> operationRunsFromProductionQuantities = Maps.newHashMap();

    OperationProductComponentWithQuantityContainer productQuantities = productQuantitiesService
            .getProductComponentQuantities(technology, BigDecimal.ONE, operationRunsFromProductionQuantities);

    BigDecimal operationsRunsForOneMainProduct = operationRunsFromProductionQuantities
            .get(operationComponent.getId());
    BigDecimal quantityOutputProductProduced = productQuantities.get(getOutputProduct(operationComponent));
    BigDecimal cycles = operationsRunsForOneMainProduct.multiply(nextOperationAfterProducedQuantity, mc)
            .divide(quantityOutputProductProduced, mc);

    return numberService.setScale(cycles);
}

From source file:com.gst.portfolio.shareaccounts.domain.ShareAccountCharge.java

private BigDecimal percentageOf(final BigDecimal value, final BigDecimal percentage) {
    BigDecimal percentageOf = BigDecimal.ZERO;
    if (isGreaterThanZero(value)) {
        final MathContext mc = new MathContext(8, MoneyHelper.getRoundingMode());
        final BigDecimal multiplicand = percentage.divide(BigDecimal.valueOf(100l), mc);
        percentageOf = value.multiply(multiplicand, mc);
    }/*from ww  w . j  a  v a 2 s  .  co m*/
    return percentageOf;
}

From source file:com.qcadoo.mes.deliveries.DeliveriesServiceImpl.java

private void calculatePriceUsingPricePerUnit(final ViewDefinitionState view, FieldComponent quantityField,
        FieldComponent pricePerUnitField) {
    FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(L_TOTAL_PRICE);

    Locale locale = view.getLocale();

    BigDecimal pricePerUnit = getBigDecimalFromField(pricePerUnitField, locale);
    BigDecimal quantity = getBigDecimalFromField(quantityField, locale);

    BigDecimal totalPrice = numberService
            .setScale(pricePerUnit.multiply(quantity, numberService.getMathContext()));

    totalPriceField.setFieldValue(numberService.format(totalPrice));
    totalPriceField.requestComponentUpdateState();
}

From source file:com.qcadoo.mes.deliveries.DeliveriesServiceImpl.java

private BigDecimal calculateTotalPrice(final BigDecimal quantity, final BigDecimal pricePerUnit) {
    BigDecimal totalPrice = BigDecimal.ZERO;

    if ((quantity == null) || (BigDecimal.ZERO.compareTo(quantity) == 0)) {
        totalPrice = BigDecimal.ZERO;
    } else {/*from w w w  . ja  v  a  2 s .c  om*/
        totalPrice = pricePerUnit.multiply(quantity, numberService.getMathContext());
    }

    return totalPrice;
}