List of usage examples for java.math BigDecimal ROUND_UP
int ROUND_UP
To view the source code for java.math BigDecimal ROUND_UP.
Click Source Link
From source file:BigNumCalc.java
public BigDecimal calculate(Object[] input) { BigDecimal tmp;/*from ww w . ja v a2s .c om*/ for (int i = 0; i < input.length; i++) { Object o = input[i]; if (o instanceof BigDecimal) { s.push(o); } else if (o instanceof String) { switch (((String) o).charAt(0)) { // + and * are commutative, order doesn't matter case '+': s.push(((BigDecimal) s.pop()).add((BigDecimal) s.pop())); break; case '*': s.push(((BigDecimal) s.pop()).multiply((BigDecimal) s.pop())); break; // - and /, order *does* matter case '-': tmp = (BigDecimal) s.pop(); s.push(((BigDecimal) s.pop()).subtract(tmp)); break; case '/': tmp = (BigDecimal) s.pop(); s.push(((BigDecimal) s.pop()).divide(tmp, BigDecimal.ROUND_UP)); break; default: throw new IllegalStateException("Unknown OPERATOR popped"); } } else { throw new IllegalArgumentException("Syntax error in input"); } } return (BigDecimal) s.pop(); }
From source file:org.skfiy.typhon.spi.atlasloot.SingleAtlasloot.java
@Override void prepare() { p_prob = MathUtils.round((1 - getProb()) / factor, 3, BigDecimal.ROUND_UP); }
From source file:io.seldon.prediction.VariationPredictionStrategy.java
public static VariationPredictionStrategy build(List<Variation> variations) { Map<Range, SimplePredictionStrategy> strategyMap = new LinkedHashMap<>(); BigDecimal ratioTotal = BigDecimal.ZERO; for (Variation var : variations) { ratioTotal = ratioTotal.add(var.ratio); }/* ww w .j a va 2 s . c o m*/ BigDecimal currentMax = BigDecimal.ZERO; for (Variation var : variations) { NumberRange range = new NumberRange(currentMax, currentMax.add(var.ratio.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); strategyMap.put(range, var.variationStrategy); currentMax = currentMax.add(var.ratio); } return new VariationPredictionStrategy(strategyMap); }
From source file:com.sequenceiq.ambari.shell.flash.InstallProgress.java
@Override public String getText() { StringBuilder sb = new StringBuilder(); if (!done) {/* w w w. j a va2 s. c o m*/ BigDecimal progress = client.getRequestProgress(); if (progress != null) { BigDecimal decimal = progress.setScale(2, BigDecimal.ROUND_HALF_UP); int intValue = decimal.intValue(); if (intValue != SUCCESS && intValue != FAILED) { sb.append("Installation: ").append(decimal).append("% "); int rounded = round(progress.setScale(0, BigDecimal.ROUND_UP).intValue() / 10); for (int i = 0; i < 10; i++) { if (i < rounded) { sb.append("="); } else { sb.append("-"); } } } else if (intValue == FAILED) { sb.append("Installation: FAILED"); done = true; } else { sb.append("Installation: COMPLETE"); done = true; } } else { sb.append("Installation: WAITING.."); } } else { if (exit) { System.exit(0); } } return sb.toString(); }
From source file:io.seldon.recommendation.VariationTestingClientStrategy.java
public static VariationTestingClientStrategy build(List<Variation> variations) { Map<Range, ClientStrategy> strategyMap = new LinkedHashMap<>(); BigDecimal ratioTotal = BigDecimal.ZERO; for (Variation var : variations) { ratioTotal = ratioTotal.add(var.ratio); }//from w w w .j ava 2s . c om BigDecimal currentMax = BigDecimal.ZERO; for (Variation var : variations) { NumberRange range = new NumberRange(currentMax, currentMax.add(var.ratio.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); strategyMap.put(range, var.variationStrategy); currentMax = currentMax.add(var.ratio); } return new VariationTestingClientStrategy(strategyMap); }
From source file:org.apache.sling.etcd.testing.tree.Node.java
/** * @return the timeout in second or {@code null} if no timeout is set. A timeout of {@code 0} is elapsed. *//*from w w w .jav a2 s.c o m*/ @Nullable public Integer ttl() { if (timeout != null) { long now = System.currentTimeMillis(); BigDecimal delta = new BigDecimal((timeout - now) / 1000.0D); // we round up the ttl to 1 if the value in ms is > 1 return Math.max(0, delta.setScale(0, BigDecimal.ROUND_UP).intValue()); } return null; }
From source file:com.netsteadfast.greenstep.bsc.command.WeightBodyCommand.java
private void autoAllocation(BscStructTreeObj treeObj) throws Exception { int scale = 2; for (VisionVO vision : treeObj.getVisions()) { for (int px = 0; px < vision.getPerspectives().size(); px++) { PerspectiveVO perspective = vision.getPerspectives().get(px); int round = BigDecimal.ROUND_DOWN; if ((px + 1) == vision.getPerspectives().size()) { round = BigDecimal.ROUND_UP; }// w ww. j a va2 s . c o m perspective.setWeight( MAX_WEIGHT_VALUE.divide(new BigDecimal(vision.getPerspectives().size()), scale, round)); for (int ox = 0; ox < perspective.getObjectives().size(); ox++) { ObjectiveVO objective = perspective.getObjectives().get(ox); round = BigDecimal.ROUND_DOWN; if ((ox + 1) == perspective.getObjectives().size()) { round = BigDecimal.ROUND_UP; } objective.setWeight(MAX_WEIGHT_VALUE.divide(new BigDecimal(perspective.getObjectives().size()), scale, round)); for (int kx = 0; kx < objective.getKpis().size(); kx++) { KpiVO kpi = objective.getKpis().get(kx); round = BigDecimal.ROUND_DOWN; if ((kx + 1) == objective.getKpis().size()) { round = BigDecimal.ROUND_UP; } kpi.setWeight( MAX_WEIGHT_VALUE.divide(new BigDecimal(objective.getKpis().size()), scale, round)); } } } } }
From source file:io.seldon.recommendation.VariationTestingClientStrategyTest.java
@Test public void rangeTest() { BigDecimal ratioTotal = new BigDecimal(1.0); BigDecimal currentMax = new BigDecimal(0.0); BigDecimal r1 = new BigDecimal(0.9); BigDecimal r2 = new BigDecimal(0.1); NumberRange range1 = new NumberRange(currentMax, currentMax.add(r1.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); currentMax = currentMax.add(r1);//from www .j a va2s . c om NumberRange range2 = new NumberRange(currentMax.add(new BigDecimal(0.0001)), currentMax.add(r2.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); BigDecimal t = new BigDecimal(0.900001); Assert.assertTrue(range1.containsNumber(t)); Assert.assertFalse(range2.containsNumber(t)); BigDecimal t2 = new BigDecimal(0.901); Assert.assertFalse(range1.containsNumber(t2)); Assert.assertTrue(range2.containsNumber(t2)); }
From source file:de.kopis.glacier.util.VaultInventoryPrinter.java
private String humanReadableSize(final String size) throws IllegalArgumentException { final String[] sanitizedSize = sanitize(size); double sizeAsDouble = 0; try {//from ww w.ja v a2 s . c o m // parse as US value, because WTF? java default? sizeAsDouble = NumberFormat.getInstance(Locale.US).parse(sanitizedSize[0]).doubleValue(); } catch (final ParseException e) { throw new IllegalArgumentException("Can not parse Number", e); } String humanReadableSize = ""; String sizeClass = sanitizedSize[1]; if (sizeAsDouble > 1024) { sizeClass = getLargerSizeClass(sanitizedSize[1]); humanReadableSize = humanReadableSize(sizeAsDouble / 1024.0 + " " + sizeClass); } else { humanReadableSize = round(Double.toString(sizeAsDouble), 2, BigDecimal.ROUND_UP) + sizeClass; } return humanReadableSize; }
From source file:org.openhab.binding.nikobus.internal.config.ModuleChannelGroup.java
/** * Push the state of all channels to the Nikobus. * // w ww . j a va2 s . c om * @param moduleChannel */ public void publishStateToNikobus(ModuleChannel moduleChannel, NikobusBinding binding) { log.trace("Publishing group {}-{} status to eventbus and nikobus", address, group); // update the channel on the event bus.. binding.postUpdate(moduleChannel.getName(), moduleChannel.getState()); StringBuilder command = new StringBuilder(); command.append(statusUpdateGroup); command.append(address); for (int i = 0; i < 6; i++) { if (channels[i] == null) { // no channel defined command.append(LOW_BYTE); continue; } State channelState = channels[i].getState(); if (channelState == null || channelState.equals(OnOffType.OFF) || channelState.equals(PercentType.ZERO)) { command.append(LOW_BYTE); } else if (channelState.equals(UpDownType.UP)) { command.append(UP_BYTE); } else if (channelState.equals(UpDownType.DOWN)) { command.append(DOWN_BYTE); } else if (channelState instanceof PercentType) { // calculate dimmer value... PercentType currentState = (PercentType) channelState; int value = BigDecimal.valueOf(255).multiply(currentState.toBigDecimal()) .divide(BigDecimal.valueOf(100), 0, BigDecimal.ROUND_UP).intValue(); command.append(StringUtils.leftPad(Integer.toHexString(value), 2, "0").toUpperCase()); } else { command.append(HIGH_BYTE); } } command.append(HIGH_BYTE); NikobusCommand cmd = new NikobusCommand( CRCUtil.appendCRC2(STATUS_CHANGE_CMD + CRCUtil.appendCRC(command.toString()))); try { binding.sendCommand(cmd); } catch (Exception e) { log.error("Error sending command.", e); } }