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:org.onebusaway.webapp.actions.admin.vehiclestatus.VehicleStatusAction.java
private void buildResponse(List<VehicleStatus> vehicleRecordsPerPage, Integer pageNum, Integer rowsPerPage, int totalRecords) { String totalPages = StringUtils.EMPTY; vehicleGridResponse = new VehicleGridResponse(); //Set page number vehicleGridResponse.setPage(page);/*w ww. ja v a 2 s . c o m*/ //Calculate records per page if (totalRecords <= (rowsPerPage * pageNum)) { totalPages = String.valueOf(pageNum); } else { //Set total pages (no of records / records per page) totalPages = new BigDecimal(totalRecords).divide(new BigDecimal(rowsPerPage), BigDecimal.ROUND_UP) .toPlainString(); } vehicleGridResponse.setRecords(String.valueOf(totalRecords)); vehicleGridResponse.setRows(vehicleRecordsPerPage); vehicleGridResponse.setTotal(totalPages); }
From source file:com.salesmanager.core.util.CurrencyUtil.java
/** * Converts a BigDecimal amount from a given currency to another currency * // ww w .j a v a 2s . c o m * @param amount * @param originCurrency * @param toCurrency * @return */ public static BigDecimal convertToCurrency(BigDecimal amount, String originCurrency, String toCurrency) { try { // get originCurrency Map currencies = RefCache.getCurrenciesListWithCodes(); double returnAmount = amount.doubleValue(); com.salesmanager.core.entity.reference.Currency origin = (com.salesmanager.core.entity.reference.Currency) currencies .get(originCurrency); com.salesmanager.core.entity.reference.Currency convert = (com.salesmanager.core.entity.reference.Currency) currencies .get(toCurrency); if (origin == null) { log.error("Origin currency " + originCurrency + " not found"); return amount; } if (convert == null) { log.error("Convert currency " + toCurrency + " not found"); return amount; } returnAmount = returnAmount / origin.getValue().doubleValue(); returnAmount = returnAmount * convert.getValue().doubleValue(); return new BigDecimal(returnAmount).setScale(2, BigDecimal.ROUND_UP); } catch (Exception e) { log.equals(e); return amount; } }
From source file:org.kuali.kpme.core.util.TKUtils.java
public static int convertMillisToWholeDays(long millis) { BigDecimal days = convertMillisToDays(millis); return Integer.parseInt(days.setScale(0, BigDecimal.ROUND_UP).toString()); }
From source file:ch.algotrader.entity.security.SecurityFamilyImpl.java
@Override public BigDecimal roundUp(String broker, BigDecimal price) { Validate.notNull(price, "Price cannot be null"); return RoundUtil.roundToNextN(price, getTickSize(broker, price, true), BigDecimal.ROUND_UP); }
From source file:vteaexploration.plottools.panels.XYExplorationPanel.java
public void makeOverlayImage(ArrayList gates, int x, int y, int xAxis, int yAxis) { //convert gate to chart x,y path Gate gate;//from w w w .ja v a2s.c o m ListIterator<Gate> gate_itr = gates.listIterator(); //.get int total = 0; int gated = 0; int selected = 0; int gatedSelected = 0; int gatecount = gates.size(); while (gate_itr.hasNext()) { gate = gate_itr.next(); if (gate.getSelected()) { Path2D path = gate.createPath2DInChartSpace(); ArrayList<MicroObject> result = new ArrayList<MicroObject>(); ArrayList<MicroObject> volumes = (ArrayList) this.plotvalues.get(1); MicroObjectModel volume; double xValue = 0; double yValue = 0; ListIterator<MicroObject> it = volumes.listIterator(); try { while (it.hasNext()) { volume = it.next(); if (volume != null) { xValue = ((Number) processPosition(xAxis, (MicroObject) volume)).doubleValue(); yValue = ((Number) processPosition(yAxis, (MicroObject) volume)).doubleValue(); if (path.contains(xValue, yValue)) { result.add((MicroObject) volume); } } } } catch (NullPointerException e) { } ; Overlay overlay = new Overlay(); int count = 0; BufferedImage placeholder = new BufferedImage(impoverlay.getWidth(), impoverlay.getHeight(), BufferedImage.TYPE_INT_ARGB); ImageStack gateOverlay = new ImageStack(impoverlay.getWidth(), impoverlay.getHeight()); selected = getSelectedObjects(); total = volumes.size(); gated = getGatedObjects(impoverlay); gatedSelected = getGatedSelected(impoverlay); for (int i = 0; i <= impoverlay.getNSlices(); i++) { BufferedImage selections = new BufferedImage(impoverlay.getWidth(), impoverlay.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = selections.createGraphics(); ImageRoi ir = new ImageRoi(0, 0, placeholder); ListIterator<MicroObject> vitr = result.listIterator(); while (vitr.hasNext()) { try { MicroObject vol = (MicroObject) vitr.next(); int[] x_pixels = vol.getXPixelsInRegion(i); int[] y_pixels = vol.getYPixelsInRegion(i); for (int c = 0; c < x_pixels.length; c++) { g2.setColor(gate.getColor()); g2.drawRect(x_pixels[c], y_pixels[c], 1, 1); } ir = new ImageRoi(0, 0, selections); count++; } catch (NullPointerException e) { } } ir.setPosition(i); ir.setOpacity(0.4); overlay.add(ir); gateOverlay.addSlice(ir.getProcessor()); java.awt.Font f = new Font("Arial", Font.BOLD, 12); BigDecimal percentage = new BigDecimal(selected); BigDecimal totalBD = new BigDecimal(total); percentage = percentage.divide(totalBD, 4, BigDecimal.ROUND_UP); BigDecimal percentageGated = new BigDecimal(gated); BigDecimal totalGatedBD = new BigDecimal(total); percentageGated = percentageGated.divide(totalGatedBD, 4, BigDecimal.ROUND_UP); BigDecimal percentageGatedSelected = new BigDecimal(gatedSelected); BigDecimal totalGatedSelectedBD = new BigDecimal(total); percentageGatedSelected = percentageGatedSelected.divide(totalGatedSelectedBD, 4, BigDecimal.ROUND_UP); // System.out.println("PROFILING: gate fraction: " + percentage.toString()); if (impoverlay.getWidth() > 256) { TextRoi textTotal = new TextRoi(5, 10, selected + "/" + total + " gated (" + 100 * percentage.doubleValue() + "%)"); if (gated > 0) { textTotal = new TextRoi(5, 10, selected + "/" + total + " total (" + 100 * percentage.doubleValue() + "%)" + "; " + gated + "/" + total + " roi (" + 100 * percentageGated.doubleValue() + "%)" + "; " + gatedSelected + "/" + total + " overlap (" + 100 * percentageGatedSelected.doubleValue() + "%)", f); } //TextRoi textImageGated = new TextRoi(5, 18, selected + "/" + total + " gated objects (" + 100 * percentage.doubleValue() + "%)", f); textTotal.setPosition(i); //textImageGated.setPosition(i); overlay.add(textTotal); } else { f = new Font("Arial", Font.PLAIN, 10); TextRoi line1 = new TextRoi(5, 5, selected + "/" + total + " gated" + "(" + 100 * percentage.doubleValue() + "%)", f); overlay.add(line1); if (gated > 0) { f = new Font("Arial", Font.PLAIN, 10); TextRoi line2 = new TextRoi(5, 18, gated + "/" + total + " roi (" + 100 * percentageGated.doubleValue() + "%)", f); overlay.add(line2); TextRoi line3 = new TextRoi(5, 31, gatedSelected + "/" + total + " overlap (" + 100 * percentageGatedSelected.doubleValue() + "%)", f); overlay.add(line3); } line1.setPosition(i); } } impoverlay.setOverlay(overlay); //ImagePlus gateMaskImage = new ImagePlus("gates", gateOverlay); //gateMaskImage.show(); gate.setGateOverlayStack(gateOverlay); } impoverlay.draw(); impoverlay.setTitle(this.getTitle()); if (impoverlay.getDisplayMode() != IJ.COMPOSITE) { impoverlay.setDisplayMode(IJ.COMPOSITE); } if (impoverlay.getSlice() == 1) { impoverlay.setZ(Math.round(impoverlay.getNSlices() / 2)); } else { impoverlay.setSlice(impoverlay.getSlice()); } impoverlay.show(); } }
From source file:ch.algotrader.entity.security.SecurityFamilyImpl.java
@Override public double roundUp(String broker, double price) { return RoundUtil.roundToNextN(price, getTickSize(broker, price, true), BigDecimal.ROUND_UP); }
From source file:org.onebusaway.admin.util.VehicleStatusBuilder.java
private String getLastUpdate(String timeReported) { String lastUpdate;/*from w ww .j a v a2 s . c om*/ BigDecimal difference = getTimeDifference(timeReported); if (difference.abs().compareTo(new BigDecimal(86400)) > 0) { //Calculate the difference in days BigDecimal days = difference.divide(new BigDecimal(86400), BigDecimal.ROUND_HALF_UP); lastUpdate = days.toPlainString() + " days"; } else { if (difference.abs().compareTo(new BigDecimal(3600)) > 0) { //Calculate the difference in hours BigDecimal hours = difference.divide(new BigDecimal(3600), BigDecimal.ROUND_HALF_UP); lastUpdate = hours.toPlainString() + " hours"; } else { if (difference.abs().compareTo(new BigDecimal(60)) > 0) { //Calculate the difference in minutes BigDecimal minutes = difference.divide(new BigDecimal(60), BigDecimal.ROUND_UP); lastUpdate = minutes.toPlainString() + " mins"; } else { lastUpdate = difference + " sec"; } } } return lastUpdate; }
From source file:de.otto.mongodb.profiler.web.OpProfileController.java
@RequestMapping(value = "/{id:.+}/chart-data/moved-documents", method = RequestMethod.GET, produces = { JSON_TYPE_1, JSON_TYPE_2 })/*w w w. ja v a 2 s . c o m*/ public HttpEntity<String> getMovedDocumentChartData(@PathVariable("connectionId") final String connectionId, @PathVariable("databaseName") final String databaseName, @PathVariable("id") final String id, @RequestParam(value = "sampleRate", required = false) Long sampleRate) throws ResourceNotFoundException { final ProfiledDatabase database = requireDatabase(connectionId, databaseName); final OpProfile profile = requireProfile(database, id); if (!(profile instanceof UpdateProfile)) { throw new ResourceNotFoundException("No update profile found!"); } if (sampleRate == null) { sampleRate = 15L; } final DocumentMoveMeasure measure = ((UpdateProfile) profile).getMoveMeasure(); final ChronoSampler<DocumentMoveMeasure.Mark, MovedDocumentsSample> sampler = new ChronoSampler<>( sampleRate, TimeUnit.MINUTES, MOVED_DOCUMENTS_REDUCTION, lowerBoundary(-24)); for (DocumentMoveMeasure.Mark mark : measure.getMarks()) { sampler.add(mark.time, mark); } final List<MovedDocumentsSample> samples = sampler.finish(); final JsonArray ratioValues = new JsonArray(); final JsonArray totalValues = new JsonArray(); final JsonArray movedValues = new JsonArray(); for (MovedDocumentsSample sample : samples) { final JsonArray ratioValue = new JsonArray(); ratioValue.add(new JsonPrimitive(Long.valueOf(sample.time))); ratioValue.add(new JsonPrimitive( Integer.valueOf(sample.ratio.movePointRight(2).setScale(0, BigDecimal.ROUND_UP).intValue()))); ratioValues.add(ratioValue); final JsonArray totalValue = new JsonArray(); totalValue.add(new JsonPrimitive(Long.valueOf(sample.time))); totalValue.add(new JsonPrimitive(Long.valueOf(sample.normal + sample.moved))); totalValues.add(totalValue); final JsonArray movedValue = new JsonArray(); movedValue.add(new JsonPrimitive(Long.valueOf(sample.time))); movedValue.add(new JsonPrimitive(Long.valueOf(sample.moved))); movedValues.add(movedValue); } final JsonObject ratioJson = new JsonObject(); ratioJson.add("key", new JsonPrimitive("Ratio")); ratioJson.add("values", ratioValues); final JsonObject totalJson = new JsonObject(); totalJson.add("key", new JsonPrimitive("Total")); totalJson.add("values", totalValues); final JsonObject movedJson = new JsonObject(); movedJson.add("key", new JsonPrimitive("Moved")); movedJson.add("values", movedValues); final JsonObject json = new JsonObject(); json.add("ratio", ratioJson); json.add("total", totalJson); json.add("moved", movedJson); return new HttpEntity<>(json.toString()); }
From source file:no.abmu.questionnaire.domain.data.BigDecimalFieldData.java
@Transient private BigDecimal bigDecimalWithCorrectScaling(BigDecimal bigDecimal) { if (bigDecimal == null) { return null; }// w w w . j ava 2s .co m return bigDecimal.setScale(bigDecimalScale, BigDecimal.ROUND_UP); }
From source file:org.netxilia.functions.MathFunctions.java
public double ROUNDUP(double number, int count) { return MathUtils.round(number, count, BigDecimal.ROUND_UP); }