List of usage examples for java.math BigDecimal setScale
@Deprecated(since = "9") public BigDecimal setScale(int newScale, int roundingMode)
From source file:org.kuali.ole.select.document.OleVendorCreditMemoDocument.java
public void creditMemoCalculation(OleCreditMemoItem item) { item.setItemUnitPrice(item.getPoUnitPrice()); BigDecimal calcExtendedPrice = item.getItemUnitPrice().multiply(item.getItemQuantity().bigDecimalValue()); KualiDecimal extendedPrice = new KualiDecimal( calcExtendedPrice.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)); item.setPoTotalAmount(extendedPrice); }
From source file:org.kuali.kfs.module.purap.businessobject.PurApItemBase.java
@Override public void setItemUnitPrice(BigDecimal itemUnitPrice) { if (itemUnitPrice != null) { if (itemUnitPrice.scale() < PurapConstants.DOLLAR_AMOUNT_MIN_SCALE) { itemUnitPrice = itemUnitPrice.setScale(PurapConstants.DOLLAR_AMOUNT_MIN_SCALE, KualiDecimal.ROUND_BEHAVIOR); } else if (itemUnitPrice.scale() > PurapConstants.UNIT_PRICE_MAX_SCALE) { itemUnitPrice = itemUnitPrice.setScale(PurapConstants.UNIT_PRICE_MAX_SCALE, KualiDecimal.ROUND_BEHAVIOR); }//from ww w . j av a 2s .co m } this.itemUnitPrice = itemUnitPrice; }
From source file:org.codice.ddf.spatial.ogc.wfs.transformer.handlebars.HandlebarsWfsFeatureTransformer.java
private String convertToBytes(String value, String unit) { BigDecimal resourceSize = new BigDecimal(value); resourceSize = resourceSize.setScale(1, BigDecimal.ROUND_HALF_UP); switch (unit) { case B:/*from w w w . j av a2s. c o m*/ break; case KB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_KB)); break; case MB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_MB)); break; case GB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_GB)); break; case TB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_TB)); break; case PB: resourceSize = resourceSize.multiply(new BigDecimal(BYTES_PER_PB)); break; default: break; } String resourceSizeAsString = resourceSize.toPlainString(); LOGGER.debug("resource size in bytes: {}", resourceSizeAsString); return resourceSizeAsString; }
From source file:com.aliyun.fs.oss.nat.BufferReader.java
private void progressPrint() { long hasRead = pos + realContentSize - instreamStart; double currentProgress = hasRead >= lengthToFetch ? 1.0d : (double) hasRead / lengthToFetch; if (currentProgress - lastProgress >= 0.1 || currentProgress == 1.0d) { BigDecimal b = new BigDecimal(currentProgress); LOG.info("Current progress of reading '" + key + " [" + instreamStart + ":...]' is " + b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); lastProgress = currentProgress;//from ww w .ja va 2s . co m } }
From source file:org.apache.sling.reqanalyzer.impl.RequestAnalyzerWebConsole.java
private String formatByteSize(final long value) { final String suffix; final String suffixedValue; if (value >= 0) { final BigDecimal KB = new BigDecimal(1000L); final BigDecimal MB = new BigDecimal(1000L * 1000); final BigDecimal GB = new BigDecimal(1000L * 1000 * 1000); BigDecimal bd = new BigDecimal(value); if (bd.compareTo(GB) > 0) { bd = bd.divide(GB);//from w w w. j a va 2s . c o m suffix = "GB"; } else if (bd.compareTo(MB) > 0) { bd = bd.divide(MB); suffix = "MB"; } else if (bd.compareTo(KB) > 0) { bd = bd.divide(KB); suffix = "kB"; } else { suffix = "B"; } suffixedValue = bd.setScale(2, RoundingMode.UP).toString(); } else { suffixedValue = "n/a"; suffix = ""; } return suffixedValue + suffix; }
From source file:org.egov.ptis.web.controller.reports.BaseRegisterVLTResultAdaptor.java
@Override public JsonElement serialize(final DataTable<PropertyMVInfo> baseRegisterResponse, final Type type, final JsonSerializationContext jsc) { final List<PropertyMVInfo> baseRegisterResult = baseRegisterResponse.getData(); final JsonArray baseRegisterResultData = new JsonArray(); baseRegisterResult.forEach(baseRegisterResultObj -> { final JsonObject jsonObject = new JsonObject(); final BigDecimal taxRate = propertyTaxUtil.getTaxRates(); final Map<String, BigDecimal> valuesMap = getTaxDetails(baseRegisterResultObj); final BigDecimal marketValue = baseRegisterResultObj.getMarketValue() == null ? BigDecimal.ZERO : baseRegisterResultObj.getMarketValue(); final BigDecimal capitalValue = baseRegisterResultObj.getCapitalValue() == null ? BigDecimal.ZERO : baseRegisterResultObj.getCapitalValue(); final BigDecimal higherValueForImposedTax = marketValue.compareTo(capitalValue) > 0 ? marketValue.setScale(2, BigDecimal.ROUND_HALF_UP) : capitalValue.setScale(2, BigDecimal.ROUND_HALF_UP); BigDecimal currPenaltyFine = BigDecimal.ZERO; if (baseRegisterResultObj.getAggrCurrFirstHalfPenaly() != null) currPenaltyFine = currPenaltyFine.add(baseRegisterResultObj.getAggrCurrFirstHalfPenaly()); if (baseRegisterResultObj.getAggrCurrSecondHalfPenaly() != null) currPenaltyFine = currPenaltyFine.add(baseRegisterResultObj.getAggrCurrSecondHalfPenaly()); final BigDecimal currentColl = baseRegisterResultObj.getAggrCurrFirstHalfColl() == null ? BigDecimal.ZERO .add(baseRegisterResultObj.getAggrCurrSecondHalfColl() == null ? BigDecimal.ZERO : baseRegisterResultObj.getAggrCurrSecondHalfColl()) : baseRegisterResultObj.getAggrCurrFirstHalfColl(); final BigDecimal arrColl = baseRegisterResultObj.getAggrArrColl() != null ? baseRegisterResultObj.getAggrArrColl() : BigDecimal.ZERO; final BigDecimal totalColl = arrColl.add(currentColl); final BigDecimal currTotal = baseRegisterResultObj.getAggrCurrFirstHalfDmd() == null ? BigDecimal.ZERO.add(baseRegisterResultObj.getAggrCurrSecondHalfDmd() == null ? BigDecimal.ZERO : baseRegisterResultObj.getAggrCurrSecondHalfDmd()) : baseRegisterResultObj.getAggrCurrFirstHalfDmd(); jsonObject.addProperty("assessmentNo", baseRegisterResultObj.getPropertyId()); jsonObject.addProperty("oldAssessmentNo", StringUtils.isNotBlank(baseRegisterResultObj.getOldMuncipalNum()) ? baseRegisterResultObj.getOldMuncipalNum() : "NA"); jsonObject.addProperty("sitalArea", baseRegisterResultObj.getSitalArea().setScale(2, BigDecimal.ROUND_HALF_UP)); jsonObject.addProperty("ward", baseRegisterResultObj.getWard().getBoundaryNum()); jsonObject.addProperty("ownerName", baseRegisterResultObj.getOwnerName()); jsonObject.addProperty("surveyNo", StringUtils.isNotBlank(baseRegisterResultObj.getSurveyNo()) ? baseRegisterResultObj.getSurveyNo() : "NA"); jsonObject.addProperty("taxationRate", taxRate); jsonObject.addProperty("marketValue", marketValue.toString()); jsonObject.addProperty("documentValue", capitalValue.toString()); jsonObject.addProperty("higherValueForImposedtax", higherValueForImposedTax.toString()); jsonObject.addProperty("isExempted", baseRegisterResultObj.getIsExempted() ? "Yes" : "No"); jsonObject.addProperty("propertyTaxFirstHlf", baseRegisterResultObj.getAggrCurrFirstHalfDmd() == null ? BigDecimal.ZERO : baseRegisterResultObj.getAggrCurrFirstHalfDmd()); if (!valuesMap.isEmpty()) { jsonObject.addProperty("libraryCessTaxFirstHlf", valuesMap.get(CURR_FIRST_HALF_LIB_CESS) == null ? BigDecimal.ZERO : valuesMap.get(CURR_FIRST_HALF_LIB_CESS)); jsonObject.addProperty("libraryCessTaxSecondHlf", valuesMap.get(CURR_SECOND_HALF_LIB_CESS) == null ? BigDecimal.ZERO : valuesMap.get(CURR_SECOND_HALF_LIB_CESS)); jsonObject.addProperty("arrearLibraryTax", valuesMap.get(ARR_LIB_CESS) == null ? BigDecimal.ZERO : valuesMap.get(ARR_LIB_CESS)); }/*from w w w . j av a2 s . co m*/ jsonObject.addProperty("propertyTaxSecondHlf", baseRegisterResultObj.getAggrCurrSecondHalfDmd() == null ? BigDecimal.ZERO : baseRegisterResultObj.getAggrCurrSecondHalfDmd()); jsonObject.addProperty("currTotal", currTotal); jsonObject.addProperty("penaltyFines", currPenaltyFine); jsonObject.addProperty("arrearPeriod", baseRegisterResultObj.getDuePeriod() != null && org.apache.commons.lang.StringUtils.isNotBlank(baseRegisterResultObj.getDuePeriod()) ? baseRegisterResultObj.getDuePeriod() : "NA"); jsonObject.addProperty("arrearPropertyTax", baseRegisterResultObj.getAggrArrDmd() != null && baseRegisterResultObj.getAggrArrDmd().compareTo(BigDecimal.ZERO) >= 1 ? baseRegisterResultObj.getAggrArrDmd().subtract( valuesMap == null ? BigDecimal.ZERO : valuesMap.get(ARR_LIB_CESS)) : BigDecimal.ZERO); jsonObject.addProperty("arrearPenaltyFines", baseRegisterResultObj.getAggrArrearPenaly() == null ? BigDecimal.ZERO : baseRegisterResultObj.getAggrArrearPenaly()); jsonObject.addProperty("arrearTotal", baseRegisterResultObj.getAggrArrDmd() == null ? BigDecimal.ZERO : baseRegisterResultObj.getAggrArrDmd()); jsonObject.addProperty("arrearColl", arrColl); jsonObject.addProperty("currentColl", currentColl); jsonObject.addProperty("totalColl", totalColl); baseRegisterResultData.add(jsonObject); }); return enhance(baseRegisterResultData, baseRegisterResponse); }
From source file:org.kuali.kfs.module.endow.businessobject.FeeMethod.java
/** * Sets the firstFeeRate attribute value. * //from w w w .ja v a 2 s . co m * @param firstFeeRate The firstFeeRate to set. */ public void setFirstFeeRate(BigDecimal firstFeeRate) { this.firstFeeRate = firstFeeRate.setScale(EndowConstants.FeeMethod.FEE_RATE_MAX_SCALE, KualiDecimal.ROUND_BEHAVIOR); }
From source file:org.kuali.kfs.module.endow.businessobject.FeeMethod.java
/** * Sets the thirdFeeRate attribute value. * //w w w . j a v a 2s . c o m * @param thirdFeeRate The thirdFeeRate to set. */ public void setThirdFeeRate(BigDecimal thirdFeeRate) { this.thirdFeeRate = thirdFeeRate.setScale(EndowConstants.FeeMethod.FEE_RATE_MAX_SCALE, KualiDecimal.ROUND_BEHAVIOR); }
From source file:org.kuali.kfs.module.endow.businessobject.FeeMethod.java
/** * Sets the secondFeeRate attribute value. * /* w ww . j ava 2 s.com*/ * @param secondFeeRate The secondFeeRate to set. */ public void setSecondFeeRate(BigDecimal secondFeeRate) { this.secondFeeRate = secondFeeRate.setScale(EndowConstants.FeeMethod.FEE_RATE_MAX_SCALE, KualiDecimal.ROUND_BEHAVIOR); }
From source file:com.artivisi.biller.simulator.gateway.pln.PlnGateway.java
private boolean handleInquiryPostpaid(ISOSource src, ISOMsg msg, ISOMsg response) throws ISOException, IOException, VetoException { String bit48Request = msg.getString(48); if (bit48Request.length() != 19) { logger.error("[POSTPAID] - [INQ-REQ] - Invalid bit 48 [{}]", bit48Request); response.set(39, ResponseCode.ERROR_INVALID_MESSAGE); src.send(response);//from w w w.ja v a 2 s . c o m return true; } String mitra = bit48Request.substring(0, 7); if (billerSimulatorService.findMitraByKode(mitra.trim()) == null) { logger.debug("[POSTPAID] - [INQ-REQ] - Mitra [{}]", mitra); logger.error("[POSTPAID] - [INQ-REQ] - Kode mitra tidak ditemukan [{}]", mitra); response.set(39, ResponseCode.ERROR_UNREGISTERED_SWITCHING); src.send(response); return true; } String idpel = bit48Request.substring(7); Pelanggan p = plnSimulatorService.findPelangganByIdpel(idpel); if (p == null) { logger.error("[POSTPAID] - [INQ-REQ] - IDPEL tidak ditemukan [{}]", idpel); response.set(39, ResponseCode.ERROR_UNKNOWN_SUBSCRIBER); src.send(response); return true; } if (!ResponseCode.SUCCESSFUL.equals(p.getResponseCode())) { logger.error("[POSTPAID] - [INQ-REQ] - Pelanggan diset untuk RC [{}]", p.getResponseCode()); response.set(39, p.getResponseCode()); src.send(response); return true; } List<TagihanPascabayar> daftarTagihan = plnSimulatorService.findTagihan(p); if (daftarTagihan.size() < 1) { logger.error("[POSTPAID] - [INQ-REQ] - Tagihan untuk idpel [{}] tidak ada", idpel); response.set(39, ResponseCode.ERROR_CURRENT_BILL_IS_NOT_AVAILABLE); src.send(response); return true; } List<TagihanPascabayar> tagihanDikirim; if (daftarTagihan.size() > 4) { tagihanDikirim = daftarTagihan.subList(0, 4); } else { tagihanDikirim = daftarTagihan; } BigDecimal amount = BigDecimal.ZERO; for (TagihanPascabayar tagihanPascabayar : tagihanDikirim) { amount = amount.add(tagihanPascabayar.getBill()); amount = amount.add(tagihanPascabayar.getDenda()); } response.set(4, "360" + "0" + StringUtils.leftPad(amount.setScale(0, RoundingMode.HALF_EVEN).toString(), 12, "0")); InquiryPostpaidResponse ipr = new InquiryPostpaidResponse(); ipr.setBank(msg.getString(32)); ipr.setSwitcher(mitra); ipr.setStan(msg.getString(11)); for (TagihanPascabayar tagihanPascabayar : tagihanDikirim) { InquiryPostpaidResponseDetail detail = new InquiryPostpaidResponseDetail(); detail.setTagihanPascabayar(tagihanPascabayar); detail.setInquiryPostpaidResponse(ipr); ipr.getDetails().add(detail); } plnService.save(ipr); StringBuffer bit48Response = createBit48InquiryPostpaidResponse(bit48Request, p, daftarTagihan, tagihanDikirim, ipr); response.set(39, ResponseCode.SUCCESSFUL); response.set(48, bit48Response.toString()); try { logger.info("[POSTPAID] - [INQ-REQ] - Pelanggan diset untuk hold [{}]", p.getHoldResponse()); Thread.sleep(p.getHoldResponse()); } catch (Exception e) { logger.error(e.getMessage(), e); } src.send(response); return true; }