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 getNetAssetVar1() {
    try {/* w  ww .j  av a  2 s.  c  o m*/
        BigDecimal res = new BigDecimal(financialRatio.getNetAsset().doubleValue());
        res = res.divide(financialRatioCompOne.getNetAsset(), 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 getNetAssetVar2() {
    try {/* w  ww  .  j  a va2 s .  co m*/
        BigDecimal res = new BigDecimal(financialRatio.getNetAsset().doubleValue());
        res = res.divide(financialRatioCompTwo.getNetAsset(), 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.AcctServer.java

/**
 * Is Document convertible to currency and Conversion Type
 * /*from w  w w  .  j  a v a2  s.  co  m*/
 * @param acctSchema
 *          accounting schema
 * @return true, if convertible to accounting currency
 */
public boolean isConvertible(AcctSchema acctSchema, ConnectionProvider conn) throws ServletException {
    // No Currency in document
    if (NO_CURRENCY.equals(C_Currency_ID)) {
        // if (log4j.isDebugEnabled())
        // log4j.debug("AcctServer - isConvertible (none) - " + DocumentNo);
        return true;
    }
    // Get All Currencies
    Vector<Object> set = new Vector<Object>();
    set.addElement(C_Currency_ID);
    for (int i = 0; p_lines != null && i < p_lines.length; i++) {
        String currency = p_lines[i].m_C_Currency_ID;
        if (currency != null && !currency.equals(""))
            set.addElement(currency);
    }

    // just one and the same
    if (set.size() == 1 && acctSchema.m_C_Currency_ID.equals(C_Currency_ID)) {
        // if (log4j.isDebugEnabled()) log4j.debug
        // ("AcctServer - isConvertible (same) Cur=" + C_Currency_ID + " - "
        // + DocumentNo);
        return true;
    }
    boolean convertible = true;
    for (int i = 0; i < set.size() && convertible == true; i++) {
        // if (log4j.isDebugEnabled()) log4j.debug
        // ("AcctServer - get currency");
        String currency = (String) set.elementAt(i);
        if (currency == null)
            currency = "";
        // if (log4j.isDebugEnabled()) log4j.debug
        // ("AcctServer - currency = " + currency);
        if (!currency.equals(acctSchema.m_C_Currency_ID)) {
            // if (log4j.isDebugEnabled()) log4j.debug
            // ("AcctServer - get converted amount (init)");
            String amt = "";
            OBQuery<ConversionRateDoc> conversionQuery = null;
            int conversionCount = 0;
            if (AD_Table_ID.equals(TABLEID_Invoice)) {
                conversionQuery = OBDal.getInstance().createQuery(ConversionRateDoc.class,
                        "invoice = '" + Record_ID + "' and currency='" + currency + "' and toCurrency='"
                                + acctSchema.m_C_Currency_ID + "'");
            } else if (AD_Table_ID.equals(TABLEID_Payment)) {
                conversionQuery = OBDal.getInstance().createQuery(ConversionRateDoc.class,
                        "payment = '" + Record_ID + "' and currency='" + currency + "' and toCurrency='"
                                + acctSchema.m_C_Currency_ID + "'");
            } else if (AD_Table_ID.equals(TABLEID_Transaction)) {
                conversionQuery = OBDal.getInstance().createQuery(ConversionRateDoc.class,
                        "financialAccountTransaction = '" + Record_ID + "' and currency='" + currency
                                + "' and toCurrency='" + acctSchema.m_C_Currency_ID + "'");
            }
            if (conversionQuery != null) {
                conversionCount = conversionQuery.count();
            }
            if (conversionCount > 0) {
                List<ConversionRateDoc> conversionRate = conversionQuery.list();
                OBCriteria<Currency> currencyCrit = OBDal.getInstance().createCriteria(Currency.class);
                currencyCrit.add(Restrictions.eq(Currency.PROPERTY_ID, acctSchema.m_C_Currency_ID));
                currencyCrit.setProjection(Projections.max(Currency.PROPERTY_STANDARDPRECISION));
                Long precision = 0L;
                if (currencyCrit.count() > 0) {
                    List<Currency> toCurrency = currencyCrit.list();
                    precision = toCurrency.get(0).getStandardPrecision();
                }
                BigDecimal convertedAmount = new BigDecimal("1").multiply(conversionRate.get(0).getRate());
                amt = convertedAmount.setScale(precision.intValue(), RoundingMode.HALF_UP).toString();
            }
            if (("").equals(amt) || amt == null)
                amt = getConvertedAmt("1", currency, acctSchema.m_C_Currency_ID, DateAcct,
                        acctSchema.m_CurrencyRateType, AD_Client_ID, AD_Org_ID, conn);
            // if (log4j.isDebugEnabled()) log4j.debug
            // ("get converted amount (end)");
            if (amt == null || ("").equals(amt)) {
                convertible = false;
                log4j.warn("AcctServer - isConvertible NOT from " + currency + " - " + DocumentNo);
            } else if (log4j.isDebugEnabled())
                log4j.debug("AcctServer - isConvertible from " + currency);
        }
    }
    // if (log4j.isDebugEnabled()) log4j.debug
    // ("AcctServer - isConvertible=" + convertible + ", AcctSchemaCur=" +
    // acctSchema.m_C_Currency_ID + " - " + DocumentNo);
    return convertible;
}

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

public BigDecimal getAmortizationsVar1() {
    try {/*from w ww.  j a  v a  2  s .co  m*/
        BigDecimal res = new BigDecimal(financialRatio.getAmortizations().doubleValue());
        res = res.divide(financialRatioCompOne.getAmortizations(), 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 getAmortizationsVar2() {
    try {/*from w  ww.  j  ava  2  s .  c  om*/
        BigDecimal res = new BigDecimal(financialRatio.getAmortizations().doubleValue());
        res = res.divide(financialRatioCompTwo.getAmortizations(), 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 getInfrastructuresVar1() {
    try {/*from   w w w .  ja  v a 2  s .  co m*/
        BigDecimal res = new BigDecimal(financialRatio.getInfrastructures().doubleValue());
        res = res.divide(financialRatioCompOne.getInfrastructures(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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

From source file:coffeshop.PaymentPage.java

private void cboSplitItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboSplitItemStateChanged
    int split = cboSplit.getSelectedIndex() + 1;
    txtPayAmt.setText((due.divide(new BigDecimal(split), 2, RoundingMode.HALF_UP)).toString());
}

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

public BigDecimal getInfrastructuresVar2() {
    try {/*from   w w w  . j a v a  2  s  .c o  m*/
        BigDecimal res = new BigDecimal(financialRatio.getInfrastructures().doubleValue());
        res = res.divide(financialRatioCompTwo.getInfrastructures(), 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 getTotalAssetVar1() {
    try {//from   w  ww.  j a v  a  2s .  c o  m
        BigDecimal res = new BigDecimal(financialRatio.getTotalAsset().doubleValue());
        res = res.divide(financialRatioCompOne.getTotalAsset(), 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 getTotalAssetVar2() {
    try {/* w  w w .ja va2 s  .  co  m*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalAsset().doubleValue());
        res = res.divide(financialRatioCompTwo.getTotalAsset(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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