List of usage examples for java.math BigDecimal setScale
@Deprecated(since = "9") public BigDecimal setScale(int newScale, int roundingMode)
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.message.BinRpcMessage.java
private void addObject(Object object) { if (object.getClass() == String.class) { addInt(3);//from w w w. j a v a 2s. co m String string = (String) object; addInt(string.length()); addString(string); } else if (object.getClass() == Boolean.class) { addInt(2); addByte(((Boolean) object).booleanValue() ? (byte) 1 : (byte) 0); } else if (object.getClass() == Integer.class) { addInt(1); addInt(((Integer) object).intValue()); } else if (object.getClass() == Double.class) { addInt(4); addDouble(((Double) object).doubleValue()); } else if (object.getClass() == Float.class) { addInt(4); BigDecimal bd = new BigDecimal((Float) object); addDouble(bd.setScale(6, RoundingMode.HALF_DOWN).doubleValue()); } else if (object.getClass() == BigDecimal.class) { addInt(4); addDouble(((BigDecimal) object).setScale(6, RoundingMode.HALF_DOWN).doubleValue()); } else if (object.getClass() == BigInteger.class) { addInt(4); addDouble(((BigInteger) object).doubleValue()); } else if (object.getClass() == Date.class) { addInt(5); addInt((int) ((Date) object).getTime() / 1000); } else if (object instanceof List<?>) { Collection<?> list = (Collection<?>) object; addInt(0x100); addInt(list.size()); addList(list); } else if (object instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) object; addInt(0x101); addInt(map.size()); for (Map.Entry<?, ?> entry : map.entrySet()) { String key = (String) entry.getKey(); if (key != null) { addInt(key.length()); addString(key); addList(Collections.singleton(entry.getValue())); } } } }
From source file:org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.AbstractFeatureConverter.java
private String convertToBytes(HierarchicalStreamReader reader, String unit) { BigDecimal resourceSize = new BigDecimal(reader.getValue()); resourceSize = resourceSize.setScale(1, BigDecimal.ROUND_HALF_UP); switch (unit) { case B://from w ww . ja va2 s .c om break; case KB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_KB)); break; case MB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_MB)); break; case GB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_GB)); break; case TB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_TB)); break; case PB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_PB)); break; default: break; } String resourceSizeAsString = resourceSize.toPlainString(); LOGGER.debug("resource size in bytes: {}", resourceSizeAsString); return resourceSizeAsString; }
From source file:com.opensourcestrategies.financials.accounts.GLAccountInTree.java
/** * Gets the debit of this GL account children GL accounts. * @return a <code>BigDecimal</code> value *///from w ww . j ava 2s. c om public BigDecimal getDebitOfChildren() { BigDecimal debitOfChildren = BigDecimal.ZERO; for (GLAccountInTree childAccount : childAccounts) { debitOfChildren = debitOfChildren.add(getDebitOfChildrenRec(childAccount)); } return debitOfChildren.setScale(AccountsHelper.decimals, AccountsHelper.rounding); }
From source file:com.opensourcestrategies.financials.accounts.GLAccountInTree.java
/** * Gets the credit of this GL account children GL accounts. * @return a <code>BigDecimal</code> value *//*from ww w .java2 s . c o m*/ public BigDecimal getCreditOfChildren() { BigDecimal creditOfChildren = BigDecimal.ZERO; for (GLAccountInTree childAccount : childAccounts) { creditOfChildren = creditOfChildren.add(getCreditOfChildrenRec(childAccount)); } return creditOfChildren.setScale(AccountsHelper.decimals, AccountsHelper.rounding); }
From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java
/** * Displays the accounts' movements balances by period * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted *///from w w w . j a v a2 s.c o m private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Movements' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the movements' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphMovementsBalancesTopComponent.class, "GraphMovementsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelMovementsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>( balances.get(moneyContainer).keySet()); for (SearchCriteria searchCriteria : sortedSearchFilters) { BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria); accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN); dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelMovementsBalances.removeAll(); jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER); jPanelMovementsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:com.opensourcestrategies.financials.accounts.GLAccountInTree.java
/** * Gets the balance of this GL account children GL accounts. * @return a <code>BigDecimal</code> value *///from ww w . ja v a 2 s .com public BigDecimal getBalanceOfChildren() { BigDecimal balanceOfChildren = BigDecimal.ZERO; for (GLAccountInTree childAccount : childAccounts) { balanceOfChildren = balanceOfChildren.add(getBalanceOfChildrenRec(childAccount)); } return balanceOfChildren.setScale(AccountsHelper.decimals, AccountsHelper.rounding); }
From source file:net.sourceforge.fenixedu.domain.Guide.java
public void updateTotalValue() { BigDecimal total = BigDecimal.ZERO; for (final GuideEntry guideEntry : getGuideEntriesSet()) { total = total//from w ww . ja v a 2s . c o m .add(guideEntry.getPriceBigDecimal().multiply(BigDecimal.valueOf(guideEntry.getQuantity()))); } total.setScale(2, RoundingMode.HALF_EVEN); setTotalBigDecimal(total); }
From source file:tasly.greathealth.erp.order.services.impl.DefaultOrderUpdateService.java
private BigDecimal double2BigDecimal(final double refundAmount) { final BigDecimal decimal = new BigDecimal(Double.toString(refundAmount)); decimal.setScale(3, BigDecimal.ROUND_HALF_UP); if (decimal.precision() > 18) { erpOrderLog.warn(UO_LogHead + "Message: " + "refundAmount" + ": " + refundAmount + "," + decimal.precision() + ",?" + "(15,3)" + "."); erpOrderLog.warn(UO_LogHead + "Message:" + "refundAmount" + ",?????ECC."); }//from w ww . j av a 2 s . com return decimal; }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.message.BinRpcMessage.java
private Object readRpcValue() throws IOException { int type = readInt(); switch (type) { case 1://from w w w . jav a 2 s.c om return new Integer(readInt()); case 2: return binRpcData[offset++] != 0 ? Boolean.TRUE : Boolean.FALSE; case 3: return readString(); case 4: int mantissa = readInt(); int exponent = readInt(); BigDecimal bd = new BigDecimal((double) mantissa / (double) (1 << 30) * Math.pow(2, exponent)); return bd.setScale(6, RoundingMode.HALF_DOWN).doubleValue(); case 5: return new Date(readInt() * 1000); case 0x100: // Array int numElements = readInt(); Collection<Object> array = new ArrayList<Object>(); while (numElements-- > 0) { array.add(readRpcValue()); } return array.toArray(); case 0x101: // Struct numElements = readInt(); Map<String, Object> struct = new TreeMap<String, Object>(); while (numElements-- > 0) { String name = readString(); struct.put(name, readRpcValue()); } return struct; default: for (int i = 0; i < binRpcData.length; i++) { logger.info("{} {}", Integer.toHexString(binRpcData[i]), (char) binRpcData[i]); } throw new IOException("Unknown data type " + type); } }
From source file:com.esd.ps.LoginController.java
/** * ,?,?,?//from w w w . j a v a2 s. c o m * @return */ @RequestMapping(value = "/datas", method = RequestMethod.POST) @ResponseBody public Map<String, Object> datasPost() { Map<String, Object> map = new HashMap<String, Object>(); int peopleCountTotle = workerService.getWorkerCount(); double moneyTotle = 0.00; try { moneyTotle = salaryService.getMoneyTotle(0); } catch (NullPointerException n) { } int taskCountTotle = taskService.getWorkerIdZeroCountByPackId(0); int taskCount = taskService.getCountTaskDoing(1); double moneyToday = 0.00; try { moneyToday = salaryService.getMoneyTotle(1); } catch (NullPointerException n) { moneyToday = 0.00; } BigDecimal b = new BigDecimal(moneyTotle / 18); moneyTotle = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); BigDecimal b1 = new BigDecimal(moneyToday / 18); moneyToday = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); map.put("peopleCountTotle", peopleCountTotle); map.put("moneyTotle", moneyTotle); map.put("taskCountTotle", taskCountTotle); map.put("taskCount", taskCount); map.put("moneyToday", moneyToday); return map; }