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:sv.com.mined.sieni.controller.GestionNotasController.java
public synchronized void guardarModifica() { try {/*w w w .j a v a2s.c om*/ this.getNotaModifica().setIdAlumno(this.getIdAlumnoModifica().getIdAlumno()); this.getNotaModifica().setIdEvaluacion(this.getIdEvaluacionModifica()); if (validarModifica(this.getNotaModifica())) {//valida el guardado BigDecimal nota = new BigDecimal(this.getNotaModifica().getNtCalificacion()); this.getNotaModifica().setNtCalificacion(nota.setScale(2, RoundingMode.HALF_UP).doubleValue()); setNotaModHistorial("Modificacion", this.getNotaModifica()); sieniNotaFacadeRemote.edit(this.getNotaModifica()); registrarEnBitacora("Modificar", "Nota", this.getNotaModifica().getIdNota()); new ValidationPojo().printMsj("Nota Modificada Exitosamente", FacesMessage.SEVERITY_INFO); } } catch (Exception e) { new ValidationPojo().printMsj("Ocurri un error:" + e, FacesMessage.SEVERITY_ERROR); System.out.println(e.getMessage()); } }
From source file:org.egov.ptis.repository.dashboard.RevenueDashboardRepository.java
public Map<String, Object> collectionsPaymentMode() { final List<Object[]> typeCollection = getQuery("revenue.ptis.collecion.payment.type").list(); final BigDecimal totalTransactions = BigDecimal .valueOf((Double) getQuery("revenue.ptis.collecion.total").uniqueResult()); final DecimalFormat df = new DecimalFormat("####0.00"); final List<Map<String, Object>> overAllCollHolder = new LinkedList<Map<String, Object>>(); final Map<String, BigDecimal> overallCollPercHolder = new HashMap<String, BigDecimal>(); for (final Object[] collObj : typeCollection) { final Map<String, Object> collPaymentType = new HashMap<String, Object>(); collPaymentType.put("name", String.valueOf(collObj[0])); BigDecimal collectionPerc = collObj[1] != null ? new BigDecimal(collObj[1].toString()) : BigDecimal.ZERO; collectionPerc = collectionPerc.multiply(BigDecimal.valueOf(100)).divide(totalTransactions, 2, RoundingMode.HALF_UP); overallCollPercHolder.put(String.valueOf(collObj[0]), collectionPerc != null ? collectionPerc : BigDecimal.ZERO); collPaymentType.put("y", collectionPerc != null ? new BigDecimal(df.format(collectionPerc.doubleValue())) : 0); overAllCollHolder.add(collPaymentType); }/* w w w . j a va 2 s . c o m*/ final List<Object[]> totalNoTransactions = getQuery("revenue.ptis.collecion.total.type").list(); final List<Map<String, Object>> totalPercTrans = new LinkedList<Map<String, Object>>(); final BigDecimal totalCount = new BigDecimal( getQuery("revenue.ptis.collecion.total.count").uniqueResult().toString()); for (final Object[] revenueObj : totalNoTransactions) { final Map<String, Object> revnTotalTransData = new HashMap<String, Object>(); revnTotalTransData.put("name", String.valueOf(revenueObj[0])); BigDecimal numberTransactions = revenueObj[1] != null ? new BigDecimal(revenueObj[1].toString()) : BigDecimal.ZERO; numberTransactions = numberTransactions.multiply(BigDecimal.valueOf(100)).divide(totalCount, 2, RoundingMode.HALF_UP); revnTotalTransData.put("y", numberTransactions != null ? new BigDecimal(df.format(numberTransactions.doubleValue())) : 0); revnTotalTransData.put("overAllPerc", new BigDecimal( df.format(overallCollPercHolder.get(String.valueOf(revenueObj[0])).doubleValue()))); totalPercTrans.add(revnTotalTransData); } // SORT BY TOTAL COUNT % sortData(totalPercTrans, "y"); // SORT BY COLLECTION % sortData(overAllCollHolder, "y"); // SORT BACK BY OVER ALL COUNT % sortData(totalPercTrans, "overAllPerc"); final Map<String, Object> revenueAggrData = new HashMap<String, Object>(); revenueAggrData.put("overallColl", overAllCollHolder); revenueAggrData.put("totalTransPerc", totalPercTrans); return revenueAggrData; }
From source file:org.projectforge.fibu.datev.EmployeeSalaryExportDao.java
private void addEmployeeRow(final ExportSheet sheet, final EmployeeDO employee, final BigDecimal numberOfWorkingDays, final BigDecimal totalDuration) { final PFUserDO user = userGroupCache.getUser(employee.getUserId()); final ExportRow row = sheet.addRow(); row.addCell(0, user.getFullname());//w w w .ja v a 2 s . com // Wochenstunden row.addCell(1, employee.getWochenstunden(), "STUNDEN"); // Sollstunden: Wochenstunden * Arbeitstage / 5 Arbeitstage pro Woche Integer wochenstunden = employee.getWochenstunden(); if (wochenstunden == null) { wochenstunden = 0; } final BigDecimal soll = new BigDecimal(wochenstunden).multiply(numberOfWorkingDays) .divide(new BigDecimal(5), 2, RoundingMode.HALF_UP); row.addCell(2, soll, "STUNDEN"); // Iststunden final BigDecimal total = totalDuration.divide(new BigDecimal(3600000), 2, RoundingMode.HALF_UP); row.addCell(3, total, "STUNDEN"); // Differenz final BigDecimal differenz = total.subtract(soll); row.addCell(4, differenz, "STUNDEN"); }
From source file:org.cgiar.ccafs.marlo.action.projects.ProjectBudgetByFlagshipAction.java
/** * Roun up the value that the user put in the value field * // w ww . ja v a2s. com * @param value * @param places * @return round number value */ public double round(double value, int places) { if (places < 0) { throw new IllegalArgumentException(); } BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); }
From source file:com.mgmtp.perfload.perfalyzer.PerfAlyzerModule.java
@Provides @IntFormat/*from ww w . ja v a 2 s . c o m*/ NumberFormat provideIntFormat(final Locale locale) { NumberFormat nf = NumberFormat.getIntegerInstance(locale); nf.setGroupingUsed(false); nf.setRoundingMode(RoundingMode.HALF_UP); return nf; }
From source file:org.openbravo.costing.LandedCostProcess.java
private void matchCostWithInvoiceLine(LandedCostCost lcc) { LCMatched lcm = OBProvider.getInstance().get(LCMatched.class); lcm.setOrganization(lcc.getOrganization()); lcm.setLandedCostCost(lcc);/*from w ww . j ava 2 s. c om*/ lcm.setAmount(lcc.getAmount()); lcm.setInvoiceLine(lcc.getInvoiceLine()); OBDal.getInstance().save(lcm); final OBCriteria<ConversionRateDoc> conversionRateDoc = OBDal.getInstance() .createCriteria(ConversionRateDoc.class); conversionRateDoc .add(Restrictions.eq(ConversionRateDoc.PROPERTY_INVOICE, lcm.getInvoiceLine().getInvoice())); ConversionRateDoc invoiceconversionrate = (ConversionRateDoc) conversionRateDoc.uniqueResult(); Currency currency = lcc.getOrganization().getCurrency() != null ? lcc.getOrganization().getCurrency() : lcc.getOrganization().getClient().getCurrency(); ConversionRate landedCostrate = FinancialUtils.getConversionRate(lcc.getLandedCost().getReferenceDate(), lcc.getCurrency(), currency, lcc.getOrganization(), lcc.getClient()); if (invoiceconversionrate != null && invoiceconversionrate.getRate() != landedCostrate.getMultipleRateBy()) { BigDecimal amount = lcc.getAmount().multiply(invoiceconversionrate.getRate()) .subtract(lcc.getAmount().multiply(landedCostrate.getMultipleRateBy())) .divide(landedCostrate.getMultipleRateBy(), currency.getStandardPrecision().intValue(), RoundingMode.HALF_UP); LCMatched lcmCm = OBProvider.getInstance().get(LCMatched.class); lcmCm.setOrganization(lcc.getOrganization()); lcmCm.setLandedCostCost(lcc); lcmCm.setAmount(amount); lcmCm.setInvoiceLine(lcc.getInvoiceLine()); lcmCm.setConversionmatching(true); OBDal.getInstance().save(lcmCm); lcc.setMatched(Boolean.FALSE); lcc.setProcessed(Boolean.FALSE); lcc.setMatchingAdjusted(true); OBDal.getInstance().flush(); LCMatchingProcess.doProcessLCMatching(lcc); } lcc.setMatched(Boolean.TRUE); lcc.setProcessed(Boolean.TRUE); OBCriteria<LCMatched> critMatched = OBDal.getInstance().createCriteria(LCMatched.class); critMatched.add(Restrictions.eq(LCMatched.PROPERTY_LANDEDCOSTCOST, lcc)); critMatched.setProjection(Projections.sum(LCMatched.PROPERTY_AMOUNT)); BigDecimal matchedAmt = (BigDecimal) critMatched.uniqueResult(); if (matchedAmt == null) { matchedAmt = lcc.getAmount(); } lcc.setMatchingAmount(matchedAmt); }
From source file:org.openhab.binding.pilight.internal.PilightBinding.java
private BigDecimal getPercentageFromDimLevel(String string) { return new BigDecimal(string).setScale(2).divide(new BigDecimal(MAX_DIM_LEVEL), RoundingMode.HALF_UP) .multiply(new BigDecimal(100)); }
From source file:com.mgmtp.perfload.perfalyzer.PerfAlyzerModule.java
@Provides @FloatFormat/*from w w w. ja v a 2 s .c o m*/ NumberFormat provideFloatFormat(final Locale locale) { DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); NumberFormat nf = new DecimalFormat("0.00", dfs); nf.setGroupingUsed(false); nf.setRoundingMode(RoundingMode.HALF_UP); return nf; }
From source file:org.sputnikdev.bluetooth.gattparser.FieldHolder.java
/** * Sets the field value into a new BigInteger value. * @param value a new field value/*from ww w . j av a 2 s.c o m*/ */ public void setBigInteger(BigInteger value) { if (value == null) { this.value = null; } else { BigDecimal vl = new BigDecimal(value); Double maximum = field.getMaximum(); if (maximum != null && vl.compareTo(new BigDecimal(maximum)) > 0) { throw new IllegalArgumentException("Value [" + value + "] is greater than maximum: " + maximum); } Double minimum = field.getMinimum(); if (minimum != null && vl.compareTo(new BigDecimal(minimum)) < 0) { throw new IllegalArgumentException("Value [" + value + "] is less than minimum: " + minimum); } double multiplier = getMultiplier(); double offset = getOffset(); BigInteger adjusted; if (multiplier != 1.0 || offset != 0.0) { adjusted = vl.subtract(BigDecimal.valueOf(offset)).setScale(0, RoundingMode.HALF_UP) .divide(BigDecimal.valueOf(multiplier)).toBigInteger(); } else { adjusted = value; } if (field.getFormat().isStruct()) { this.value = new TwosComplementNumberFormatter().serialize(adjusted, adjusted.bitLength(), false) .toByteArray(); } else { this.value = getConverter().convert(null, adjusted); } } }
From source file:com.baidu.rigel.biplatform.ma.resource.utils.DataModelUtils.java
private static CellData parseCellData(BigDecimal value) { CellData data = new CellData(); data.setCellId(""); data.setFormattedValue("I,III.DD"); if (value != null) { value = value.setScale(8, RoundingMode.HALF_UP); data.setV(value);/*from w w w. jav a 2 s . c o m*/ } else { value = BigDecimal.ZERO; data.setV(value); } return data; }