List of usage examples for java.math BigDecimal setScale
@Deprecated(since = "9") public BigDecimal setScale(int newScale, int roundingMode)
From source file:ec.edu.distri.clientejava.protocolo.model.Canal.java
public void setCosto(BigDecimal costo) { this.costo = costo.setScale(2, RoundingMode.HALF_UP); }
From source file:com.hotelbeds.hotelapimodel.auto.convert.json.RateSerializer.java
@Override public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeString(value.setScale(value.scale(), BigDecimal.ROUND_HALF_EVEN).toString()); }
From source file:org.apache.ojb.ejb.ArticleVO.java
public void setPrice(BigDecimal price) { if (price != null) price.setScale(2, BigDecimal.ROUND_HALF_UP); this.price = price; }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.GeometricMeanBigDecimalTest.java
/** * Corrects any rounding errors due to differences in the implementation of * the statistic between the Apache and MicroFlex libraries * @param BigDecimal the first result * @param BigDecimal the second result * @return corrected results *///from w w w . ja v a2 s .c o m private static BigDecimal[] correctRoundingErrors(BigDecimal bd1, BigDecimal bd2) { BigDecimal[] array = new BigDecimal[2]; int scale = mc.getPrecision(); while (!bd1.equals(bd2) && scale > mc.getPrecision() / 4) { bd1 = bd1.setScale(scale, RoundingMode.HALF_DOWN); bd2 = bd2.setScale(scale, RoundingMode.HALF_DOWN); if (bd1.subtract(bd1.ulp()).equals(bd2)) { bd1 = bd1.subtract(bd1.ulp()); } if (bd1.add(bd1.ulp()).equals(bd2)) { bd1 = bd1.add(bd1.ulp()); } scale--; } array[0] = bd1; array[1] = bd2; return array; }
From source file:tibano.service.ParkService.java
@RequestMapping(path = "/getPaymentInfo") PaymentInfo getPaymentInfo(@RequestParam(name = "areaId") Long areaId, @RequestParam(name = "licensePlate") String licensePlate) { ParkingTransaction pt = ptRepository.findOpenTransactionByAreaAndLicensePlate(areaId, licensePlate); if (pt != null) { Duration duration = Duration.between(pt.getStart(), LocalDateTime.now()); Double amount = duration.getSeconds() * SEC_TARIF; BigDecimal bd = new BigDecimal(amount); bd = bd.setScale(2, RoundingMode.HALF_UP); Integer loyaltyPoints = 5 + Integer.valueOf(Double.valueOf(bd.doubleValue()).intValue()); return new PaymentInfo(pt.getEnd(), amount, duration, loyaltyPoints); }//from w w w . j ava2 s. c o m return new PaymentInfo(null, Double.valueOf(0), Duration.ZERO, Integer.valueOf(0)); }
From source file:org.opencredo.cloud.storage.samples.quote.QuoteService.java
public void lookupQuote(Message<String> tickerMessage) { BigDecimal price = new BigDecimal(new Random().nextDouble() * 100); LOG.info("Quote Update... {}: {}", tickerMessage.getPayload(), price.setScale(2, RoundingMode.HALF_EVEN)); }
From source file:org.codhaus.groovy.grails.validation.ScaleConstraint.java
/** * @return the <code>BigDecimal</code> object that results from applying the contraint's scale to the underlying number * @param originalValue The original value *///from w ww .j ava 2 s . c o m private BigDecimal getScaledValue(BigDecimal originalValue) { return originalValue.setScale(scale, BigDecimal.ROUND_HALF_UP); }
From source file:com.codecrate.shard.level.ConstantRateLevelCalculator.java
public int calculateValue(int level) { BigDecimal value = rate.multiply(new BigDecimal(level - 1)); value = value.add(new BigDecimal(initialValue)); value = value.setScale(0, BigDecimal.ROUND_HALF_UP); LOG.debug("Computed value for level " + level + " is: " + value); return value.intValue(); }
From source file:com.create.databind.MoneySerializer.java
@Override public void serialize(BigDecimal value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { final String moneyValue = value.setScale(CURRENCY_SCALE, BigDecimal.ROUND_HALF_UP).toString(); jsonGenerator.writeString(moneyValue); }
From source file:feedme.model.Order.java
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(); }