List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:es.tid.fiware.rss.expenditureLimit.manager.test.BalanceAccumulateManagerTest.java
/** * /*from ww w .j a va 2 s.c o m*/ */ @Test public void deleteUserAccumulated() throws RSSException { BalanceAccumulateManagerTest.logger.debug("Into getUserAccumulated method."); ExpendControl control = generateExpendControl(); balanceAccumulateManager.deleteUserAccumulated(endUserId, control); BalanceAccumulateManagerTest.logger.debug("Get objects after deleting."); AccumsExpend result = balanceAccumulateManager.getUserAccumulated(endUserId, control.getService(), control.getAppProvider(), control.getCurrency(), control.getType()); Assert.assertTrue(result.getAccums().size() > 0); boolean changed = false; for (AccumExpend accum : result.getAccums()) { if (accum.getType().equalsIgnoreCase(control.getType()) && accum.getExpensedAmount().compareTo(BigDecimal.valueOf(0)) == 0) { changed = true; } } Assert.assertTrue(changed); }
From source file:es.tid.fiware.rss.service.RSSModelsManagerTest.java
@Test public void checkValidRSSModelRevenuelessThan0Test() throws Exception { logger.debug("checkValidRSSModelTest"); // nothing happens rssModelsManager.checkValidRSSModel(rssModel); thrown.expect(RSSException.class); thrown.expectMessage("percRevenueShare must be greater than 0"); rssModel.setPercRevenueShare(BigDecimal.valueOf(-1)); rssModelsManager.checkValidRSSModel(rssModel); }
From source file:com.opengamma.examples.analyticservice.ExampleAnalyticServiceUsage.java
private String generateTrade(String securityId, String destinationName, JmsConnector jmsConnector) { SimpleTrade trade = new SimpleTrade(); trade.setCounterparty(COUNTERPARTY); trade.setPremiumCurrency(Currency.USD); trade.setQuantity(BigDecimal.valueOf(_random.nextInt(10) + 10)); trade.setTradeDate(LocalDate.now()); String providerId = GUIDGenerator.generate().toString(); trade.addAttribute(PROVIDER_ID_NAME, RANDOM_ID_SCHEME + "~" + providerId); trade.setSecurityLink(new SimpleSecurityLink(ExternalSchemes.syntheticSecurityId(securityId))); s_logger.debug("Generated {}", trade); FudgeMsg msg = s_fudgeContext.toFudgeMsg(trade).getMessage(); s_logger.debug("sending {} to {}", msg, destinationName); final byte[] bytes = s_fudgeContext.toByteArray(msg); jmsConnector.getJmsTemplateQueue().send(destinationName, new MessageCreator() { @Override//from w w w . j av a 2 s. c om public Message createMessage(Session session) throws JMSException { BytesMessage bytesMessage = session.createBytesMessage(); bytesMessage.writeBytes(bytes); return bytesMessage; } }); return providerId; }
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.GanttDiagramTagLib.java
private String generateGanttDiagramString() throws JspException { switch (getViewTypeEnum()) { case TOTAL:/* w ww. j a v a2 s. c o m*/ return generateGanttDiagramInTotalMode(convertToEm(getGanttDiagramObject().getMonthsDaysSize())) .toString(); case MONTHLY_TOTAL: return generateGanttDiagramInTotalMode(convertToEm(getGanttDiagramObject().getMonthsDaysSize())) .toString(); case MONTHLY: return generateGanttDiagramInTimeMode(BigDecimal.valueOf(getGanttDiagramObject().getDays().size()) .multiply(convertToEm(NUMBER_OF_DAY_HOURS))).toString(); case WEEKLY: return generateGanttDiagramInTimeMode( BigDecimal.valueOf(7).multiply(convertToEm(NUMBER_OF_DAY_HALF_HOURS))).toString(); case DAILY: return generateGanttDiagramInTimeMode(convertToEm(NUMBER_OF_DAY_5_MINUTES)).toString(); case YEAR_DAILY: return generateGanttDiagramInTimeMode(BigDecimal.valueOf(getGanttDiagramObject().getDays().size()) .multiply(convertToEm(NUMBER_OF_DAY_HOURS))).toString(); default: return ""; } }
From source file:com.akartkam.inShop.domain.order.OrderItem.java
@Transient @CurrencyFormat//from w ww . ja va 2s. c om public BigDecimal getRowTotal() { BigDecimal returnValue = BigDecimal.ZERO; if (quantity != null) { BigDecimal quant = BigDecimal.valueOf(quantity); if (price != null) { returnValue = price.multiply(quant); } } return returnValue; }
From source file:Main.java
/** * Compute the natural logarithm of x to a given scale, x > 0. * Use Newton's algorithm./*from w ww .j a v a 2s .c o m*/ */ private static BigDecimal lnNewton(BigDecimal x, int scale) { int sp1 = scale + 1; BigDecimal n = x; BigDecimal term; // Convergence tolerance = 5*(10^-(scale+1)) BigDecimal tolerance = BigDecimal.valueOf(5).movePointLeft(sp1); // Loop until the approximations converge // (two successive approximations are within the tolerance). do { // e^x BigDecimal eToX = exp(x, sp1); // (e^x - n)/e^x term = eToX.subtract(n).divide(eToX, sp1, BigDecimal.ROUND_DOWN); // x - (e^x - n)/e^x x = x.subtract(term); Thread.yield(); } while (term.compareTo(tolerance) > 0); return x.setScale(scale, BigDecimal.ROUND_HALF_EVEN); }
From source file:com.streamsets.pipeline.stage.it.DecimalTypeIT.java
@Test public void incompatibleScale() throws Exception { executeUpdate("CREATE TABLE `tbl` (id int, dec decimal(4, 2)) PARTITIONED BY (dt string) STORED AS AVRO"); HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().decimalConfig(4, 2).build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); List<Record> records = new LinkedList<>(); Map<String, Field> map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 1)); map.put("dec", Field.create(BigDecimal.valueOf(0.123))); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record);// ww w. j a va2 s . c o m try { processRecords(processor, hiveTarget, records); Assert.fail("Expected failure!"); } catch (OnRecordErrorException e) { Assert.assertEquals(Errors.HIVE_26, e.getErrorCode()); Assert.assertTrue(e.getMessage().contains("scale 3 is more then expected 2")); } }
From source file:de.inren.service.banking.BankDataServiceImpl.java
private BigDecimal getBigDecimal(String value) { value = value.replace(".", ""); value = value.replace(',', '.'); return BigDecimal.valueOf(Double.parseDouble(value)); }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.Utils.java
public static String formatSize(Integer size) { String formattedFileSize = ""; if (size != null) { BigDecimal kb = BigDecimal.valueOf(1024); BigDecimal mb = BigDecimal.valueOf(1048576); BigDecimal fileSizeBD = BigDecimal.valueOf(size); if (size > 999999) { formattedFileSize = fileSizeBD.divide(mb, 2, RoundingMode.HALF_UP).toPlainString(); formattedFileSize += " MB"; } else if (size > 999) { formattedFileSize = fileSizeBD.divide(kb, 2, RoundingMode.HALF_UP).toPlainString(); formattedFileSize += " KB"; } else {/* w w w . j a v a 2s. c om*/ formattedFileSize = fileSizeBD.toPlainString(); formattedFileSize += " B"; } } return formattedFileSize; }
From source file:com.streamsets.pipeline.lib.parser.excel.TestWorkbookParser.java
@Test public void testParseCorrectlyEmptyLeadingRowsAndColumns() throws IOException, InvalidFormatException, DataParserException { Workbook workbook = createWorkbook("/excel/TestExcelEmptyRowsCols.xlsx"); WorkbookParser parser = new WorkbookParser(settingsWithHeader, getContext(), workbook, "Sheet1::0"); // column header prefix, row value multiplier List<Pair<String, Integer>> sheetParameters = Arrays.asList(Pair.of("column", 1), Pair.of("header", 10)); for (int sheet = 1; sheet <= sheetParameters.size(); sheet++) { for (int row = 1; row <= 2; row++) { Record parsedRow = parser.parse(); LinkedHashMap<String, Field> contentMap = new LinkedHashMap<>(); String columnPrefix = sheetParameters.get(sheet - 1).getLeft(); Integer valueMultiplier = sheetParameters.get(sheet - 1).getRight(); for (int column = 1; column <= 3 + sheet; column++) { contentMap.put(columnPrefix + column, Field.create(BigDecimal.valueOf(column * valueMultiplier))); }/*ww w.j a v a2s . c o m*/ Field expectedRow = Field.createListMap(contentMap); assertEquals(String.format("Parsed value for sheet %1d, row %2d did not match expected value", sheet, row), expectedRow, parsedRow.get()); } } }