List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:org.chiba.xml.xforms.ui.Range.java
/** * Initializes this range./*from w w w . j a v a2 s.co m*/ * * @throws XFormsException if the datatype of the bound is not supported. */ protected final void initializeRange() throws XFormsException { if (!isBound()) { return; } // get model item datatype Validator validator = this.model.getValidator(); String datatype = getDatatype(); if (validator.isRestricted("decimal", datatype) || validator.isRestricted("float", datatype) || validator.isRestricted("double", datatype)) { // get bound value String value = getInstanceValue(); BigDecimal valueDecimal; if (value != null && value.length() > 0) { valueDecimal = new BigDecimal(value); } else { // set '0.0' as default value valueDecimal = new BigDecimal(0d); } // get step size BigDecimal stepDecimal; String stepAttribute = getXFormsAttribute(STEP_ATTRIBUTE); if (stepAttribute != null) { stepDecimal = new BigDecimal(stepAttribute); } else { // set '1.0' as default step stepDecimal = new BigDecimal(1d); this.element.setAttributeNS(null, STEP_ATTRIBUTE, stepDecimal.toString()); } // get range start BigDecimal startDecimal; String startAttribute = getXFormsAttribute(START_ATTRIBUTE); if (startAttribute != null) { startDecimal = new BigDecimal(startAttribute); } else { // set 'value - (2 * step)' as default start startDecimal = valueDecimal.subtract(stepDecimal.multiply(new BigDecimal(2d))); this.element.setAttributeNS(null, START_ATTRIBUTE, startDecimal.toString()); } // get range end BigDecimal endDecimal; String endAttribute = getXFormsAttribute(END_ATTRIBUTE); if (endAttribute != null) { endDecimal = new BigDecimal(endAttribute); } else { // set 'value + (2 * step)' as default end endDecimal = valueDecimal.add(stepDecimal.multiply(new BigDecimal(2d))); this.element.setAttributeNS(null, END_ATTRIBUTE, endDecimal.toString()); } if (valueDecimal.compareTo(startDecimal) < 0 || valueDecimal.compareTo(endDecimal) > 0) { this.model.getContainer().dispatch(this.target, XFormsEventNames.OUT_OF_RANGE, null); } return; } throw new XFormsBindingException("datatype not supported by range control", this.target, datatype); }
From source file:org.mobicents.servlet.restcomm.http.converter.AbstractConverter.java
protected void writePrice(final BigDecimal price, final JsonObject object) { object.addProperty("price", price.toString()); }
From source file:org.apache.pig.builtin.Utf8StorageConverter.java
@Override public byte[] toBytes(BigDecimal bd) throws IOException { return bd.toString().getBytes(); }
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertDecimalTypes(Object val, String javaColType) { HiveDecimal hd = (HiveDecimal) val; BigDecimal bd = hd.bigDecimalValue(); if (javaColType.equals(BIG_DECIMAL_TYPE)) { return bd; } else if (javaColType.equals(STRING_TYPE)) { String bdStr = null;/*from w w w . java 2s . co m*/ if (bigDecimalFormatString) { bdStr = bd.toPlainString(); } else { bdStr = bd.toString(); } return bdStr; } return null; }
From source file:com.panet.imeta.trans.steps.pgbulkloader.PGBulkLoader.java
private void writeRowToPostgres(RowMetaInterface rowMeta, Object[] r) throws KettleException { try {// w ww. jav a 2 s.co m // So, we have this output stream to which we can write CSV data to. // Basically, what we need to do is write the binary data (from strings to it as part of this proof of concept) // // Let's assume the data is in the correct format here too. // for (int i = 0; i < data.keynrs.length; i++) { if (i > 0) { // Write a separator // data.pgOutputStream.write(data.separator); } int index = data.keynrs[i]; ValueMetaInterface valueMeta = rowMeta.getValueMeta(index); Object valueData = r[index]; if (valueData != null) { switch (valueMeta.getType()) { case ValueMetaInterface.TYPE_STRING: data.pgOutputStream.write(data.quote); if (valueMeta.isStorageBinaryString()) { // lazy conversion. For this test, just dump the data to the output stream. // data.pgOutputStream.write((byte[]) valueData); } else { data.pgOutputStream.write(valueMeta.getString(valueData).getBytes()); } data.pgOutputStream.write(data.quote); break; case ValueMetaInterface.TYPE_INTEGER: if (valueMeta.isStorageBinaryString()) { data.pgOutputStream.write((byte[]) valueData); } else { data.pgOutputStream.write(Long.toString(valueMeta.getInteger(valueData)).getBytes()); } break; case ValueMetaInterface.TYPE_DATE: // Format the date in the right format. // switch (data.dateFormatChoices[i]) { // Pass the data along in the format chosen by the user OR in binary format... // case PGBulkLoaderMeta.NR_DATE_MASK_PASS_THROUGH: { if (valueMeta.isStorageBinaryString()) { data.pgOutputStream.write((byte[]) valueData); } else { String dateString = valueMeta.getString(valueData); if (dateString != null) { data.pgOutputStream.write(dateString.getBytes()); } } } break; // Convert to a "YYYY/MM/DD" format // case PGBulkLoaderMeta.NR_DATE_MASK_DATE: { String dateString = data.dateMeta.getString(valueMeta.getDate(valueData)); if (dateString != null) { data.pgOutputStream.write(dateString.getBytes()); } } break; // Convert to a "YYYY/MM/DD HH:MM:SS" (ISO) format // case PGBulkLoaderMeta.NR_DATE_MASK_DATETIME: { String dateTimeString = data.dateTimeMeta.getString(valueMeta.getDate(valueData)); if (dateTimeString != null) { data.pgOutputStream.write(dateTimeString.getBytes()); } } break; } break; case ValueMetaInterface.TYPE_BOOLEAN: if (valueMeta.isStorageBinaryString()) { data.pgOutputStream.write((byte[]) valueData); } else { data.pgOutputStream.write(Double.toString(valueMeta.getNumber(valueData)).getBytes()); } break; case ValueMetaInterface.TYPE_NUMBER: if (valueMeta.isStorageBinaryString()) { data.pgOutputStream.write((byte[]) valueData); } else { data.pgOutputStream.write(Double.toString(valueMeta.getNumber(valueData)).getBytes()); } break; case ValueMetaInterface.TYPE_BIGNUMBER: if (valueMeta.isStorageBinaryString()) { data.pgOutputStream.write((byte[]) valueData); } else { BigDecimal big = valueMeta.getBigNumber(valueData); if (big != null) { data.pgOutputStream.write(big.toString().getBytes()); } } break; } } } // Now write a newline // data.pgOutputStream.write(data.newline); } catch (Exception e) { throw new KettleException("Error serializing rows of data to the psql command", e); } }
From source file:org.egov.ptis.actions.citizen.search.SearchAction.java
private List<Map<String, String>> getResultFromDemandDetails(final BasicProperty basicProperty) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entered into getSearchResults method"); LOGGER.debug("Assessment Number : " + basicProperty.getUpicNo()); }/* w w w .j a va 2 s .c o m*/ final Property property = basicProperty.getProperty(); final Map<String, BigDecimal> demandCollMap = ptDemandDAO .getDemandCollMapIncludingPenaltyAndAdvance(property); final Map<String, String> searchResultMap = new HashMap<>(); searchResultMap.put("assessmentNum", basicProperty.getUpicNo()); searchResultMap.put("ownerName", basicProperty.getFullOwnerName()); searchResultMap.put("address", basicProperty.getAddress().toString()); searchResultMap.put("source", basicProperty.getSource().toString()); searchResultMap.put("isDemandActive", String.valueOf(isDemandActive)); searchResultMap.put("propType", property.getPropertyDetail().getPropertyTypeMaster().getCode()); searchResultMap.put("isTaxExempted", String.valueOf(property.getIsExemptedFromTax())); searchResultMap.put("isUnderWorkflow", String.valueOf(basicProperty.isUnderWorkflow())); searchResultMap.put("enableVacancyRemission", String.valueOf(propertyTaxUtil.enableVacancyRemission(basicProperty.getUpicNo()))); searchResultMap.put("enableMonthlyUpdate", String.valueOf(propertyTaxUtil.enableMonthlyUpdate(basicProperty.getUpicNo()))); searchResultMap.put("enableVRApproval", String.valueOf(propertyTaxUtil.enableVRApproval(basicProperty.getUpicNo()))); if (property.getIsExemptedFromTax()) searchResultMap.putAll(getDemandDetailsForExemptedProperty()); else { searchResultMap.put(CURRENT_FIRST_HALF_DEMAND, demandCollMap.get(CURR_FIRSTHALF_DMD_STR).toString()); searchResultMap.put(CURRENT_SECOND_HALF_DEMAND, demandCollMap.get(CURR_SECONDHALF_DMD_STR).toString()); searchResultMap.put(ARREAR_DEMAND_DUE, demandCollMap.get(ARR_DMD_STR).subtract(demandCollMap.get(ARR_COLL_STR)).toString()); searchResultMap.put(CURRENT_FIRST_HALF_DEMAND_DUE, demandCollMap.get(CURR_FIRSTHALF_DMD_STR) .subtract(demandCollMap.get(CURR_FIRSTHALF_COLL_STR)).toString()); searchResultMap.put(CURRENT_SECOND_HALF_DEMAND_DUE, demandCollMap.get(CURR_SECONDHALF_DMD_STR) .subtract(demandCollMap.get(CURR_SECONDHALF_COLL_STR)).toString()); searchResultMap.put(CURRENT_FIRST_HALF_PENALTY_DUE, demandCollMap.get(CURR_FIRSTHALF_PENALTY_DMD_STR) .subtract(demandCollMap.get(CURR_FIRSTHALF_PENALTY_COLL_STR)).toString()); searchResultMap.put(CURRENT_SECOND_HALF_PENALTY_DUE, demandCollMap.get(CURR_SECONDHALF_PENALTY_DMD_STR) .subtract(demandCollMap.get(CURR_SECONDHALF_PENALTY_COLL_STR)).toString()); searchResultMap.put(ARREAR_PENALTY_DUE, demandCollMap.get(ARR_PENALTY_DMD_STR) .subtract(demandCollMap.get(ARR_PENALTY_COLL_STR)).toString()); searchResultMap.put(ADVANCE, demandCollMap.get(ADVANCE_DMD_RSN_CODE).toString()); BigDecimal rebate = calculateRebate(basicProperty); searchResultMap.put(REBATE_AMOUNT, rebate.toString()); searchResultMap.put(NET_PAYABLE_AMOUNT, calculateNetPayAmt(demandCollMap).subtract(rebate).toString()); } searchList.add(searchResultMap); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Search list : " + searchList); LOGGER.debug("Exit from getSearchResults method"); } return searchList; }
From source file:com.onesignal.TrackGooglePurchase.java
private void sendPurchases(final ArrayList<String> skusToAdd, final ArrayList<String> newPurchaseTokens) { try {//from w w w . jav a 2 s.c om if (getSkuDetailsMethod == null) { getSkuDetailsMethod = getGetSkuDetailsMethod(IInAppBillingServiceClass); getSkuDetailsMethod.setAccessible(true); } Bundle querySkus = new Bundle(); querySkus.putStringArrayList("ITEM_ID_LIST", skusToAdd); Bundle skuDetails = (Bundle) getSkuDetailsMethod.invoke(mIInAppBillingService, 3, appContext.getPackageName(), "inapp", querySkus); int response = skuDetails.getInt("RESPONSE_CODE"); if (response == 0) { ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST"); Map<String, JSONObject> currentSkus = new HashMap<String, JSONObject>(); JSONObject jsonItem; for (String thisResponse : responseList) { JSONObject object = new JSONObject(thisResponse); String sku = object.getString("productId"); BigDecimal price = new BigDecimal(object.getString("price_amount_micros")); price = price.divide(new BigDecimal(1000000)); jsonItem = new JSONObject(); jsonItem.put("sku", sku); jsonItem.put("iso", object.getString("price_currency_code")); jsonItem.put("amount", price.toString()); currentSkus.put(sku, jsonItem); } JSONArray purchasesToReport = new JSONArray(); for (String sku : skusToAdd) { if (!currentSkus.containsKey(sku)) continue; purchasesToReport.put(currentSkus.get(sku)); } // New purchases to report. // Wait until we have a userID then send purchases to server. If successful then mark them as tracked. if (purchasesToReport.length() > 0) { final JSONArray finalPurchasesToReport = purchasesToReport; OneSignal.idsAvailable(new IdsAvailableHandler() { public void idsAvailable(String userId, String registrationId) { OneSignal.sendPurchases(finalPurchasesToReport, newAsExisting, new OneSignalRestClient.ResponseHandler() { public void onFailure(int statusCode, JSONObject response, Throwable throwable) { OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "HTTP sendPurchases failed to send.", throwable); isWaitingForPurchasesRequest = false; } public void onSuccess(String response) { purchaseTokens.addAll(newPurchaseTokens); prefsEditor.putString("purchaseTokens", purchaseTokens.toString()); prefsEditor.remove("ExistingPurchases"); prefsEditor.commit(); newAsExisting = false; isWaitingForPurchasesRequest = false; } }); } }); } } } catch (Throwable t) { OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "Failed to track IAP purchases", t); } }
From source file:net.groupbuy.plugin.yeepay.YeepayController.java
/** * /* w w w . ja v a 2s . co m*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String paymentName, String partner, String key, FeeType feeType, BigDecimal fee, String logo, String description, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order, RedirectAttributes redirectAttributes) { PluginConfig pluginConfig = yeepayPlugin.getPluginConfig(); pluginConfig.setAttribute(PaymentPlugin.PAYMENT_NAME_ATTRIBUTE_NAME, paymentName); pluginConfig.setAttribute("partner", partner); pluginConfig.setAttribute("key", key); pluginConfig.setAttribute(PaymentPlugin.FEE_TYPE_ATTRIBUTE_NAME, feeType.toString()); pluginConfig.setAttribute(PaymentPlugin.FEE_ATTRIBUTE_NAME, fee.toString()); pluginConfig.setAttribute(PaymentPlugin.LOGO_ATTRIBUTE_NAME, logo); pluginConfig.setAttribute(PaymentPlugin.DESCRIPTION_ATTRIBUTE_NAME, description); pluginConfig.setIsEnabled(isEnabled); pluginConfig.setOrder(order); pluginConfigService.update(pluginConfig); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:/admin/payment_plugin/list.jhtml"; }
From source file:net.groupbuy.plugin.unionpay.UnionpayController.java
/** * /*from w w w.j av a 2 s . co m*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String paymentName, String partner, String key, FeeType feeType, BigDecimal fee, String logo, String description, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order, RedirectAttributes redirectAttributes) { PluginConfig pluginConfig = unionpayPlugin.getPluginConfig(); pluginConfig.setAttribute(PaymentPlugin.PAYMENT_NAME_ATTRIBUTE_NAME, paymentName); pluginConfig.setAttribute("partner", partner); pluginConfig.setAttribute("key", key); pluginConfig.setAttribute(PaymentPlugin.FEE_TYPE_ATTRIBUTE_NAME, feeType.toString()); pluginConfig.setAttribute(PaymentPlugin.FEE_ATTRIBUTE_NAME, fee.toString()); pluginConfig.setAttribute(PaymentPlugin.LOGO_ATTRIBUTE_NAME, logo); pluginConfig.setAttribute(PaymentPlugin.DESCRIPTION_ATTRIBUTE_NAME, description); pluginConfig.setIsEnabled(isEnabled); pluginConfig.setOrder(order); pluginConfigService.update(pluginConfig); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:/admin/payment_plugin/list.jhtml"; }
From source file:net.groupbuy.plugin.pay99bill.Pay99billController.java
/** * /* w w w . j a v a 2 s .co m*/ */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String paymentName, String partner, String key, FeeType feeType, BigDecimal fee, String logo, String description, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order, RedirectAttributes redirectAttributes) { PluginConfig pluginConfig = pay99billPlugin.getPluginConfig(); pluginConfig.setAttribute(PaymentPlugin.PAYMENT_NAME_ATTRIBUTE_NAME, paymentName); pluginConfig.setAttribute("partner", partner); pluginConfig.setAttribute("key", key); pluginConfig.setAttribute(PaymentPlugin.FEE_TYPE_ATTRIBUTE_NAME, feeType.toString()); pluginConfig.setAttribute(PaymentPlugin.FEE_ATTRIBUTE_NAME, fee.toString()); pluginConfig.setAttribute(PaymentPlugin.LOGO_ATTRIBUTE_NAME, logo); pluginConfig.setAttribute(PaymentPlugin.DESCRIPTION_ATTRIBUTE_NAME, description); pluginConfig.setIsEnabled(isEnabled); pluginConfig.setOrder(order); pluginConfigService.update(pluginConfig); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:/admin/payment_plugin/list.jhtml"; }