List of usage examples for java.math RoundingMode HALF_UP
RoundingMode HALF_UP
To view the source code for java.math RoundingMode HALF_UP.
Click Source Link
From source file:org.projectforge.business.fibu.kost.BusinessAssessmentRow.java
void recalculate() { if (accountRecordsExist == true) { // Nothing to do. return;/*from www .j a va 2 s. c o m*/ } final Script groovyScript = config.getValueScript(); if (groovyScript == null) { // Nothing to do. return; } amount = BigDecimal.ZERO; final Map<String, Object> vars = new HashMap<String, Object>(); BusinessAssessment.putBusinessAssessmentRows(vars, businessAssessment); final GroovyResult result = new GroovyExecutor().execute(groovyScript, vars); final Object rval = result.getResult(); if (rval instanceof BigDecimal) { amount = (BigDecimal) rval; } else if (rval instanceof Number) { amount = new BigDecimal(String.valueOf(rval)).setScale(getScale(), RoundingMode.HALF_UP); } }
From source file:alfio.model.PriceContainerTest.java
@Test public void getFinalPriceInputVatNotIncluded() throws Exception { generateTestStream(PriceContainer.VatStatus.NOT_INCLUDED).forEach(p -> { PriceContainer priceContainer = p.getRight(); BigDecimal finalPrice = priceContainer.getFinalPrice(); Integer price = p.getLeft(); BigDecimal netPrice = MonetaryUtil.centsToUnit(price); BigDecimal vatAmount = finalPrice.subtract(netPrice); int result = MonetaryUtil.unitToCents(vatAmount .subtract(MonetaryUtil.calcVat(netPrice, priceContainer.getVatPercentageOrZero())).abs()); if (result >= 2) { BigDecimal calcVatPerc = vatAmount.divide(finalPrice, 5, RoundingMode.HALF_UP) .multiply(new BigDecimal("100.00")).setScale(2, RoundingMode.HALF_UP); fail(String.format("Expected percentage: %s, got %s, vat %s v. %s", calcVatPerc, priceContainer.getOptionalVatPercentage(), vatAmount, MonetaryUtil.calcVat(netPrice, priceContainer.getVatPercentageOrZero()))); }//from w w w .j a va 2 s . co m }); }
From source file:org.kuali.kra.budget.calculator.LineItemCalculator.java
@Override public void populateApplicableCosts(Boundary boundary) { int totalNumOfDays = dateTimeService.dateDiff(this.bli.getStartDate(), this.bli.getEndDate(), true); int boundaryNumOfDays = boundary.getNumberOfDays(); List<BudgetPersonnelDetails> personnelDetailsList = bli.getBudgetPersonnelDetailsList(); BudgetDecimal salaryRequested = BudgetDecimal.ZERO; BudgetDecimal costSharingRequested = BudgetDecimal.ZERO; if (!personnelDetailsList.isEmpty()) { for (BudgetPersonnelDetails budgetPersonnelDetails : personnelDetailsList) { budgetCalculationService.calculateBudgetLineItem(budget, budgetPersonnelDetails); salaryRequested = salaryRequested.add(budgetPersonnelDetails.getSalaryRequested()); costSharingRequested = costSharingRequested.add(budgetPersonnelDetails.getCostSharingAmount()); }//from ww w . java 2 s . c om bli.setLineItemCost(salaryRequested); bli.setCostSharingAmount(costSharingRequested); } else { BudgetDecimal lineItemCost = bli.getLineItemCost(); BudgetDecimal lineItemCostSharing = bli.getCostSharingAmount(); boundary.setApplicableCost(lineItemCost == null ? BudgetDecimal.ZERO : new BudgetDecimal( lineItemCost.bigDecimalValue().multiply(((new BigDecimal(boundaryNumOfDays)))) .divide(new BigDecimal(totalNumOfDays), 2, RoundingMode.HALF_UP))); boundary.setApplicableCostSharing( lineItemCostSharing == null ? BudgetDecimal.ZERO : new BudgetDecimal(lineItemCostSharing.bigDecimalValue() .multiply(((new BigDecimal(boundaryNumOfDays)))) .divide(new BigDecimal(totalNumOfDays), 2, RoundingMode.HALF_UP))); } }
From source file:com.epam.ta.reportportal.core.project.impl.GetProjectStatisticHandler.java
@Override public ProjectInfoResource getProjectInfo(String projectId, String dataInterval) { Project project = projectRepository.findOne(projectId); expect(project, notNull()).verify(PROJECT_NOT_FOUND, projectId); InfoInterval interval = InfoInterval.findByName(dataInterval); expect(interval, notNull()).verify(BAD_REQUEST_ERROR, dataInterval); Date date = getStartIntervalDate(interval); ProjectInfoResource projectInfoResource = projectInfoResourceAssembler.toResource(project); projectInfoResource// ww w.j a va 2s. c o m .setLaunchesQuantity(launchRepository.findLaunchesQuantity(project.getId(), DEFAULT.name(), date)); // Extended information Map<String, Integer> map = launchRepository.findGroupedLaunchesByOwner(projectId, DEFAULT.name(), date); List<LaunchesPerUser> launches = this.getLaunchesInfo(map); projectInfoResource.setLaunchesPerUser(launches); projectInfoResource.setUsersQuantity(project.getUsers().size()); List<Launch> allLaunches = getLaunchesForProjectInformation(projectId, interval); List<String> tickets = itemRepository.getUniqueTicketsCount(allLaunches); projectInfoResource.setUniqueTickets(tickets.size()); if ((null != allLaunches) && !allLaunches.isEmpty()) { formatter.setRoundingMode(RoundingMode.HALF_UP); double value = allLaunches.size() / (interval.getCount() * WEEKS_IN_MONTH); projectInfoResource.setLaunchesPerWeek(formatter.format(value)); } else { projectInfoResource.setLaunchesPerWeek(formatter.format(0)); } return projectInfoResource; }
From source file:org.openconcerto.erp.graph.GraphFamilleArticlePanel.java
protected BigDecimal updateDataset(List<String> labels, List<Number> values) { final SQLTable tableVFElement = Configuration.getInstance().getDirectory() .getElement("SAISIE_VENTE_FACTURE_ELEMENT").getTable(); final SQLTable tableVF = tableVFElement.getTable("SAISIE_VENTE_FACTURE"); final SQLTable tableArticle = tableVFElement.getTable("ARTICLE"); final SQLSelect sel = new SQLSelect(); final String field = "ID_FAMILLE_ARTICLE"; sel.addSelect(tableArticle.getField(field)); sel.addSelect(tableVFElement.getField("T_PA_HT"), "SUM"); sel.addSelect(tableVFElement.getField("T_PV_HT"), "SUM"); sel.addSelect(tableVFElement.getField("QTE"), "SUM"); Where w = new Where(tableVF.getKey(), "=", tableVFElement.getField("ID_SAISIE_VENTE_FACTURE")); w = w.and(new Where(tableVF.getField("DATE"), this.d1, this.d2)); w = w.and(new Where(tableArticle.getKey(), "=", tableVFElement.getField("ID_ARTICLE"))); sel.setWhere(w);//from www. java 2s.c o m final List<Object[]> rowsArticle = (List<Object[]>) Configuration.getInstance().getBase().getDataSource() .execute(sel.asString() + " GROUP BY \"ARTICLE\".\"" + field + "\"", new ArrayListHandler()); Collections.sort(rowsArticle, new Comparator<Object[]>() { @Override public int compare(Object[] o1, Object[] o2) { BigDecimal pa1 = (BigDecimal) o1[1]; BigDecimal pv1 = (BigDecimal) o1[2]; BigDecimal qte1 = new BigDecimal(o1[3].toString()); BigDecimal pa2 = (BigDecimal) o2[1]; BigDecimal pv2 = (BigDecimal) o2[2]; BigDecimal qte2 = new BigDecimal(o2[3].toString()); BigDecimal marge1 = pv1.subtract(pa1).multiply(qte1, DecimalUtils.HIGH_PRECISION); BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, DecimalUtils.HIGH_PRECISION); return pv1.compareTo(pv2); } }); SQLTable tableFamille = tableVFElement.getTable("FAMILLE_ARTICLE"); BigDecimal total = BigDecimal.ZERO; for (int i = 0; i < rowsArticle.size(); i++) { Object[] o = rowsArticle.get(i); BigDecimal pv2 = (BigDecimal) o[2]; total = total.add(pv2); } if (total.signum() > 0) { for (int i = 0; i < 12 && i < rowsArticle.size(); i++) { Object[] o = rowsArticle.get(i); BigDecimal pa2 = (BigDecimal) o[1]; BigDecimal pv2 = (BigDecimal) o[2]; BigDecimal qte2 = new BigDecimal(o[3].toString()); BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, DecimalUtils.HIGH_PRECISION); String s = "Indfini"; if (o[0] != null) { int id = ((Number) o[0]).intValue(); s = tableFamille.getRow(id).getString("NOM"); } values.add(pv2); labels.add(s + "(" + decFormat.format(pv2.setScale(2, RoundingMode.HALF_UP).doubleValue()) + " soit " + pv2.divide(total, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP) + "%)"); } } return total; }
From source file:org.egov.works.services.WorkProgressAbstractReportService.java
/** * Converting given amount to show in Crores with no of decimal points to be rounded off * * @param amount/* ww w. j a v a 2 s. c o m*/ * @param decimalPoints * @return */ public BigDecimal getRoundedOfAmount(final Object amount, final int decimalPoints) { final int dividingFactor = 10000000; // 1 Crore if (amount != null) { final BigDecimal divisor = new BigDecimal(dividingFactor); final BigDecimal amountBD = (BigDecimal) amount; final BigDecimal result = amountBD.divide(divisor); return result.setScale(decimalPoints, RoundingMode.HALF_UP); } else return null; }
From source file:org.cirdles.ambapo.UTMToLatLong.java
/** * /* w w w.jav a 2 s.c o m*/ * @param xiPrime * @param etaPrime * @return tau prime */ private static BigDecimal calcTauPrime(BigDecimal xiPrime, BigDecimal etaPrime) { double xiPrimeDouble = xiPrime.doubleValue(); double etaPrimeDouble = etaPrime.doubleValue(); BigDecimal sinOfXiPrime = new BigDecimal(Math.sin(xiPrimeDouble)); BigDecimal cosOfXiPrime = new BigDecimal(Math.cos(xiPrimeDouble)); BigDecimal sinhOfEtaPrime = new BigDecimal(Math.sinh(etaPrimeDouble)); BigDecimal squareRoot = new BigDecimal( Math.sqrt(sinhOfEtaPrime.pow(2).add(cosOfXiPrime.pow(2)).doubleValue())); BigDecimal tauPrime = sinOfXiPrime.divide(squareRoot, PRECISION, RoundingMode.HALF_UP); return tauPrime; }
From source file:org.yes.cart.payment.impl.PayPalNvpPaymentGatewayImpl.java
private NVPEncoder createAuthRequest(final Payment payment, final String paymentAction) { final NVPEncoder encoder = new NVPEncoder(); encoder.add("METHOD", "DoDirectPayment"); encoder.add("PAYMENTACTION", paymentAction); encoder.add("AMT", payment.getPaymentAmount().setScale(2, RoundingMode.HALF_UP).toString()); encoder.add("CREDITCARDTYPE", payment.getCardType()); encoder.add("ACCT", payment.getCardNumber()); encoder.add("EXPDATE", payment.getCardExpireMonth() + payment.getCardExpireYear()); encoder.add("CVV2", payment.getCardCvv2Code()); encoder.add("FIRSTNAME", payment.getBillingAddress().getFirstname()); encoder.add("LASTNAME", payment.getBillingAddress().getLastname()); encoder.add("STREET", getStreetAddress(payment.getBillingAddress().getAddrline1(), payment.getBillingAddress().getAddrline2())); encoder.add("CITY", payment.getBillingAddress().getCity()); encoder.add("STATE", payment.getBillingAddress().getStateCode()); encoder.add("ZIP", payment.getBillingAddress().getStateCode()); encoder.add("COUNTRYCODE", payment.getBillingAddress().getCountryCode()); encoder.add("CURRENCYCODE", payment.getOrderCurrency()); return encoder; }
From source file:com.envision.envservice.service.RankingListService.java
private List<SpiritSortBo> sortuserPraiseNumSort(Map<String, Integer> lowerUserPraiseNum, final SortType sortType) { List<SpiritSortBo> sbos = new ArrayList<SpiritSortBo>(); for (Entry<String, Integer> entry : lowerUserPraiseNum.entrySet()) { if (!TOTAL.equals(entry.getKey())) { SpiritSortBo sbo = new SpiritSortBo(); sbo.setUserId(entry.getKey()); BigDecimal fz = new BigDecimal(entry.getValue()); BigDecimal fm = new BigDecimal(lowerUserPraiseNum.get(TOTAL)); if (fm.intValue() == 0) { sbo.setPercent("0"); } else { DecimalFormat df = new DecimalFormat("0.00"); String pe = df.format(fz.multiply(new BigDecimal(100)).divide(fm, 2, RoundingMode.HALF_UP)); sbo.setPercent(pe);//w ww . j a v a 2 s. c o m } sbos.add(sbo); } } // ? // Collections.sort(sbos, new SpiritSortBoComparator(sortType)); Collections.sort(sbos, new Comparator<SpiritSortBo>() { public int compare(SpiritSortBo o1, SpiritSortBo o2) { BigDecimal o1Percent = new BigDecimal(o1.getPercent()); BigDecimal o2Percent = new BigDecimal(o2.getPercent()); int multiplier = -1; if (sortType.equals(SortType.ASC)) { multiplier = 1; } return o1Percent.compareTo(o2Percent) * multiplier; } }); return sbos; }
From source file:com.cmsz.cloudplatform.utils.StringUtils.java
public static String convertHz(String hz) { if (StringUtil.isNullString(hz)) { return null; }//from ww w . j ava 2 s.c o m // NumberFormat format = new DecimalFormat("##0.00"); BigDecimal _1000 = new BigDecimal(1000); BigDecimal value = new BigDecimal(hz); if (value.compareTo(_1000) == -1) { return value + " MHz"; } else { return value.divide(_1000, 2, RoundingMode.HALF_UP) + " GHz"; } }