List of usage examples for java.math BigDecimal ROUND_HALF_UP
int ROUND_HALF_UP
To view the source code for java.math BigDecimal ROUND_HALF_UP.
Click Source Link
From source file:com.qcadoo.mes.technologies.controller.TechnologyMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long technologyId = Long.parseLong(request.getParameter("techId")); Entity technology = dataDefinitionService .get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY) .get(technologyId);/*from w w w . ja v a2 s. c om*/ DataDefinition attachmentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_ATTACHMENT); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null; while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path); atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField(TechnologyAttachmentFields.TECHNOLOGY, technology); atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(TechnologyAttachmentFields.SIZE, size); attachmentDD.save(atchment); } } }
From source file:com.qcadoo.mes.cmmsMachineParts.controller.MachinePartMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long part = Long.parseLong(request.getParameter("partId")); Entity technology = dataDefinitionService .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(part); DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "machinePartAttachment"); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null;/*from ww w . j a va 2 s .com*/ while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path); atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField("product", technology); atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(TechnologyAttachmentFields.SIZE, size); atchment = attachmentDD.save(atchment); atchment.isValid(); } } }
From source file:com.qcadoo.mes.basic.controllers.WorkstationMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long workstationId = Long.parseLong(request.getParameter("techId")); Entity workstation = dataDefinitionService .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION).get(workstationId); DataDefinition attachmentDD = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_WORKSTATION_ATTACHMENT); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null;/*from w w w . j a va 2 s . c om*/ while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(WorkstationAttachmentFields.ATTACHMENT, path); atchment.setField(WorkstationAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField(WorkstationAttachmentFields.WORKSTATION, workstation); atchment.setField(WorkstationAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(WorkstationAttachmentFields.SIZE, size); attachmentDD.save(atchment); } } }
From source file:com.qcadoo.mes.cmmsMachineParts.controller.MaintenanceEventMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFilesForEvent", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long eventId = Long.parseLong(request.getParameter("eventId")); Entity event = dataDefinitionService .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT) .get(eventId);// w w w.j ava 2s . c o m DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "eventAttachment"); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null; while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path); atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField("maintenanceEvent", event); atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(TechnologyAttachmentFields.SIZE, size); atchment = attachmentDD.save(atchment); atchment.isValid(); } } }
From source file:org.guili.ecshop.controller.payment.PaymentAlipayAdaptor.java
public Map<String, String> beginPayment(SalesOrder so, Model model, HttpServletRequest request, HttpServletResponse response) {/*from ww w.jav a2 s . c om*/ Map<String, String> paymentData = new LinkedHashMap<String, String>(); Map<String, String> params = new HashMap<String, String>(); params.put(POST_SERVICE, SERVER); params.put(POST_PARTNER, PARTNER); params.put(POST_SUBJECT, SUBJECT); params.put(POST_BODY, BODY); params.put(POST_OUT_TRADE_NO, so.getCode()); params.put(POST_TOTAL_FEE, so.getTotalforOrder().setScale(2, BigDecimal.ROUND_HALF_UP).toString()); params.put(POST_PAYMENT_TYPE, PAYMENT_TYPE); params.put(POST_PAYMETHOD, PAYMENT_METHOD); params.put(POST_SELLER_EMAIL, SELLER_EMAIL); params.put(POST_RETURN_URL, getReturnUrl(so.getCode(), request)); params.put(POST_NOTIFY_URL, getFeedbackUrlByPaymentType(so.getPaymentType(), request)); params.put(POST_CHARSET, INPUT_CHARSET); // params.put("antiphishing", "0"); // ??? String strToken = (String) request.getSession().getAttribute("aliPayToken"); if (strToken != null && strToken.length() > 0) { params.put(POST_TOKEN, strToken); paymentData.put(POST_TOKEN, strToken); } //? String encrypt_key = this.getAlipayTimestamp(); String exter_invoke_ip = this.getIpAddr(request); params.put(ANTI_PHISHING_KEY, encrypt_key); params.put(EXTER_INVOKE_IP, exter_invoke_ip); String signStr = getContent(params, key); logger.info("signStr:" + signStr); String sign = Md5Encrypt.md5(getContent(params, key), INPUT_CHARSET); logger.info("sign:" + sign); paymentData.put(POST_SIGN, sign); paymentData.put(POST_SIGN_TYPE, "MD5"); paymentData.put(POST_SERVICE, SERVER); paymentData.put(POST_PARTNER, PARTNER); paymentData.put(POST_SUBJECT, SUBJECT); paymentData.put(POST_BODY, BODY); paymentData.put(POST_OUT_TRADE_NO, so.getCode()); paymentData.put(POST_TOTAL_FEE, so.getTotalforOrder().setScale(2, BigDecimal.ROUND_HALF_UP).toString()); paymentData.put(POST_PAYMENT_TYPE, PAYMENT_TYPE); paymentData.put(POST_PAYMETHOD, PAYMENT_METHOD); paymentData.put(POST_SELLER_EMAIL, SELLER_EMAIL); paymentData.put(POST_RETURN_URL, getReturnUrl(so.getCode(), request)); paymentData.put(POST_NOTIFY_URL, getFeedbackUrlByPaymentType(so.getPaymentType(), request)); paymentData.put(POST_CHARSET, INPUT_CHARSET); paymentData.put("postUrl", POST_URL); paymentData.put(ANTI_PHISHING_KEY, encrypt_key); paymentData.put(EXTER_INVOKE_IP, exter_invoke_ip); model.addAttribute("postItem", paymentData); model.addAttribute("postUrl", POST_URL); model.addAttribute("postMethod", "get"); return paymentData; }
From source file:org.kalypso.model.wspm.tuhh.core.profile.TUHHInterpolationHandler.java
private Object createValue(final Object template, final double value) { if (template.getClass() == Double.class) return Double.valueOf(value); if (template.getClass() == BigDecimal.class) return BigDecimal.valueOf(value).setScale(((BigDecimal) template).scale(), BigDecimal.ROUND_HALF_UP); if (template.getClass() == Integer.class) return Integer.valueOf((int) Math.round(value)); return template; }
From source file:com.siapa.managedbean.DetalleCompraAlimentoManagedBean.java
public BigDecimal calcularTotal() { BigDecimal total1 = BigDecimal.ZERO; BigDecimal imp = BigDecimal.ZERO; if (detalleCompraAlimento != null && detalleCompraAlimento.getCantDetalleCompraAlimento() != null) { if (detalleCompraAlimento.getPrecioDetalleCompraAlimento() != null) { if (detalleCompraAlimento.getImpuestoDetCompraAlimento() != null) { total1 = total1.add((detalleCompraAlimento.getCantDetalleCompraAlimento() .multiply(detalleCompraAlimento.getPrecioDetalleCompraAlimento())) .multiply(detalleCompraAlimento.getImpuestoDetCompraAlimento() .divide(new BigDecimal(100)).add(new BigDecimal(1))) .setScale(2, BigDecimal.ROUND_HALF_UP)); }/*from www . jav a 2s .co m*/ } } return total1; }
From source file:com.sun.cb.CoffeeBreakBean.java
public void updateCart() { BigDecimal total = new BigDecimal("0.00"); BigDecimal price = new BigDecimal("0.00"); for (Iterator i = cart.getItems().iterator(); i.hasNext();) { ShoppingCartItem sci = (ShoppingCartItem) i.next(); RetailPriceItem item = sci.getItem(); BigDecimal pounds = sci.getPounds(); if (pounds != null) { price = item.getRetailPricePerPound().multiply(pounds).setScale(2, BigDecimal.ROUND_HALF_UP); } else {// w ww . j av a 2 s . c om price = new BigDecimal("0.00"); sci.setPounds(new BigDecimal("0.0")); } sci.setPrice(price); total = total.add(sci.getPrice()).setScale(2); cart.setTotal(total); } }
From source file:com.qcadoo.mes.basic.controllers.SubassemblyMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFilesForSubassembly", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long subassemblyId = Long.parseLong(request.getParameter("techId")); Entity subassembly = dataDefinitionService .get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBASSEMBLY).get(subassemblyId); DataDefinition attachmentDD = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBASSEMBLY_ATTACHMENT); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null;//w ww. j av a2s .c o m while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(SubassemblyAttachmentFields.ATTACHMENT, path); atchment.setField(SubassemblyAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField(SubassemblyAttachmentFields.SUBASSEMBLY, subassembly); atchment.setField(SubassemblyAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(SubassemblyAttachmentFields.SIZE, size); attachmentDD.save(atchment); } } }
From source file:com.qcadoo.mes.cmmsMachineParts.controller.PlannedEventMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFilesForPlannedEvent", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long eventId = Long.parseLong(request.getParameter("eventId")); Entity event = dataDefinitionService .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT) .get(eventId);/*from ww w. j av a 2s . c o m*/ DataDefinition attachmentDD = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT_ATTACHMENT); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null; while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(PlannedEventAttachmentFields.ATTACHMENT, path); atchment.setField(PlannedEventAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField(PlannedEventAttachmentFields.PLANNED_EVENT, event); atchment.setField(PlannedEventAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(PlannedEventAttachmentFields.SIZE, size); atchment = attachmentDD.save(atchment); atchment.isValid(); } } }