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 getReservesVar1() {
    try {/*from   ww  w  . j  av  a 2s.c om*/
        BigDecimal res = new BigDecimal(financialRatio.getReserves().doubleValue());
        res = res.divide(financialRatioCompOne.getReserves(), 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 getReservesVar2() {
    try {/*  w  w w. j a  va  2s .  c o  m*/
        BigDecimal res = new BigDecimal(financialRatio.getReserves().doubleValue());
        res = res.divide(financialRatioCompTwo.getReserves(), 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 getTotalOurResourcesVar1() {
    try {// w  w  w .  j  a  v  a  2s  .c om
        BigDecimal res = new BigDecimal(financialRatio.getTotalOurResources().doubleValue());
        res = res.divide(financialRatioCompOne.getReserves(), 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 getTotalOurResourcesVar2() {
    try {/*from www  .  ja  v a 2s. co m*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalOurResources().doubleValue());
        res = res.divide(financialRatioCompTwo.getReserves(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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

From source file:org.egov.works.web.actions.contractorBill.ContractorBillAction.java

private void validateExpenditureForDepositCode(final String actionName) {
    if (workOrderEstimate.getEstimate() != null && workOrderEstimate.getEstimate().getDepositCode() != null)
        if (StringUtils.isNotBlank(actionName)
                && (actionName.equalsIgnoreCase(WorksConstants.ACTION_SUBMIT_FOR_APPROVAL)
                        || actionName.equalsIgnoreCase(WorksConstants.ACTION_APPROVAL)
                        || actionName.equalsIgnoreCase(WorksConstants.ACTION_APPROVE))) {
            final FinancialDetail financialDetails = workOrderEstimate.getEstimate().getFinancialDetails()
                    .get(0);/*from  w w  w .j av a 2  s  .  c  om*/
            if (financialDetails != null) {
                BigDecimal expenditureAmount = BigDecimal.ZERO;
                BigDecimal totalExpAmount = BigDecimal.ZERO;
                final Fund fund = financialDetails.getFund();
                final CChartOfAccounts coa = financialDetails.getCoa();
                final Accountdetailtype accountdetailtype = (Accountdetailtype) persistenceService
                        .find("from Accountdetailtype where name=?", "DEPOSITCODE");
                if (fund != null && fund.getId() != null && coa != null && coa.getId() != null
                        && workOrderEstimate.getEstimate().getDepositCode().getId() != null) {
                    final BigDecimal totalAmountDeposited = egovCommon.getDepositAmountForDepositCode(
                            new Date(), coa.getGlcode(), fund.getCode(), accountdetailtype.getId(),
                            workOrderEstimate.getEstimate().getDepositCode().getId().intValue());
                    final List<Integer> projectCodeIdsList = contractorBillService
                            .getProjCodeIdsListForDepositCode(fund.getId(), coa.getId(),
                                    workOrderEstimate.getEstimate().getDepositCode().getId());
                    if (!projectCodeIdsList.isEmpty())
                        expenditureAmount = contractorBillService.getTotalExpenditure(projectCodeIdsList,
                                WorksConstants.PROJECTCODE);
                    // In case id is null, include the current bill amount
                    if (id == null)
                        totalExpAmount = expenditureAmount.add(contractorBillRegister.getBillamount());
                    else
                        totalExpAmount = expenditureAmount;
                    final BigDecimal finalExpenditureAmount = totalExpAmount.setScale(2, RoundingMode.HALF_UP);
                    final BigDecimal totalDepositedAmount = totalAmountDeposited.setScale(2,
                            RoundingMode.HALF_UP);

                    if (totalDepositedAmount.compareTo(finalExpenditureAmount) == -1) {
                        populateBudgetHeadForDepositWorksEstimate();
                        throw new ValidationException(Arrays.asList(new ValidationError(
                                "contractoBill.dwEstimate.expenditure.amount.insufficient",
                                getText("contractoBill.dwEstimate.expenditure.amount.insufficient",
                                        new String[] {
                                                workOrderEstimate.getEstimate().getDepositCode().getCode(),
                                                NumberUtil.formatNumber(finalExpenditureAmount),
                                                NumberUtil.formatNumber(totalDepositedAmount) }))));
                    }
                }
            }
        }
}

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

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

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

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.por.PORFileReader.java

private double base30Tobase10Conversion(String base30String) {

    // new base(radix) number
    int oldBase = 30;
    //dbgLog.fine("base30String="+base30String);

    // trim white-spaces from the both ends
    String base30StringClean = StringUtils.trim(base30String);
    //dbgLog.fine("base30StringClean="+base30StringClean);

    // check the negative/positive sign
    boolean isNegativeNumber = false;
    boolean hasPositiveSign = false;
    if (base30StringClean.startsWith("-")) {
        isNegativeNumber = true;//  w  w  w .ja v  a2  s.co m
    }

    if (base30StringClean.startsWith("+")) {
        hasPositiveSign = true;
    }

    // remove the sign if exits
    String base30StringNoSign = null;

    if ((isNegativeNumber) || (hasPositiveSign)) {
        base30StringNoSign = base30StringClean.substring(1);
    } else {
        base30StringNoSign = new String(base30StringClean);
    }

    // check the scientific notation
    // if so, divide it into the significand and exponent
    String significand = null;
    long exponent = 0;

    int plusIndex = base30StringNoSign.indexOf("+");
    int minusIndex = base30StringNoSign.indexOf("-");

    if (plusIndex > 0) {
        significand = base30StringNoSign.substring(0, plusIndex);
        exponent = Long.valueOf(base30StringNoSign.substring(plusIndex + 1), oldBase);

    } else if (minusIndex > 0) {
        significand = base30StringNoSign.substring(0, minusIndex);
        exponent = -1 * Long.valueOf(base30StringNoSign.substring(minusIndex + 1), oldBase);

    } else {
        significand = new String(base30StringNoSign);
    }

    // "move" decimal point; for each shift right, subtract one from exponent; end result is a string with no decimal
    int decimalIndex = significand.indexOf(".");
    if (decimalIndex != -1) {
        exponent -= (significand.length() - (decimalIndex + 1));
        significand = significand.substring(0, decimalIndex) + significand.substring(decimalIndex + 1);
    }

    MathContext mc = new MathContext(15, RoundingMode.HALF_UP);
    long base10Significand = Long.parseLong(significand, oldBase);
    BigDecimal base10value = new BigDecimal(String.valueOf(base10Significand), mc);
    BigDecimal exponentialComponent = new BigDecimal("1", mc);

    for (int g = 0; g < Math.abs(exponent); g++) {
        exponentialComponent = exponentialComponent.multiply(new BigDecimal("30", mc));
    }

    if (exponent >= 0) {
        base10value = base10value.multiply(exponentialComponent, mc);
    } else {
        base10value = base10value.divide(exponentialComponent, mc);
    }

    // negative sign if applicable
    if (isNegativeNumber) {
        base10value = base10value.multiply(new BigDecimal("-1", mc));
    }

    return base10value.doubleValue();
}

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

public BigDecimal getTotalLiabilityVar2() {
    try {/*from w w  w.  j a v a2s.  co m*/
        BigDecimal res = new BigDecimal(financialRatio.getTotalLiability().doubleValue());
        res = res.divide(financialRatioCompTwo.getTotalLiability(), 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 getIncomesVar1() {
    try {/*from   w  w w  .ja v a2 s . com*/
        BigDecimal res = new BigDecimal(financialRatio.getIncomes().doubleValue());
        res = res.divide(financialRatioCompOne.getIncomes(), 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 getIncomesVar2() {
    try {//from   ww w.  j  av  a2s . c o  m
        BigDecimal res = new BigDecimal(financialRatio.getIncomes().doubleValue());
        res = res.divide(financialRatioCompTwo.getIncomes(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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