Example usage for java.math BigDecimal divideAndRemainder

List of usage examples for java.math BigDecimal divideAndRemainder

Introduction

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

Prototype

public BigDecimal[] divideAndRemainder(BigDecimal divisor) 

Source Link

Document

Returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

Usage

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123.145");
    BigDecimal bg2 = new BigDecimal("110.01");

    BigDecimal bg[] = bg1.divideAndRemainder(bg2);

    System.out.println("Quotient is " + bg[0]);
    System.out.println("Remainder is " + bg[1]);
}

From source file:com.inkubator.hrm.service.impl.PayTempKalkulasiServiceImpl.java

@Override
@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void executeBatchFinalSalaryCalculation(EmpData empData) throws ScriptException {
    PayTempKalkulasiEmpPajak tax_23 = payTempKalkulasiEmpPajakDao
            .getEntityByEmpDataIdAndTaxComponentId(empData.getId(), 23L);
    PayTempKalkulasi taxKalkulasi = payTempKalkulasiDao
            .getEntityByEmpDataIdAndSpecificModelComponent(empData.getId(), HRMConstant.MODEL_COMP_TAX);
    //jika pajak PPh pasal 21 kurang dari 0(minus), maka di set 0 saja di payTempKalkulasi
    if (tax_23.getNominal() > 0) {
        taxKalkulasi.setNominal(new BigDecimal(tax_23.getNominal()));
    } else {// w  w  w  . j  ava 2  s  .  c  o m
        taxKalkulasi.setNominal(new BigDecimal(0));
    }
    payTempKalkulasiDao.update(taxKalkulasi);

    PayTempKalkulasi ceilKalkulasi = payTempKalkulasiDao
            .getEntityByEmpDataIdAndSpecificModelComponent(empData.getId(), HRMConstant.MODEL_COMP_CEIL);
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
    double ceiling = (Double) jsEngine.eval(ceilKalkulasi.getPaySalaryComponent().getFormula());

    PayTempKalkulasi totalIncomeKalkulasi = payTempKalkulasiDao.getEntityByEmpDataIdAndSpecificModelComponent(
            empData.getId(), HRMConstant.MODEL_COMP_TAKE_HOME_PAY);
    BigDecimal totalIncome = totalIncomeKalkulasi.getNominal();
    totalIncome = this.calculateTotalIncome(totalIncome, taxKalkulasi);

    //dapatkan nilai sisa/pembulatan
    BigDecimal val[] = totalIncome.divideAndRemainder(new BigDecimal(ceiling));

    ceilKalkulasi.setNominal(val[1]);
    payTempKalkulasiDao.update(ceilKalkulasi);

    totalIncome = this.calculateTotalIncome(totalIncome, ceilKalkulasi);
    totalIncomeKalkulasi.setNominal(totalIncome);
    payTempKalkulasiDao.update(totalIncomeKalkulasi);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static BigDecimal mod(BigDecimal b0, BigDecimal b1) {
    final BigDecimal[] bigDecimals = b0.divideAndRemainder(b1);
    return bigDecimals[1];
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static BigDecimal floor(BigDecimal b0, BigDecimal b1) {
    final BigDecimal[] bigDecimals = b0.divideAndRemainder(b1);
    BigDecimal r = bigDecimals[1];
    if (r.signum() < 0) {
        r = r.add(b1);//from  ww  w . j a  v  a 2  s  . c o m
    }
    return b0.subtract(r);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static BigDecimal ceil(BigDecimal b0, BigDecimal b1) {
    final BigDecimal[] bigDecimals = b0.divideAndRemainder(b1);
    BigDecimal r = bigDecimals[1];
    if (r.signum() > 0) {
        r = r.subtract(b1);/*ww  w .  ja  v  a 2s .c o m*/
    }
    return b0.subtract(r);
}

From source file:org.libreplan.business.planner.entities.SigmoidFunction.java

private BigDecimal calculateReminder(BigDecimal decimalPart, BigDecimal truncateValue) {
    BigDecimal[] result = decimalPart.divideAndRemainder(truncateValue);
    return result[1];
}

From source file:org.openvpms.component.system.common.jxpath.BigDecimalOperationMod.java

@Override
public Object computeValue(EvalContext context) {
    BigDecimal l = TypeConversionUtil.bigDecimalValue(args[0].computeValue(context));
    BigDecimal r = TypeConversionUtil.bigDecimalValue(args[1].computeValue(context));

    return l.divideAndRemainder(r)[1];
}

From source file:org.openvpms.hl7.impl.TestPharmacyService.java

/**
 * Dispenses an order.//from ww w .jav  a 2 s .  c  o m
 *
 * @param order the order
 */
private void dispense(RDE_O11 order) {
    Connection connection = null;
    try {
        connection = sendContext.newClient(outboundHost, outboundPort, false);

        RXO rxo = order.getORDER().getORDER_DETAIL().getRXO();
        BigDecimal quantity = new BigDecimal(rxo.getRequestedDispenseAmount().getValue());
        if (quantity.compareTo(BigDecimal.ONE) != 0 && dispenses != 1) {
            BigDecimal[] decimals = quantity.divideAndRemainder(BigDecimal.valueOf(dispenses));
            for (int i = 0; i < dispenses; ++i) {
                BigDecimal qty = (i == 0) ? decimals[0].add(decimals[1]) : decimals[0];
                RDS_O13 dispense = createRDS(order, qty);
                send(dispense, connection);
            }
        } else {
            RDS_O13 dispense = createRDS(order, quantity);
            send(dispense, connection);
        }
        if (returnAfterDispense) {
            quantity = quantity.negate();
            RDS_O13 dispense = createRDS(order, quantity);
            send(dispense, connection);
        }
    } catch (Throwable exception) {
        exception.printStackTrace();
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}