List of usage examples for java.math BigDecimal ROUND_CEILING
int ROUND_CEILING
To view the source code for java.math BigDecimal ROUND_CEILING.
Click Source Link
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("40"); BigDecimal bg2 = new BigDecimal("3"); BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_CEILING); System.out.println(bg3);/* w w w .j a v a2 s. c o m*/ }
From source file:Main.java
public static int getDurationToInt(long duration) { int d = 0;//from ww w . jav a2s.c o m try { BigDecimal b = new BigDecimal(Long.toString(duration)); BigDecimal one = new BigDecimal("1000"); d = b.divide(one, 0, BigDecimal.ROUND_CEILING).intValue(); } catch (Exception e) { e.printStackTrace(); d = 0; } return d; }
From source file:com.algoTrader.util.RoundUtil.java
public static BigDecimal roundStockOptionStrikeToNextN(BigDecimal spot, double n, OptionType type) { if (OptionType.CALL.equals(type)) { // increase by strikeOffset and round to upper n return roundToNextN(spot, n, BigDecimal.ROUND_CEILING); } else {/*from ww w.j a v a 2 s. c o m*/ // reduce by strikeOffset and round to lower n return roundToNextN(spot, n, BigDecimal.ROUND_FLOOR); } }
From source file:org.yes.cart.service.dto.impl.ComplexSearchUtils.java
/** * Check if filter is a number search with prefix * * Format: [prefix]\d+// w ww.j a v a2s. c om * * E.g. -1, +1.01, #333 where -,+ and # are prefix characters * * @param filter non empty filter * @param binarySortedPrefixes prefixes * @param precision precision * * @return prefix and number */ public static Pair<String, BigDecimal> checkNumericSearch(String filter, char[] binarySortedPrefixes, int precision) { if (filter.length() > 1 && Arrays.binarySearch(binarySortedPrefixes, filter.charAt(0)) >= 0) { try { final BigDecimal qty = new BigDecimal(filter.substring(1)).setScale(precision, BigDecimal.ROUND_CEILING); if (qty.signum() == -1) { return null; } return new Pair<>(filter.substring(0, 1), qty); } catch (Exception exp) { // do nothing return null; } } return null; }
From source file:Money.java
/** * returns Money . If roundCeiling is true we rounded up to * the nearest cent, otherwise we round down. Note that rounding toward the ceiling * always rounds to positive infinity (so, for example, -$0.031 becomes * -$0.03). When roundCeiling is false we round toward the floor, so in that case * -$0.031 becomes-$0.04. This is exactly as BigDecimal.ROUND_CEILING and * BigDecimal.ROUND_FLOOR behave.//from w ww . j a v a 2 s . co m * @see java.math.BigDecimal.ROUND_CEILING */ public Money multiplyAndRound(BigDecimal val, boolean roundCeiling) { BigDecimal product = delegate.multiply(val); int rounding = roundCeiling ? BigDecimal.ROUND_CEILING : BigDecimal.ROUND_FLOOR; return new Money(product.setScale(2, rounding)); }
From source file:org.springframework.data.gemfire.examples.server.SalesFunctions.java
/** * This method computes total sales for a given product. The <code>@GemfireFunction</code> * annotation allows this function to be wrapped in a GemFire {@link Function} and registered with the given * id.//from ww w. j a v a2 s .c o m * * @param productName * @return */ @GemfireFunction public BigDecimal totalSalesForProduct(String productName) { log.debug("searching for product name '" + productName + "'"); SelectResults<Product> results = productTemplate.query("name = '" + productName + "'"); if (results.isEmpty()) { log.warn("cannot find product '" + productName + "'"); return new BigDecimal(0.0); } Product product = results.asList().get(0); long productId = product.getId(); BigDecimal total = new BigDecimal(0.0); for (Order order : orderRegion.values()) { for (LineItem lineItem : order.getLineItems()) { if (lineItem.getProductId() == productId) { total = total.add(lineItem.getTotal()); } } } return total.setScale(2, BigDecimal.ROUND_CEILING); }
From source file:fr.paris.lutece.plugins.plu.utils.PluUtils.java
/** * Transform a byte size to a readable size including units * @param size size in bytes/* www . j ava 2 s . co m*/ * @return size in string */ public static String formatSize(Long size) { String displaySize; if (size / FileUtils.ONE_GB > 0) { displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_GO, BigDecimal.ROUND_CEILING)) + " GO"; } else if (size / FileUtils.ONE_MB > 0) { displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_MO, BigDecimal.ROUND_CEILING)) + " MO"; } else if (size / FileUtils.ONE_KB > 0) { displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_KO, BigDecimal.ROUND_CEILING)) + " KO"; } else { displaySize = String.valueOf(size) + " octets"; } return displaySize; }
From source file:org.springframework.data.gemfire.examples.CalculateTotalSalesForProduct.java
@Override public void execute(FunctionContext functionContext) { ResultSender<BigDecimal> resultSender = functionContext.getResultSender(); String productName = (String) functionContext.getArguments(); log.debug("searching for product name '" + productName + "'"); SelectResults<Product> results = productTemplate.query("name = '" + productName + "'"); if (results.isEmpty()) { log.warn("cannot find product '" + productName + "'"); resultSender.lastResult(new BigDecimal(0.0)); return;/* w w w. ja v a 2 s .c o m*/ } Product product = results.asList().get(0); long productId = product.getId(); BigDecimal total = new BigDecimal(0.0); for (Order order : orderRegion.values()) { for (LineItem lineItem : order.getLineItems()) { if (lineItem.getProductId() == productId) { total = total.add(lineItem.getTotal()); } } } resultSender.lastResult(total.setScale(2, BigDecimal.ROUND_CEILING)); }
From source file:ch.algotrader.service.algo.VariableIncrementalOrderService.java
@Override protected VariableIncrementalOrderStateVO handleValidateOrder(final VariableIncrementalOrder algoOrder) { Security security = algoOrder.getSecurity(); SecurityFamily family = security.getSecurityFamily(); TickVO tick = (TickVO) this.marketDataCacheService.getCurrentMarketDataEvent(security.getId()); double bidDouble = tick.getBid().doubleValue(); double askDouble = tick.getAsk().doubleValue(); double spread = askDouble - bidDouble; double increment = algoOrder.getIncrement() * spread; double limit; double maxLimit; if (Side.BUY.equals(algoOrder.getSide())) { double limitRaw = bidDouble + algoOrder.getStartOffsetPct() * spread; double maxLimitRaw = bidDouble + algoOrder.getEndOffsetPct() * spread; limit = RoundUtil.roundToNextN(limitRaw, family.getTickSize(null, limitRaw, true), BigDecimal.ROUND_FLOOR); maxLimit = RoundUtil.roundToNextN(maxLimitRaw, family.getTickSize(null, maxLimitRaw, true), BigDecimal.ROUND_CEILING); } else {//from ww w . j a va 2 s . c o m double limitRaw = askDouble - algoOrder.getStartOffsetPct() * spread; double maxLimitRaw = askDouble - algoOrder.getEndOffsetPct() * spread; limit = RoundUtil.roundToNextN(limitRaw, family.getTickSize(null, limitRaw, true), BigDecimal.ROUND_CEILING); maxLimit = RoundUtil.roundToNextN(maxLimitRaw, family.getTickSize(null, maxLimitRaw, true), BigDecimal.ROUND_FLOOR); } // limit and maxLimit are correctly rounded according to tickSizePattern BigDecimal startLimit = RoundUtil.getBigDecimal(limit, family.getScale(null)); BigDecimal endLimit = RoundUtil.getBigDecimal(maxLimit, family.getScale(null)); return new VariableIncrementalOrderStateVO(startLimit, endLimit, startLimit, increment); }
From source file:org.egov.utils.BudgetDetailHelper.java
public String getActualsFor(final Map<String, Object> paramMap, final Date asOn) { paramMap.put(Constants.ASONDATE, asOn); try {/*from w ww . j a v a 2 s .co m*/ return budgetDetailsDAO.getActualBudgetUtilized(paramMap).setScale(0, BigDecimal.ROUND_CEILING) .toString(); } catch (final ValidationException e) { return "0.0"; } catch (final ArithmeticException e) { return "0.0"; } }