Example usage for java.math RoundingMode HALF_UP

List of usage examples for java.math RoundingMode HALF_UP

Introduction

In this page you can find the example usage for java.math RoundingMode HALF_UP.

Prototype

RoundingMode HALF_UP

To view the source code for java.math RoundingMode HALF_UP.

Click Source Link

Document

Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.

Usage

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBaitVar1() {
    try {//from w  w w  . j av  a 2 s  .c o m
        BigDecimal res = new BigDecimal(financialRatio.getBait().doubleValue());
        res = res.divide(financialRatioCompOne.getBait(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBaitVar2() {
    try {/*from www.  ja  v a  2 s.co  m*/
        BigDecimal res = new BigDecimal(financialRatio.getBait().doubleValue());
        res = res.divide(financialRatioCompTwo.getBait(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getFinancialExpensesVar1() {
    try {// w  w  w .  ja va  2 s.co  m
        BigDecimal res = new BigDecimal(financialRatio.getFinancialExpenses().doubleValue());
        res = res.divide(financialRatioCompOne.getFinancialExpenses(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getFinancialExpensesVar2() {
    try {// ww w  .java 2  s .co  m
        BigDecimal res = new BigDecimal(financialRatio.getFinancialExpenses().doubleValue());
        res = res.divide(financialRatioCompTwo.getFinancialExpenses(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBatVar1() {
    try {/*  w ww  .j  ava 2 s .  co  m*/
        BigDecimal res = new BigDecimal(financialRatio.getBat().doubleValue());
        res = res.divide(financialRatioCompOne.getBat(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBatVar2() {
    try {// www .ja v a 2 s  .  co  m
        BigDecimal res = new BigDecimal(financialRatio.getBat().doubleValue());
        res = res.divide(financialRatioCompTwo.getBat(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getTaxesVar1() {
    try {/*  w  ww.  j a v  a2  s  . c  o m*/
        BigDecimal res = new BigDecimal(financialRatio.getTaxes().doubleValue());
        res = res.divide(financialRatioCompOne.getTaxes(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:org.openbravo.erpCommon.ad_forms.DocInvoice.java

private ArrayList<HashMap<String, String>> calculateAccDefPlan(Period startingPeriod, int periodNumber,
        BigDecimal amount, String strCurrencyId) {
    Period period = startingPeriod;
    Date date = period.getEndingDate();
    ArrayList<HashMap<String, String>> plan = new ArrayList<HashMap<String, String>>();
    int i = 1;//from   w  w  w  .j av  a  2  s  .  com
    BigDecimal total = BigDecimal.ZERO;
    int stdPrecision = 0;
    OBContext.setAdminMode(true);
    try {
        stdPrecision = OBDal.getInstance().get(Currency.class, this.C_Currency_ID).getStandardPrecision()
                .intValue();
    } finally {
        OBContext.restorePreviousMode();
    }
    BigDecimal periodAmount = amount
            .divide(new BigDecimal(periodNumber), new MathContext(32, RoundingMode.HALF_UP))
            .setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);

    while (i <= periodNumber) {
        if (!OBDateUtils.formatDate(date).equals(DateAcct)) {
            HashMap<String, String> hm = new HashMap<String, String>();
            hm.put("date", OBDateUtils.formatDate(date));
            hm.put("amount", i == periodNumber ? amount.subtract(total).toString() : periodAmount.toString());
            plan.add(hm);
        }
        try {
            AcctServerData[] data = AcctServerData.periodOpen(connectionProvider, AD_Client_ID, DocumentType,
                    AD_Org_ID, OBDateUtils.formatDate(period.getEndingDate()));
            if ("".equals(data[0].period)) {
                setStatus(STATUS_PeriodClosed);
                throw new OBException("@PeriodNotAvailable@");
            }
        } catch (ServletException e) {
            log4j.warn("DocInvoice - Error checking period open.", e);
            e.printStackTrace();
        }
        if (i < periodNumber) {
            period = AccDefUtility.getNextPeriod(period);
            date = period.getEndingDate();
        }
        total = total.add(periodAmount);
        i++;
    }
    return plan;
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getTaxesVar2() {
    try {//from   ww  w. j  av a2s. com
        BigDecimal res = new BigDecimal(financialRatio.getTaxes().doubleValue());
        res = res.divide(financialRatioCompTwo.getTaxes(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getBdtVar1() {
    try {/*from w  w  w  .j  a va  2s  . co  m*/
        BigDecimal res = new BigDecimal(financialRatio.getBdt().doubleValue());
        res = res.divide(financialRatioCompOne.getBdt(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}