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:org.kuali.coeus.s2sgen.impl.budget.S2SBudgetCalculatorServiceImpl.java

/**
 * // w  w w . ja  v  a 2s  .  c  o  m
 * This method populates the details for {@link OtherPersonnelDto} business object for the given
 * {@link ProposalDevelopmentDocumentContract}
 * 
 * @param budgetPeriod given budget period.
 * @param pdDoc Proposal Development Document.
 * @param category budget category
 * @param personnelType proposal personnel type.
 * @param role role of the proposal person.
 * @return OtherPersonnelInfo information about the other personnel.
 */
protected OtherPersonnelDto getOtherPersonnelDetails(BudgetPeriodContract budgetPeriod,
        ProposalDevelopmentDocumentContract pdDoc, String category, String personnelType, String role) {
    OtherPersonnelDto otherPersonnelInfo = new OtherPersonnelDto();

    int count = 0;
    ScaleTwoDecimal salaryRequested = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal salaryCostSharing = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal lineItemCost = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal lineItemCostSharingAmount = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal mrLaCost = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal mrLaCostSharingAmount = ScaleTwoDecimal.ZERO;

    ScaleTwoDecimal fringeCost = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal fringeCostSharingAmount = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal mrLaFringeCost = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal mrLaFringeCostSharingAmount = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal budgetLineItemFringeCost = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal budgetLineItemFringeCostSharingAmount = ScaleTwoDecimal.ZERO;

    ScaleTwoDecimal bdSalary = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal bdFringe = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal bdFunds = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal bdSalaryCostSharing = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal bdFringeCostSharing = ScaleTwoDecimal.ZERO;
    ScaleTwoDecimal bdNonFunds = ScaleTwoDecimal.ZERO;

    BigDecimal academicMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
    BigDecimal summerMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
    BigDecimal calendarMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
    BigDecimal cycleMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);

    BigDecimal numberOfMonths = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
    String rateTypeSupportStaffSalaries = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.S2SBUDGET_RATE_TYPE_SUPPORT_STAFF_SALARIES);
    String rateClassCodeEmployeeBenefits = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.S2SBUDGET_RATE_CLASS_CODE_EMPLOYEE_BENEFITS);
    String rateClassCodeVacation = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.S2SBUDGET_RATE_CLASS_CODE_VACATION);
    String rateTypeAdministrativeSalaries = s2SConfigurationService
            .getValueAsString(ConfigurationConstants.S2SBUDGET_RATE_TYPE_ADMINISTRATIVE_SALARIES);
    Map<String, String> personJobCodes = new HashMap<String, String>();
    boolean personExistsAsProposalPerson = false;

    // Calculate the salary and fringe for category
    // LASALARIES
    if (category.equalsIgnoreCase(LASALARIES)) {
        for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
            // Caluclate LA for rate class type Y
            for (BudgetLineItemCalculatedAmountContract lineItemCalculatedAmount : lineItem
                    .getBudgetLineItemCalculatedAmounts()) {
                if (lineItemCalculatedAmount.getRateClass().getRateClassType().getCode()
                        .equals(s2SConfigurationService.getValueAsString(
                                ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_LAB_ALLOCATION_SALARIES))) {
                    mrLaCost = mrLaCost.add(lineItemCalculatedAmount.getCalculatedCost());
                    if (lineItem.getSubmitCostSharingFlag()) {
                        mrLaCostSharingAmount = mrLaCostSharingAmount
                                .add(lineItemCalculatedAmount.getCalculatedCostSharing());
                    }
                }

                // Calculate the fringe
                if ((lineItemCalculatedAmount.getRateClass().getRateClassType().getCode()
                        .equals(s2SConfigurationService.getValueAsString(
                                ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_EMPLOYEE_BENEFITS))
                        && lineItemCalculatedAmount.getRateTypeCode().equals(rateTypeSupportStaffSalaries))
                        || (lineItemCalculatedAmount.getRateClass().getRateClassType().getCode()
                                .equals(s2SConfigurationService.getValueAsString(
                                        ConfigurationConstants.S2SBUDGET_RATE_CLASS_TYPE_VACATION))
                                && lineItemCalculatedAmount.getRateTypeCode()
                                        .equals(rateTypeAdministrativeSalaries))) {
                    mrLaFringeCost = mrLaFringeCost.add(lineItemCalculatedAmount.getCalculatedCost());
                    if (lineItem.getSubmitCostSharingFlag()) {
                        mrLaFringeCostSharingAmount = mrLaFringeCostSharingAmount
                                .add(lineItemCalculatedAmount.getCalculatedCostSharing());
                    }
                }
            }
        }
    } else {
        for (BudgetLineItemContract lineItem : budgetPeriod.getBudgetLineItems()) {
            List<? extends BudgetCategoryMappingContract> budgetCategoryList = budgetCategoryMapService
                    .findCatMappingByTargetAndMappingName(category, SPONSOR);

            for (BudgetCategoryMappingContract categoryMapping : budgetCategoryList) {
                if (categoryMapping.getBudgetCategoryCode().equals(lineItem.getBudgetCategory().getCode())) {
                    List<? extends BudgetPersonnelDetailsContract> lineItemPersonDetails = lineItem
                            .getBudgetPersonnelDetailsList();
                    boolean personExist = !lineItemPersonDetails.isEmpty();
                    if (personExist) {
                        for (BudgetPersonnelDetailsContract personDetails : lineItemPersonDetails) {
                            if (categoryMapping.getBudgetCategoryCode()
                                    .equals(lineItem.getBudgetCategory().getCode())) {
                                String budgetPersonId = personDetails.getPersonId();
                                personExistsAsProposalPerson = false;
                                // get sum of salary of other personnel, but
                                // exclude the key persons and investigators
                                for (ProposalPersonContract proposalPerson : pdDoc.getDevelopmentProposal()
                                        .getProposalPersons()) {
                                    if (budgetPersonId.equals(proposalPerson.getPersonId())
                                            || (proposalPerson.getRolodexId() != null && budgetPersonId
                                                    .equals(proposalPerson.getRolodexId().toString()))) {
                                        personExistsAsProposalPerson = true;
                                        break;
                                    }
                                }
                                if (!personExistsAsProposalPerson) {
                                    salaryRequested = salaryRequested.add(personDetails.getSalaryRequested());
                                    if (lineItem.getSubmitCostSharingFlag()) {
                                        salaryCostSharing = salaryCostSharing
                                                .add(personDetails.getCostSharingAmount());
                                    }
                                    numberOfMonths = s2SDateTimeService
                                            .getNumberOfMonths(personDetails.getStartDate(),
                                                    personDetails.getEndDate())
                                            .bigDecimalValue();
                                    if (personDetails.getPeriodTypeCode()
                                            .equals(s2SConfigurationService.getValueAsString(
                                                    ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_ACADEMIC_MONTHS))) {
                                        if (lineItem.getSubmitCostSharingFlag()) {
                                            academicMonths = academicMonths
                                                    .add(personDetails.getPercentEffort().bigDecimalValue()
                                                            .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                        } else {
                                            academicMonths = academicMonths
                                                    .add(personDetails.getPercentCharged().bigDecimalValue()
                                                            .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                        }
                                    } else if (personDetails.getPeriodTypeCode()
                                            .equals(s2SConfigurationService.getValueAsString(
                                                    ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_SUMMER_MONTHS))) {
                                        if (lineItem.getSubmitCostSharingFlag()) {
                                            summerMonths = summerMonths
                                                    .add(personDetails.getPercentEffort().bigDecimalValue()
                                                            .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                        } else {
                                            summerMonths = summerMonths
                                                    .add(personDetails.getPercentCharged().bigDecimalValue()
                                                            .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                        }

                                    } else if (personDetails.getPeriodTypeCode()
                                            .equals(s2SConfigurationService.getValueAsString(
                                                    ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_CALENDAR_MONTHS))) {
                                        if (lineItem.getSubmitCostSharingFlag()) {
                                            calendarMonths = calendarMonths
                                                    .add(personDetails.getPercentEffort().bigDecimalValue()
                                                            .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                        } else {
                                            calendarMonths = calendarMonths
                                                    .add(personDetails.getPercentCharged().bigDecimalValue()
                                                            .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                        }
                                    } else if (personDetails.getPeriodTypeCode()
                                            .equals(s2SConfigurationService.getValueAsString(
                                                    ConfigurationConstants.S2SBUDGET_PERIOD_TYPE_CYCLE_MONTHS))) {
                                        cycleMonths = cycleMonths
                                                .add(personDetails.getPercentEffort().bigDecimalValue()
                                                        .multiply(numberOfMonths).multiply(POINT_ZERO_ONE));
                                    }
                                    // Get total count of unique
                                    // personId+jobCode combination for those
                                    // persons who are part of
                                    // BudgetPersonnelDetails but are not
                                    // proposal persons
                                    personJobCodes.put(personDetails.getPersonId() + personDetails.getJobCode(),
                                            "");
                                    // Calcculate the fringe cost
                                    for (BudgetPersonnelCalculatedAmountContract personCalculatedAmount : personDetails
                                            .getBudgetPersonnelCalculatedAmounts()) {
                                        if ((personCalculatedAmount.getRateClass().getCode()
                                                .equals(rateClassCodeEmployeeBenefits)
                                                && !personCalculatedAmount.getRateTypeCode()
                                                        .equals(rateTypeSupportStaffSalaries))
                                                || (personCalculatedAmount.getRateClass().getCode()
                                                        .equals(rateClassCodeVacation)
                                                        && !personCalculatedAmount.getRateTypeCode()
                                                                .equals(rateTypeAdministrativeSalaries))) {
                                            fringeCost = fringeCost
                                                    .add(personCalculatedAmount.getCalculatedCost());
                                            if (lineItem.getSubmitCostSharingFlag()) {
                                                fringeCostSharingAmount = fringeCostSharingAmount
                                                        .add(personCalculatedAmount.getCalculatedCostSharing());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        // personExist is false. No person found for the line
                        // item.
                        // get costs for this budget category that do not have
                        // persons attached to the cost element
                        lineItemCost = lineItemCost.add(lineItem.getLineItemCost());
                        if (lineItem.getSubmitCostSharingFlag()) {
                            lineItemCostSharingAmount = lineItemCostSharingAmount
                                    .add(lineItem.getCostSharingAmount());
                        }
                        count = lineItem.getQuantity();
                        for (BudgetLineItemCalculatedAmountContract lineItemCalculatedAmount : lineItem
                                .getBudgetLineItemCalculatedAmounts()) {

                            // Calculate fringe cost
                            if (lineItemCalculatedAmount.getRateClass().getRateClassType().getCode()
                                    .equalsIgnoreCase("E")) {
                                fringeCost = fringeCost.add(lineItemCalculatedAmount.getCalculatedCost());
                            }
                            if ((lineItemCalculatedAmount.getRateClass().getCode()
                                    .equals(rateClassCodeEmployeeBenefits)
                                    && !lineItemCalculatedAmount.getRateTypeCode()
                                            .equals(rateTypeSupportStaffSalaries))
                                    || (lineItemCalculatedAmount.getRateClass().getCode()
                                            .equals(rateClassCodeVacation)
                                            && !lineItemCalculatedAmount.getRateTypeCode()
                                                    .equals(rateTypeAdministrativeSalaries))) {
                                if (lineItem.getSubmitCostSharingFlag()) {
                                    fringeCostSharingAmount = fringeCostSharingAmount
                                            .add(lineItemCalculatedAmount.getCalculatedCostSharing());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Set the salary amounts
    bdSalary = bdSalary.add(salaryRequested).add(lineItemCost).add(mrLaCost);
    bdSalaryCostSharing = bdSalaryCostSharing.add(salaryCostSharing).add(lineItemCostSharingAmount)
            .add(mrLaCostSharingAmount);

    // Set the fringe costs
    bdFringe = bdFringe.add(fringeCost).add(budgetLineItemFringeCost).add(mrLaFringeCost);
    bdFringeCostSharing = bdFringeCostSharing.add(fringeCostSharingAmount)
            .add(budgetLineItemFringeCostSharingAmount).add(mrLaFringeCostSharingAmount);

    bdNonFunds = bdSalaryCostSharing.add(bdFringeCostSharing);
    bdFunds = bdSalary.add(bdFringe);

    count = personJobCodes.isEmpty() ? count : personJobCodes.size();
    otherPersonnelInfo.setNumberPersonnel(count);
    otherPersonnelInfo.setPersonnelType(personnelType);
    otherPersonnelInfo.setRole(role);

    CompensationDto compensationInfo = new CompensationDto();
    // not sure that we need base salary
    compensationInfo.setBaseSalary(ScaleTwoDecimal.ZERO);
    compensationInfo.setFringe(bdFringe);
    compensationInfo.setFundsRequested(bdFunds);
    compensationInfo.setRequestedSalary(bdSalary);
    compensationInfo.setSummerMonths(new ScaleTwoDecimal(summerMonths));
    compensationInfo.setAcademicMonths(new ScaleTwoDecimal(academicMonths));
    compensationInfo.setCalendarMonths(new ScaleTwoDecimal(calendarMonths));

    // start add costSaring for fedNonFedBudget report
    compensationInfo.setFringeCostSharing(bdFringeCostSharing);
    compensationInfo.setNonFundsRequested(bdNonFunds);
    compensationInfo.setCostSharingAmount(bdSalaryCostSharing);
    // end add costSaring for fedNonFedBudget report

    otherPersonnelInfo.setCompensation(compensationInfo);
    return otherPersonnelInfo;
}

From source file:org.kuali.ole.select.service.impl.OleReqPOCreateDocumentServiceImpl.java

private void setForeignCurrencyDetails(OleRequisitionItem item, OleRequisitionDocument requisitionDocument) {
    if (requisitionDocument.getVendorDetail().getCurrencyType() != null) {
        if (requisitionDocument.getVendorDetail().getCurrencyType().getCurrencyType()
                .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) {
            currencyTypeIndicator = true;
        } else {//from   www .j ava  2 s .c om
            currencyTypeIndicator = false;
        }
    }
    if (!currencyTypeIndicator) {
        item.setItemForeignListPrice(item.getItemListPrice());
        item.setItemForeignDiscountType(item.getItemDiscountType());
        item.setItemForeignDiscount(item.getItemDiscount());
        item.setItemListPrice(new KualiDecimal(0.00));
        getOlePurapService().calculateForeignCurrency(item);
        Long currencyTypeId = requisitionDocument.getVendorDetail().getCurrencyType().getCurrencyTypeId();
        Map documentNumberMap = new HashMap();
        documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId);
        BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
        List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(
                OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
        Iterator iterator = exchangeRateList.iterator();
        if (iterator.hasNext()) {
            OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
            item.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
        }
        if (item.getItemExchangeRate() != null && item.getItemForeignUnitCost() != null) {
            item.setItemUnitCostUSD(new KualiDecimal(item.getItemForeignUnitCost().bigDecimalValue()
                    .divide(item.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP)));
            item.setItemUnitPrice(item.getItemUnitCostUSD().bigDecimalValue());
            item.setItemListPrice(item.getItemUnitCostUSD());
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.GanttDiagramTagLib.java

private BigDecimal convertToEm(int value) {
    return BigDecimal.valueOf(value).divide(PX_TO_EM_CONVERSION_DIVISOR, 2, RoundingMode.HALF_UP);
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398FellowshipSupplementalV1_1Generator.java

private ScaleTwoDecimal getNumberOfMonths(Date dateStart, Date dateEnd) {
    BigDecimal monthCount = ScaleTwoDecimal.ZERO.bigDecimalValue();
    int fullMonthCount = 0;

    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    startDate.setTime(dateStart);//w  w w .jav a 2  s . co  m
    endDate.setTime(dateEnd);

    startDate.clear(Calendar.HOUR);
    startDate.clear(Calendar.MINUTE);
    startDate.clear(Calendar.SECOND);
    startDate.clear(Calendar.MILLISECOND);

    endDate.clear(Calendar.HOUR);
    endDate.clear(Calendar.MINUTE);
    endDate.clear(Calendar.SECOND);
    endDate.clear(Calendar.MILLISECOND);

    if (startDate.after(endDate)) {
        return ScaleTwoDecimal.ZERO;
    }
    int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE);
    startMonthDays++;
    int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE);
    BigDecimal startMonthFraction = new ScaleTwoDecimal(startMonthDays).bigDecimalValue()
            .divide(new ScaleTwoDecimal(startMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP);

    int endMonthDays = endDate.get(Calendar.DATE);
    int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE);

    BigDecimal endMonthFraction = new ScaleTwoDecimal(endMonthDays).bigDecimalValue()
            .divide(new ScaleTwoDecimal(endMonthMaxDays).bigDecimalValue(), RoundingMode.HALF_UP);

    startDate.set(Calendar.DATE, 1);
    endDate.set(Calendar.DATE, 1);

    while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) {
        startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1);
        fullMonthCount++;
    }
    fullMonthCount = fullMonthCount - 1;
    monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount).bigDecimalValue()).add(startMonthFraction)
            .add(endMonthFraction);
    return new ScaleTwoDecimal(monthCount);
}

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

public BigDecimal getBanksAccountsVar1() {
    try {//ww  w .j  av a2  s.c  o m
        BigDecimal res = new BigDecimal(financialRatio.getBanksAccounts().doubleValue());
        res = res.divide(financialRatioCompOne.getBanksAccounts(), 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 getBanksAccountsVar2() {
    try {/*  ww  w  .j ava  2  s .  c o  m*/
        BigDecimal res = new BigDecimal(financialRatio.getBanksAccounts().doubleValue());
        res = res.divide(financialRatioCompTwo.getBanksAccounts(), 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 getCustomersVar1() {
    try {//from w  ww .  j a v  a2 s  .  c o  m
        BigDecimal res = new BigDecimal(financialRatio.getCustomers().doubleValue());
        res = res.divide(financialRatioCompOne.getCustomers(), 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 getCustomersVar2() {
    try {/*from w  w w. ja v  a 2s.  c o m*/
        BigDecimal res = new BigDecimal(financialRatio.getCustomers().doubleValue());
        res = res.divide(financialRatioCompTwo.getCustomers(), 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 getStocksVar1() {
    try {//from  w  ww  . j  a  v a  2s . co  m
        BigDecimal res = new BigDecimal(financialRatio.getStocks().doubleValue());
        res = res.divide(financialRatioCompOne.getStocks(), 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 getStocksVar2() {
    try {/*w w w .  j  av a2s  . c  om*/
        BigDecimal res = new BigDecimal(financialRatio.getStocks().doubleValue());
        res = res.divide(financialRatioCompTwo.getStocks(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

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