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 getShortTermLiabilityVar1() {
    try {/*from w  w  w . j  ava  2s.c  o m*/
        BigDecimal res = new BigDecimal(financialRatio.getShortTermLiability().doubleValue());
        res = res.divide(financialRatioCompOne.getShortTermLiability(), 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 getShortTermLiabilityVar2() {
    try {/*from w w  w  .j  a  v a  2  s  . co  m*/
        BigDecimal res = new BigDecimal(financialRatio.getShortTermLiability().doubleValue());
        res = res.divide(financialRatioCompTwo.getShortTermLiability(), 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 getObligationBondVar1() {
    try {/* ww  w.ja v  a  2 s.  c  o m*/
        BigDecimal res = new BigDecimal(financialRatio.getObligationBond().doubleValue());
        res = res.divide(financialRatioCompOne.getObligationBond(), 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 getObligationBondVar2() {
    try {//from   ww w . j  a  v a  2 s . c  o  m
        BigDecimal res = new BigDecimal(financialRatio.getObligationBond().doubleValue());
        res = res.divide(financialRatioCompTwo.getObligationBond(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#round(Object, Number, RoundingMode, Class)}.
 *///  w  w w .  j a v a  2s.c  om
@SuppressWarnings("unchecked")
@Test
public void testRoundObjectNumberRoundingModeClassOfT() {
    assertEquals("null", null, round(null, null, null, null));
    try {
        for (Class<?> type : NUMBERS) {
            Object expected = null;
            if (ObjectUtils.isAny(ClassUtils.primitiveToWrapper(type), Float.class, Double.class)) {
                expected = ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class).invoke(null,
                        "3.14");
            } else if (ClassUtils.isPrimitiveOrWrapper(type)) {
                expected = ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class).invoke(null,
                        "3");
            } else {
                expected = new BigDecimal("3.14");
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("PI: " + type.getSimpleName(), expected,
                    round(Math.PI, 2, RoundingMode.HALF_UP, (Class<? extends Number>) type));
            if (ObjectUtils.isAny(ClassUtils.primitiveToWrapper(type), Float.class, Double.class)) {
                expected = ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class).invoke(null,
                        "3.15");
            } else if (ClassUtils.isPrimitiveOrWrapper(type)) {
                expected = ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class).invoke(null,
                        "3");
            } else {
                expected = new BigDecimal("3.15");
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("PI: " + type.getSimpleName(), expected,
                    round(Math.PI, 2, RoundingMode.CEILING, (Class<? extends Number>) type));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}

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

public BigDecimal getTotalOtherResourcesVar1() {
    try {/* w w w . j av  a  2s  . c  om*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalOtherResources().doubleValue());
        res = res.divide(financialRatioCompOne.getTotalOtherResources(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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

From source file:org.kuali.ole.select.document.OleInvoiceDocument.java

@Override
public void prepareForSave(KualiDocumentEvent event) {
    // TODO Auto-generated method stub
    // first populate, then call super
    if (event instanceof AttributedContinuePurapEvent) {
        SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
    }//  ww w .  j a va2s . c  o  m
    if (this.getVendorPaymentTermsCode() != null && this.getVendorPaymentTermsCode().isEmpty()) {
        this.setVendorPaymentTermsCode(null);
    }
    super.prepareForSave(event);
    try {
        if (this.proformaIndicator && !this.immediatePaymentIndicator) {
            this.setImmediatePaymentIndicator(true);
        }
        LOG.debug("###########Inside OleInvoiceDocument " + "repareForSave###########");
        List<OleInvoiceItem> items = new ArrayList<OleInvoiceItem>();
        items = this.getItems();
        Iterator iterator = items.iterator();
        HashMap dataMap = new HashMap();
        String titleId;
        while (iterator.hasNext()) {
            LOG.debug("###########inside prepareForSave item loop###########");
            Object object = iterator.next();
            if (object instanceof OleInvoiceItem) {
                LOG.debug("###########inside prepareForSave ole payment request item###########");
                OleInvoiceItem singleItem = (OleInvoiceItem) object;
                if (StringUtils.isNotBlank(this.invoiceCurrencyType)) {
                    this.setInvoiceCurrencyTypeId(new Long(this.getInvoiceCurrencyType()));
                    String currencyType = SpringContext.getBean(OleInvoiceService.class)
                            .getCurrencyType(this.getInvoiceCurrencyType());
                    if (StringUtils.isNotBlank(currencyType)) {
                        if (!currencyType.equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) {
                            if (StringUtils.isNotBlank(this.getInvoiceCurrencyExchangeRate())) {
                                try {
                                    Double.parseDouble(this.getInvoiceCurrencyExchangeRate());
                                    singleItem.setItemExchangeRate(
                                            new KualiDecimal(this.getInvoiceCurrencyExchangeRate()));
                                    singleItem.setExchangeRate(this.getInvoiceCurrencyExchangeRate());
                                } catch (NumberFormatException nfe) {
                                    throw new RuntimeException("Invalid Exchange Rate", nfe);
                                }
                            } else {
                                BigDecimal exchangeRate = SpringContext.getBean(OleInvoiceService.class)
                                        .getExchangeRate(this.getInvoiceCurrencyType()).getExchangeRate();
                                this.setInvoiceCurrencyExchangeRate(exchangeRate.toString());
                                singleItem.setItemExchangeRate(new KualiDecimal(exchangeRate));
                                singleItem.setExchangeRate(exchangeRate.toString());
                            }
                            this.setVendorInvoiceAmount(this.getForeignVendorInvoiceAmount() != null
                                    ? new KualiDecimal(this.getForeignVendorInvoiceAmount().divide(
                                            new BigDecimal(singleItem.getExchangeRate()), 4,
                                            RoundingMode.HALF_UP))
                                    : null);
                        }
                    }
                }
                setItemDescription(singleItem);
                Map<String, String> copyCriteria = new HashMap<String, String>();
                if (singleItem.getPaidCopies().size() <= 0 && singleItem.getPoItemIdentifier() != null
                        && (this.getPurapDocumentIdentifier() != null
                                && singleItem.getItemIdentifier() != null)) {
                    copyCriteria.put("poItemId", singleItem.getPoItemIdentifier().toString());
                    List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService()
                            .findMatching(OleCopy.class, copyCriteria);
                    if (copies.size() > 0) {
                        List<OLEPaidCopy> paidCopies = new ArrayList<OLEPaidCopy>();
                        for (OleCopy copy : copies) {
                            OLEPaidCopy paidCopy = new OLEPaidCopy();
                            paidCopy.setCopyId(copy.getCopyId());
                            paidCopy.setInvoiceItemId(this.getPurapDocumentIdentifier());
                            paidCopy.setInvoiceIdentifier(singleItem.getItemIdentifier());
                            //copy.getOlePaidCopies().add(paidCopy);
                            paidCopies.add(paidCopy);
                        }
                        getBusinessObjectService().save(paidCopies);
                        singleItem.setPaidCopies(paidCopies);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Exception during prepareForSave() in OleInvoiceDocument", e);
        throw new RuntimeException(e);
    }
}

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

public BigDecimal getTotalOtherResourcesVar2() {
    try {/*from  w  w  w  .j  av  a2s.  c om*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalOtherResources().doubleValue());
        res = res.divide(financialRatioCompTwo.getTotalOtherResources(), 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 getCapitalVar1() {
    try {/* w  ww.jav a2  s  .  co m*/
        BigDecimal res = new BigDecimal(financialRatio.getCapital().doubleValue());
        res = res.divide(financialRatioCompOne.getCapital(), 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 getCapitalVar2() {
    try {/* w w  w. j a  v  a2s.  c o  m*/
        BigDecimal res = new BigDecimal(financialRatio.getCapital().doubleValue());
        res = res.divide(financialRatioCompTwo.getCapital(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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