List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:pe.gob.mef.gescon.hibernate.impl.ContenidoDaoImpl.java
@Override public List<Tconocimiento> getContenidos() throws Exception { DetachedCriteria criteria = DetachedCriteria.forClass(Tconocimiento.class); criteria.add(Restrictions.eq("ntipoconocimientoid", BigDecimal.valueOf(Long.parseLong("4")))); criteria.addOrder(Order.desc("dfechacreacion")); return (List<Tconocimiento>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.impotch.calcul.impot.cantonal.ge.pp.ConstructeurBaremeDeductionBeneficiaireRenteAVSAITest.java
@Test public void coupleDeuxRentes2014() { BaremeConstantParTranche bareme = constructeur.construireBaremeCoupleDeuxRentes(2014); assertThat(bareme.calcul(BigDecimal.valueOf(57947))).isEqualTo("11589"); assertThat(bareme.calcul(BigDecimal.valueOf(57948))).isEqualTo("9272"); }
From source file:com.trenako.web.controllers.form.WishListFormTests.java
@Test public void shouldUseTheCurrencyCodeFromUserProfileCreatingWishLists() { WishListForm form = WishListForm.newForm(messageSource); form.setBudget(BigDecimal.valueOf(150.50)); WishList wlUSD = form.buildWishList(owner("USD")); assertEquals("$150.50", wlUSD.getBudget().toString()); WishList wlGBP = form.buildWishList(owner("GBP")); assertEquals("GBP150.50", wlGBP.getBudget().toString()); }
From source file:io.coala.time.Rate.java
/** * {@link Rate} static factory method// w w w .j av a 2 s . c om */ public static Rate of(final long value, final Unit<Frequency> amount) { return of(BigDecimal.valueOf(value), amount); }
From source file:eu.europa.ec.grow.espd.xml.common.exporting.UblRequirementFactory.java
public static QuantityType buildQuantityIntegerType(Integer number) { if (number == null) { return null; }/*w w w. j av a 2 s. c o m*/ QuantityType quantityType = new QuantityType(); quantityType.setValue(BigDecimal.valueOf(number)); quantityType.setUnitCode("NUMBER"); return quantityType; }
From source file:client.Pi.java
/** * Compute the value, in radians, of the arctangent of * the inverse of the supplied integer to the specified * number of digits after the decimal point. The value * is computed using the power series expansion for the * arc tangent://from ww w . j a va 2 s. co m * * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + * (x^9)/9 ... */ public static BigDecimal arctan(int inverseX, int scale) { BigDecimal result, numer, term; BigDecimal invX = BigDecimal.valueOf(inverseX); BigDecimal invX2 = BigDecimal.valueOf(inverseX * inverseX); numer = BigDecimal.ONE.divide(invX, scale, roundingMode); result = numer; int i = 1; do { numer = numer.divide(invX2, scale, roundingMode); int denom = 2 * i + 1; term = numer.divide(BigDecimal.valueOf(denom), scale, roundingMode); if ((i % 2) != 0) { result = result.subtract(term); } else { result = result.add(term); } i++; } while (term.compareTo(BigDecimal.ZERO) != 0); return result; }
From source file:cn.bjfu.springdao.jpa.domain.order.LineItem.java
/** * Returns the total for the {@link LineItem}. * * @return */ public BigDecimal getTotal() { return price.multiply(BigDecimal.valueOf(amount)); }
From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java
/** * * This method computes the number of months between any 2 given {@link java.sql.Date} objects * * @param dateStart starting date.// w ww .j a va 2 s . c o m * @param dateEnd end date. * * @return number of months between the start date and end date. */ @Override public ScaleTwoDecimal getNumberOfMonths(java.util.Date dateStart, java.util.Date dateEnd) { ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO; int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart); endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount)) .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction)); return monthCount; }
From source file:de.hybris.platform.commercefacades.product.converters.populator.ProductPricePopulator.java
@Override public void populate(final SOURCE productModel, final TARGET productData) throws ConversionException { final PriceDataType priceType; final PriceInformation info; if (CollectionUtils.isEmpty(productModel.getVariants())) { priceType = PriceDataType.BUY;//from w ww . j ava 2s. com info = getCommercePriceService().getWebPriceForProduct(productModel); } else { priceType = PriceDataType.FROM; info = getCommercePriceService().getFromPriceForProduct(productModel); } if (info != null) { final PriceData priceData = getPriceDataFactory().create(priceType, BigDecimal.valueOf(info.getPriceValue().getValue()), info.getPriceValue().getCurrencyIso()); productData.setPrice(priceData); } else { productData.setPurchasable(Boolean.FALSE); } }
From source file:bg.elkabel.calculator.service.CoreServiceImpl.java
private double calculateWeight(Material material, double coreSize) { double result = 0.0; switch (material.ordinal()) { case 0:// w ww . j av a 2s. c om result = Math.pow(coreSize, 2) * Math.PI / 4 * 2.7 * 1 / 1000; break; case 1: result = Math.pow(coreSize, 2) * Math.PI / 4 * 8.9 * 1 / 1000; break; } return BigDecimal.valueOf(result).setScale(6, RoundingMode.HALF_UP).doubleValue(); }