List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java
/** * Returns the UP rounded value of the given value for the given steps. * * @param value The original value to be rounded. * @param steps The steps./*from ww w. j a v a2 s . c o m*/ * @return The UP rounded value of the given value for the given steps. */ public static BigDecimal roundUpTo(double value, double steps) { final BigDecimal bValue = BigDecimal.valueOf(value); final BigDecimal bSteps = BigDecimal.valueOf(steps); if (Objects.equals(bSteps, BigDecimal.ZERO)) { return bValue; } else { return bValue.divide(bSteps, 0, RoundingMode.CEILING).multiply(bSteps); } }
From source file:org.openmrs.module.pharmacyapi.api.prescription.util.PrescriptionUtils.java
public Double calculateDrugQuantity(final DrugOrder drugOrder) { final int durationUnitsDays = MappedDurationUnits.getDurationDays(drugOrder.getDurationUnits().getUuid()); double quantity = drugOrder.getDose() * drugOrder.getDuration() * durationUnitsDays * drugOrder.getFrequency().getFrequencyPerDay(); return BigDecimal.valueOf(quantity).setScale(0, RoundingMode.CEILING).doubleValue(); }
From source file:com.globocom.grou.report.ts.opentsdb.OpenTSDBClient.java
private double formatValue(double value) { try {/*from ww w . j a v a2s .c o m*/ return BigDecimal.valueOf(value).round(new MathContext(4, RoundingMode.HALF_UP)).doubleValue(); } catch (NumberFormatException ignore) { return BigDecimal.valueOf(0d).round(new MathContext(4, RoundingMode.HALF_UP)).doubleValue(); } }
From source file:com.wirecard.ezlinkwebservices.services.impl.TranxHistoryServiceImpl.java
@Override public EZLINGWSTRANXRESBODY getTranxHistory(EZLINGWSTRANXREQENV parameters) throws TranxHistoryFault_Exception { ezlink.info("Tranx History Request received in " + TranxHistoryServiceImpl.class.getName()); EZLINGWSTRANXRESBODY objEZLINGWSTRANXRESBODY = new EZLINGWSTRANXRESBODY(); TranxHistoryResError objTranxHistoryResError = new TranxHistoryResError(); String cardNo;// w ww . j av a2 s .c o m int requiredNoOfTranx; int counter = 0; List<ETranxLogDto> objETranxLogDtoList; List<ETerminalDataDto> objETerminalDataDtoList; TranxList objTranxList = new TranxList(); try { cardNo = parameters.getEZLINGWSTRANXREQBODY().getTranxHistoryReq().getCARDNO(); requiredNoOfTranx = parameters.getEZLINGWSTRANXREQBODY().getTranxHistoryReq().getREQUIREDNOOFREC() .intValue(); // log the response send time and parameters ezlink.info("\n-------Tranx HIstory----REQUEST----------------------------------------------"); ezlink.info("SOURCE ID : " + parameters.getEZLINGWSTRANXREQHEADER().getSOURCEID()); ezlink.info("IP : " + parameters.getEZLINGWSTRANXREQHEADER().getIPADDRESS()); ezlink.info("SEC LEVEL : " + parameters.getEZLINGWSTRANXREQHEADER().getSECURITYLEVEL()); ezlink.info("CAN : " + cardNo); ezlink.info("REQ NO OF TRANX : " + requiredNoOfTranx); ezlink.info("\n-------Tranx HIstory----REQUEST----------------------------------------------"); } catch (Exception e) { TranxHistoryFault objTranxHistoryFault = new TranxHistoryFault(); objTranxHistoryFault.setMessage(StringConstants.Common.REQUIRED_FIELD_MISSING); objTranxHistoryFault.setFaultInfo(StringConstants.Common.REQUIRED_FIELD_MISSING_INFO); ezlink.info("\n-----TH------EXCEPTION------------------------"); ezlink.info("Response sent from getTranxHistory : " + new Date()); ezlink.info("Status : " + objTranxHistoryFault.getMessage()); ezlink.info("Remarks : " + objTranxHistoryFault.getFaultInfo()); ezlink.info("\n------TH---------EXCEPTION--------------------"); throw new TranxHistoryFault_Exception(objTranxHistoryFault.getMessage(), objTranxHistoryFault); } //Get list of tranx ID s for CAn try { SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); objETerminalDataDtoList = objETerminalDataDtoMapper.getTranxLogIdByCan(cardNo); System.out.println("++++++++++++++++TRANX LOG ID SIZE+++++++++++++++++++++++++++++" + objETerminalDataDtoList.size()); if (null == objETerminalDataDtoList || objETerminalDataDtoList.isEmpty()) { objEZLINGWSTRANXRESBODY.setTranxList(null); objTranxHistoryResError.setDCERRORCODE(StringConstants.Common.NO_TRANSCATION_AVAILABLE); objTranxHistoryResError.setDCERRORDESC(StringConstants.Common.NO_TRANSCATION_AVAILABLE_INFO); objEZLINGWSTRANXRESBODY.setTranxHistoryResError(objTranxHistoryResError); ezlink.info("\n-------Tranx HIstory----RESPONSE SENT----------------- : CAN : " + cardNo); return objEZLINGWSTRANXRESBODY; } } catch (Exception ex) { ex.printStackTrace(); ezlink.error(new Object(), ex); TranxHistoryFault objTranxHistoryFault = new TranxHistoryFault(); objTranxHistoryFault.setMessage(StringConstants.Common.CONNECTION_ISSUE_MESSAGE); objTranxHistoryFault.setFaultInfo(StringConstants.Common.CONNECTION_ISSUE_MESSAGE_INFO); ezlink.info("\n------TH-------EXCEPTION----------------------"); ezlink.info("Response sent from getTranxHistory : " + new Date()); ezlink.info("Status : " + objTranxHistoryFault.getMessage()); ezlink.info("Remarks : " + objTranxHistoryFault.getFaultInfo()); ezlink.info("\n-------TH---------EXCEPTION-------------------"); throw new TranxHistoryFault_Exception(objTranxHistoryFault.getMessage(), objTranxHistoryFault); } //Get list of tranxlogs by tranxlogId try { SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); //System.out.println("++++++++++++++++TRANX LOG ID SIZE+++++++++++++2nd++++++++++++++++"+objETerminalDataDtoList.size()); objETranxLogDtoList = objETranxLogDtoMapper.getTranxByTranxLogId(objETerminalDataDtoList); System.out.println( "++++++++++++++++TRANXLOG SIZE+++++++++++++++++++++++++++++" + objETranxLogDtoList.size()); if (null == objETranxLogDtoList || objETranxLogDtoList.isEmpty()) { objEZLINGWSTRANXRESBODY.setTranxList(null); objTranxHistoryResError.setDCERRORCODE(StringConstants.Common.NO_TRANSCATION_AVAILABLE); objTranxHistoryResError.setDCERRORDESC(StringConstants.Common.NO_TRANSCATION_AVAILABLE_INFO); objEZLINGWSTRANXRESBODY.setTranxHistoryResError(objTranxHistoryResError); ezlink.info("\n-------Tranx HIstory----RESPONSE SENT----------------- : CAN : " + cardNo); return objEZLINGWSTRANXRESBODY; } } catch (Exception ex) { ex.printStackTrace(); ezlink.error(new Object(), ex); TranxHistoryFault objTranxHistoryFault = new TranxHistoryFault(); objTranxHistoryFault.setMessage(StringConstants.Common.CONNECTION_ISSUE_MESSAGE); objTranxHistoryFault.setFaultInfo(StringConstants.Common.CONNECTION_ISSUE_MESSAGE_INFO); ezlink.info("\n------TH-------EXCEPTION----------------------"); ezlink.info("Response sent from getTranxHistory : " + new Date()); ezlink.info("Status : " + objTranxHistoryFault.getMessage()); ezlink.info("Remarks : " + objTranxHistoryFault.getFaultInfo()); ezlink.info("\n-------TH---------EXCEPTION-------------------"); throw new TranxHistoryFault_Exception(objTranxHistoryFault.getMessage(), objTranxHistoryFault); } for (int i = 0; i < objETranxLogDtoList.size(); i++) { TranxHistoryDetail objTranxHistoryDetail = new TranxHistoryDetail(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); objTranxHistoryDetail.setTRANXDATE(df.format(objETranxLogDtoList.get(i).getDatetime())); try { // SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); String merNo = objETranxLogDtoList.get(i).getMerchantNo(); SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this); MerchantDto objMerchantDto = objMerchantDtoMapper.getMerchantNameByMerchantId(merNo); if (null == objMerchantDto) { ezlink.info("\n-------TH--getMerchantName-------EXCEPTION-------------------"); ezlink.info("Merchant name not available so assigning merchant number : "); ezlink.info("\n-------TH-----getMerchantName----EXCEPTION-------------------"); objTranxHistoryDetail.setMERCHANTNAME(objETranxLogDtoList.get(i).getMerchantNo()); } else { objTranxHistoryDetail.setMERCHANTNAME(objMerchantDto.getMerchantName()); //objTranxHistoryDetail.setMERCHANTNAME(objMerchantDtoMapper.getMerchantNameByMerchantId(objETranxLogDtoList.get(i).getMerchantNo()).getMerchantName()); } } catch (Exception ex) { ex.printStackTrace(); ezlink.error(new Object(), ex); TranxHistoryFault objTranxHistoryFault = new TranxHistoryFault(); objTranxHistoryFault.setMessage(StringConstants.Common.CONNECTION_ISSUE_MESSAGE); objTranxHistoryFault.setFaultInfo(StringConstants.Common.CONNECTION_ISSUE_MESSAGE_INFO); ezlink.info("\n------TH-------EXCEPTION----------------------"); ezlink.info("Response sent from getTranxHistory : " + new Date()); ezlink.info("Status : " + objTranxHistoryFault.getMessage()); ezlink.info("Remarks : " + objTranxHistoryFault.getFaultInfo()); ezlink.info("\n-------TH---------EXCEPTION-------------------"); throw new TranxHistoryFault_Exception(objTranxHistoryFault.getMessage(), objTranxHistoryFault); } objTranxHistoryDetail.setAMOUNT(BigDecimal.valueOf(objETranxLogDtoList.get(i).getAmount())); objTranxHistoryDetail.setSTATUS(objETranxLogDtoList.get(i).getTranxStatus()); objTranxList.getTranxHistoryDetail().add(objTranxHistoryDetail); counter++; //System.out.println("counter at : "+counter); if (counter == requiredNoOfTranx) { System.out.println("REQUIRED SIZE : " + requiredNoOfTranx); System.out.println("BREAKING AT : " + counter); System.out.println("ACTUAL SIZE : " + objETranxLogDtoList.size()); ezlink.info("\n-------TH--DETAIL--------------------------"); ezlink.info("REQUIRED SIZE : " + requiredNoOfTranx); ezlink.info("BREAKING AT : " + counter); ezlink.info("ACTUAL SIZE : " + objETranxLogDtoList.size()); ezlink.info("\n-------TH-----DETAIL-----------------------"); break; } } objEZLINGWSTRANXRESBODY.setTranxList(objTranxList); objTranxHistoryResError.setDCERRORCODE(StringConstants.ResponseCode.SUCCESS); objTranxHistoryResError.setDCERRORDESC(StringConstants.ResponseCode.SUCCESS); objEZLINGWSTRANXRESBODY.setTranxHistoryResError(objTranxHistoryResError); ezlink.info("\n-------Tranx HIstory----RESPONSE SENT----------------- : CAN : " + cardNo); return objEZLINGWSTRANXRESBODY; }
From source file:com.opengamma.examples.simulated.loader.ExampleEquityPortfolioLoader.java
/** * Create a position of a random number of shares. * <p>/*from ww w . j a v a2 s .c o m*/ * This creates the position using a random number of units and create one or two trades making up the position. * * @param security the security to add a position for, not null * @return the position, not null */ protected ManageablePosition createPositionAndTrade(EquitySecurity security) { s_logger.debug("Creating position {}", security); int shares = (RandomUtils.nextInt(490) + 10) * 10; ExternalIdBundle bundle = security.getExternalIdBundle(); // we could add an identifier pointing back to the original source database if we're doing an ETL. ManageablePosition position = new ManageablePosition(BigDecimal.valueOf(shares), bundle); // create random trades that add up in shares to the position they're under (this is not enforced by the system) if (shares <= 2000) { ManageableTrade trade = new ManageableTrade(BigDecimal.valueOf(shares), bundle, _tradeDate3, null, ExternalId.of("CPARTY", "BACS")); position.addTrade(trade); } else { ManageableTrade trade1 = new ManageableTrade(BigDecimal.valueOf(2000), bundle, _tradeDate1, null, ExternalId.of("CPARTY", "BACS")); position.addTrade(trade1); ManageableTrade trade2 = new ManageableTrade(BigDecimal.valueOf(shares - 2000), bundle, _tradeDate2, null, ExternalId.of("CPARTY", "BACS")); position.addTrade(trade2); } return position; }
From source file:ca.uhn.fhir.rest.param.QuantityParam.java
public QuantityParam setValue(double theValue) { // Use the valueOf here because the constructor gives crazy precision // changes due to the floating point conversion myValue = BigDecimal.valueOf(theValue); return this; }
From source file:io.samsungsami.example.samiiotsimplecontroller.SAMISession.java
private void sendActionInDeviceChannelWS(String actionName) { ActionIn actionIn = new ActionIn(); ActionDetails action = new ActionDetails(); ArrayList<ActionDetails> actions = new ArrayList<>(); ActionDetailsArray actionDetailsArray = new ActionDetailsArray(); action.setName(actionName);/* w w w. ja va2 s. c o m*/ actions.add(action); actionDetailsArray.setActions(actions); actionIn.setData(actionDetailsArray); actionIn.setCid(actionName); actionIn.setDdid(DEVICE_ID); actionIn.setTs(BigDecimal.valueOf(System.currentTimeMillis())); try { mWS.sendAction(actionIn); Log.d(TAG, "DeviceChannelWebSocket sendAction:" + actionIn.toString()); } catch (JsonProcessingException e) { e.printStackTrace(); } }
From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java
@Override public Recharge getQuickRecharge(String amount) throws LoginException { float am = Float.parseFloat(amount); if (am < 100.0) { throw new LoginException("?100"); }//from w w w. j a v a2 s. c om Recharge recharge = new Recharge(); recharge.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_RECHARGE)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); recharge.setAmount(amount); recharge.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/recharge/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) recharge.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/recharge/response" + "/bg"); else recharge.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); recharge.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); recharge.setRechargeType("2"); //RechargeType==2?? recharge.setFeeType("2"); //??FeeType==2??3.5 Integer cashStreamId = null; if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; recharge.setRechargeMoneymoremore(lender.getThirdPartyAccount()); cashStreamId = accountService.rechargeLenderAccount(lender.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; recharge.setRechargeMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.rechargeBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else { throw new RuntimeException("??"); } recharge.setOrderNo(String.valueOf(cashStreamId)); recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); return recharge; }
From source file:herudi.controller.productController.java
@FXML private void aksiSave(ActionEvent event) { if (txtId.getText().isEmpty()) { config2.dialog(Alert.AlertType.ERROR, "ID Not Empty"); txtId.requestFocus();//from w w w .ja va2 s. c o m } else if (cbManufacturer.getValue().equals("")) { config2.dialog(Alert.AlertType.ERROR, "Manufacturer ID Not Empty"); cbManufacturer.requestFocus(); } else if (cbProductCode.getValue().equals("")) { config2.dialog(Alert.AlertType.ERROR, "Product Code Not Empty"); cbProductCode.requestFocus(); } else if (txtPurchaseCode.getText().isEmpty()) { config2.dialog(Alert.AlertType.ERROR, "Purchase Cost Not Empty"); txtPurchaseCode.requestFocus(); } else if (txtQuantityCode.getText().isEmpty()) { config2.dialog(Alert.AlertType.ERROR, "Quantity On Hand Not Empty"); txtQuantityCode.requestFocus(); } else if (txtMarkup.getText().isEmpty()) { config2.dialog(Alert.AlertType.ERROR, "Markup Not Empty"); txtMarkup.requestFocus(); } else if (available.isEmpty()) { config2.dialog(Alert.AlertType.ERROR, "Available Not Empty"); } else if (txtDescription.getText().isEmpty()) { config2.dialog(Alert.AlertType.ERROR, "Description Not Empty"); txtDescription.requestFocus(); } else { Product p = new Product(); p.setAvailable(available); p.setDescription(txtDescription.getText()); p.setManufacturerId(Integer.valueOf(cbManufacturer.getValue().toString())); p.setMarkup(BigDecimal.valueOf(Double.valueOf(txtMarkup.getText()))); p.setProductCode(cbProductCode.getValue().toString()); p.setProductId(Integer.valueOf(txtId.getText())); p.setPurchaseCost(BigDecimal.valueOf(Double.valueOf(txtPurchaseCode.getText()))); p.setQuantityOnHand(Integer.valueOf(txtQuantityCode.getText())); crud.saveOrUpdate(p); clear(); auto(); config2.dialog(Alert.AlertType.INFORMATION, "Success Save Data.."); } }
From source file:ca.uhn.fhir.rest.param.QuantityParam.java
public QuantityParam setValue(long theValue) { // Use the valueOf here because the constructor gives crazy precision // changes due to the floating point conversion myValue = BigDecimal.valueOf(theValue); return this; }