List of usage examples for java.math BigDecimal BigDecimal
public BigDecimal(long val)
From source file:cz.muni.fi.pa165.legomanager.dao.LegoSetDaoImplTest.java
@Test public void testCreate() { LegoSet set = createLegoSet("Star Wars", new BigDecimal(10), new ArrayList<LegoKit>(), new HashSet<Category>()); legoSetDao.addLegoSet(set);/*ww w.j ava2 s .com*/ LegoSet setFromDb = em.find(LegoSet.class, set.getId()); assertNotNull(setFromDb); assertDeepEquals(setFromDb, set); }
From source file:kr.ac.kaist.se.simulator.NormalDistributor.java
public int getNextVal() { String _val = Double.toString(this.distGenerator.sample()); BigDecimal dec = new BigDecimal(_val); BigDecimal std = new BigDecimal(Integer.toString(this.stDev)); dec = dec.add(new BigDecimal(Integer.toString(mean))); std = std.multiply(new BigDecimal(_val)); int retVal = dec.add(std).toBigInteger().intValue(); return retVal; }
From source file:com.ar.dev.tierra.api.dao.impl.FiscalDAOImpl.java
@Override public void ticket(List<DetalleFactura> detalles) { try (PrintWriter ticket = new PrintWriter("command/ticket.200")) { DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setMaximumFractionDigits(1); ticket.println("@" + (char) 28 + "T" + (char) 28 + "T"); BigDecimal descuento = new BigDecimal(BigInteger.ZERO); for (DetalleFactura detalle : detalles) { if (detalle.getDescuentoDetalle() != null) { descuento = descuento.add(detalle.getDescuentoDetalle()); }//ww w.j a v a 2 s . c o m String price = null; BigDecimal sinIVA = detalle.getProducto().getPrecioVenta().subtract(detalle.getProducto() .getPrecioVenta().multiply(new BigDecimal(17.35)).divide(new BigDecimal(100))); price = sinIVA.setScale(4, RoundingMode.HALF_UP).toString(); ticket.println("B" + (char) 28 /*Abrimos linea*/ + detalle.getProducto().getDescripcion() + (char) 28 /*Nombre producto*/ + detalle.getCantidadDetalle() + ".0" + (char) 28 /*Cantidad*/ + price.replace(",", ".") + (char) 28 /*Precio unitario*/ + "21.0" + (char) 28 /*Impuestos IVA*/ + "M" + (char) 28 /*Suma monto*/ + "0.0" + (char) 28 /*Impuestos internos*/ + "0" + (char) 28 /*Parametro display*/ + "b"); /*Cierra de linea*/ } if (!descuento.equals(new BigDecimal(BigInteger.ZERO))) { ticket.println("T" + (char) 28 /*Abrimos linea descuento*/ + "Descuento: " + (char) 28 /*Texto a mostrar*/ + descuento + (char) 28 /*Monto descuento*/ + "m" + (char) 28 /*m: descuento, M: aumento*/ + "0" + (char) 28 /*parametro display*/ + "T"); /*cierre linea descuento*/ } ticket.println("E"); } catch (FileNotFoundException ex) { Logger.getLogger(FiscalDAOImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.mycompany.carshop.test.repository.CreditCardRepositoryTest.java
@Test(enabled = true) public void createCreditCard() { creditCardRepository = ctx.getBean(CreditCardRepository.class); CreditCard creditCard = new CreditCard.Builder("50361592227975").balance(new BigDecimal(2000.00)) .expiryDate(new Date()).nameOnCreditCard("Baloyi Rhulie").build(); creditCardRepository.save(creditCard); id = creditCard.getId();// w ww .j av a 2s . co m Assert.assertNotNull(creditCard); }
From source file:de.jfachwert.math.Bruch.java
private static BigInteger[] toNumbers(String bruch) { BigInteger[] numbers = new BigInteger[2]; String[] parts = StringUtils.split(bruch, "/"); try {/*from w ww . ja v a 2 s .c o m*/ switch (parts.length) { case 1: Bruch dezimalBruch = toBruch(new BigDecimal(parts[0])); numbers[0] = dezimalBruch.getZaehler(); numbers[1] = dezimalBruch.getNenner(); break; case 2: numbers[0] = new BigInteger(parts[0]); numbers[1] = new BigInteger(parts[1]); break; default: throw new LocalizedIllegalArgumentException(bruch, "fraction"); } return numbers; } catch (IllegalArgumentException ex) { throw new LocalizedIllegalArgumentException(bruch, "fraction", ex); } }
From source file:com.konakart.util.TaxUtils.java
/** * Calculates the tax for one or more items * // w ww .j av a 2 s .c o m * @param taxRate * tax rate as a percentage * @param cost * cost of a single item * @param quantity * Number of items * @param scale * This is the scale used for the precision of the calculations. It is contained in * the ADMIN_CURRENCY_DECIMAL_PLACES configuration variable. * @param rule * The rule to be used which should be either TAX_PER_ITEM or TAX_ON_TOTAL. * <ul> * <li> * TaxUtils.TAX_PER_ITEM : The tax is calculated for a single item, to the number of * decimal places defined by scale. Then this value is multiplied by the quantity. * <li> * TaxUtils.TAX_ON_TOTAL : The tax is calculated for the total amount (single item * cost x quantity). * </ul> * @return Returns the tax amount * */ public static BigDecimal getTaxAmount(BigDecimal taxRate, BigDecimal cost, int quantity, int scale, int rule) { if (taxRate == null || cost == null || quantity == 0) { return new BigDecimal(0); } BigDecimal lTaxRate = taxRate.divide(new BigDecimal(100)); if (rule == TAX_PER_ITEM) { BigDecimal taxPerItem = cost.multiply(lTaxRate); taxPerItem = taxPerItem.setScale(scale, BigDecimal.ROUND_HALF_UP); BigDecimal totalTax = taxPerItem.multiply(new BigDecimal(quantity)); totalTax = totalTax.setScale(scale, BigDecimal.ROUND_HALF_UP); return totalTax; } else if (rule == TAX_ON_TOTAL) { BigDecimal totalPrice = cost.multiply(new BigDecimal(quantity)); BigDecimal totalTax = totalPrice.multiply(lTaxRate); totalTax = totalTax.setScale(scale, BigDecimal.ROUND_HALF_UP); return totalTax; } // Should never get this far return new BigDecimal(0); }
From source file:br.com.sicoob.cro.cop.batch.core.FileReadTasklet.java
@Override public void process() { try {/* ww w. j a v a2 s. c o m*/ List<Operation> operacoes = new ArrayList(); InputStream source = this.getClass() .getResourceAsStream(this.context.getParameters().get("nomeArquivo").toString()); Scanner scan = new Scanner(source); while (scan.hasNext()) { String[] dados = scan.next().split(";"); Operation operacao = new Operation(dados[0], new BigDecimal(dados[1]), dados[2], new BigDecimal(dados[3])); operacoes.add(operacao); } // calcula o percentual de provisionamento for (Operation operacao : operacoes) { LOG.info(operacao.toString()); } scan.close(); source.close(); } catch (IOException ex) { Logger.getLogger(FileReadTasklet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.jp.systemdirector.projectzero.zab01.ap.logicbean.SZAB011CUpdateLogicBean.java
@Transactional public SZAB011CUpdateResultData execute(ContextData context, SZAB011CUpdateInputData inputData) { SZAB011CUpdateResultData resultData = new SZAB011CUpdateResultData(); SZAB011CUpdateDTO zUpdateDTO = new SZAB011CUpdateDTO(); // DTO?inputData? zUpdateDTO.setIN1(context.getProductCd()); zUpdateDTO.setQUANTITY(new BigDecimal(context.getQuantity())); try {/*from w w w . j a v a 2 s.com*/ int result = dao.update(zUpdateDTO); resultData.setAffectLines(result); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } return resultData; }
From source file:org.owasp.dependencytrack.model.VulnerabilityTest.java
@Test @Transactional/* ww w.jav a 2 s . c o m*/ public void testObject() throws Exception { Vulnerability vulnerability = new Vulnerability(); vulnerability.setId(1); vulnerability.setName("CVE-YYYY-XXXX"); vulnerability.setMatchedCPE("cpe:/a/vendor:name:version"); vulnerability.setDescription("CVE description"); vulnerability.setCvssScore(new BigDecimal(5.5)); vulnerability.setMatchedAllPreviousCPE("cpe:/a/previous:name:version"); assertEquals(new Integer(1), vulnerability.getId()); assertEquals("CVE-YYYY-XXXX", vulnerability.getName()); assertEquals("cpe:/a/vendor:name:version", vulnerability.getMatchedCPE()); assertEquals("CVE description", vulnerability.getDescription()); assertEquals(new BigDecimal(5.5), vulnerability.getCvssScore()); assertEquals("cpe:/a/previous:name:version", vulnerability.getMatchedAllPreviousCPE()); }
From source file:com.fatsecret.platform.utils.ServingUtility.java
/** * Returns food nutrient values according to serving sizes * /*from ww w . j a v a2 s. c o m*/ * @param json json object representing nutritional information of the food * @return food nutrient values according to serving sizes */ public static Serving parseServingFromJSONObject(JSONObject json) { Serving serving = new Serving(); try { Long servingId = Long.parseLong(json.getString("serving_id")); serving.setServingId(servingId); } catch (Exception ignore) { } try { String servingDescription = json.getString("serving_description"); serving.setServingDescription(servingDescription); } catch (Exception ignore) { } try { String servingUrl = json.getString("serving_url"); serving.setServingUrl(servingUrl); } catch (Exception ignore) { } try { String metricServingAmountString = json.getString("metric_serving_amount"); BigDecimal metricServingAmount = new BigDecimal(metricServingAmountString); serving.setMetricServingAmount(metricServingAmount); } catch (Exception ignore) { } try { String metricServingUnit = json.getString("metric_serving_unit"); serving.setMetricServingUnit(metricServingUnit); } catch (Exception ignore) { } try { String numberOfUnitsString = json.getString("number_of_units"); BigDecimal numberOfUnits = new BigDecimal(numberOfUnitsString); serving.setNumberOfUnits(numberOfUnits); } catch (Exception ignore) { } try { String measurementDescription = json.getString("measurement_description"); serving.setMeasurementDescription(measurementDescription); } catch (Exception ignore) { } try { String caloriesString = json.getString("calories"); BigDecimal calories = new BigDecimal(caloriesString); serving.setCalories(calories); } catch (Exception ignore) { } try { String carbohydrateString = json.getString("carbohydrate"); BigDecimal carbohydrate = new BigDecimal(carbohydrateString); serving.setCarbohydrate(carbohydrate); } catch (Exception ignore) { } try { String proteinString = json.getString("protein"); BigDecimal protein = new BigDecimal(proteinString); serving.setProtein(protein); } catch (Exception ignore) { } try { String fatString = json.getString("fat"); BigDecimal fat = new BigDecimal(fatString); serving.setFat(fat); } catch (Exception ignore) { } try { String saturatedFatString = json.getString("saturated_fat"); BigDecimal saturatedFat = new BigDecimal(saturatedFatString); serving.setSaturatedFat(saturatedFat); } catch (Exception ignore) { } try { String polyunsaturatedFatString = json.getString("polyunsaturated_fat"); BigDecimal polyunsaturatedFat = new BigDecimal(polyunsaturatedFatString); serving.setPolyunsaturatedFat(polyunsaturatedFat); } catch (Exception ignore) { } try { String monounsaturatedFatString = json.getString("monounsaturated_fat"); BigDecimal monounsaturatedFat = new BigDecimal(monounsaturatedFatString); serving.setMonounsaturatedFat(monounsaturatedFat); } catch (Exception ignore) { } try { String transFatString = json.getString("trans_fat"); BigDecimal transFat = new BigDecimal(transFatString); serving.setTransFat(transFat); } catch (Exception ignore) { } try { String cholesterolString = json.getString("cholesterol"); BigDecimal cholesterol = new BigDecimal(cholesterolString); serving.setCholesterol(cholesterol); } catch (Exception ignore) { } try { String sodiumString = json.getString("sodium"); BigDecimal sodium = new BigDecimal(sodiumString); serving.setSodium(sodium); } catch (Exception ignore) { } try { String potassiumString = json.getString("potassium"); BigDecimal potassium = new BigDecimal(potassiumString); serving.setPotassium(potassium); } catch (Exception ignore) { } try { String fiberString = json.getString("fiber"); BigDecimal fiber = new BigDecimal(fiberString); serving.setFiber(fiber); } catch (Exception ignore) { } try { String sugarString = json.getString("sugar"); BigDecimal sugar = new BigDecimal(sugarString); serving.setSugar(sugar); } catch (Exception ignore) { } try { String vitaminAString = json.getString("vitamin_a"); BigDecimal vitaminA = new BigDecimal(vitaminAString); serving.setVitaminA(vitaminA); } catch (Exception ignore) { } try { String vitaminCString = json.getString("vitamin_c"); BigDecimal vitaminC = new BigDecimal(vitaminCString); serving.setVitaminC(vitaminC); } catch (Exception ignore) { } try { String calciumString = json.getString("calcium"); BigDecimal calcium = new BigDecimal(calciumString); serving.setCalcium(calcium); } catch (Exception ignore) { } try { String ironString = json.getString("iron"); BigDecimal iron = new BigDecimal(ironString); serving.setIron(iron); } catch (Exception ignore) { } return serving; }