Example usage for java.math BigDecimal setScale

List of usage examples for java.math BigDecimal setScale

Introduction

In this page you can find the example usage for java.math BigDecimal setScale.

Prototype

@Deprecated(since = "9")
public BigDecimal setScale(int newScale, int roundingMode) 

Source Link

Document

Returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.

Usage

From source file:org.egov.adtax.service.AdvertisementDemandService.java

/**
 * @param dmdAmount//from   ww w . java 2 s.com
 * @param egDemandReason
 * @param amtCollected
 * @return
 */
public EgDemandDetails createDemandDetails(final BigDecimal dmdAmount, final EgDemandReason egDemandReason,
        final BigDecimal amtCollected) {
    return EgDemandDetails.fromReasonAndAmounts(dmdAmount.setScale(0, BigDecimal.ROUND_HALF_UP), egDemandReason,
            amtCollected);
}

From source file:org.kuali.ole.module.purap.document.service.impl.OlePurapServiceImpl.java

@Override
public OlePaymentRequestItem calculateForeignCurrency(OlePaymentRequestItem item) {
    if (item.getItemForeignListPrice() != null) {
        if (item.getItemForeignDiscount() == null) {
            item.setItemForeignDiscount(new KualiDecimal(0));
        }//  ww  w  . j  a va  2  s .  co  m
        if (item.getItemForeignDiscountType() != null && item.getItemForeignDiscountType()
                .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
            BigDecimal calculatedForeignDiscountAmt = item.getItemForeignDiscount().bigDecimalValue()
                    .multiply(new BigDecimal(0.01)).multiply(item.getItemForeignListPrice().bigDecimalValue());
            item.setItemForeignDiscountAmt(new KualiDecimal(
                    calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
            item.setItemForeignUnitCost(
                    item.getItemForeignListPrice().subtract(item.getItemForeignDiscountAmt()));
            return item;
        } else {
            item.setItemForeignDiscountAmt(item.getItemForeignDiscount());
            item.setItemForeignUnitCost(item.getItemForeignListPrice().subtract(item.getItemForeignDiscount()));
            return item;
        }
    } else {
        return item;
    }
}

From source file:org.kuali.ole.module.purap.document.service.impl.OlePurapServiceImpl.java

@Override
public OleInvoiceItem calculateForeignCurrency(OleInvoiceItem item) {
    if (item.getItemForeignListPrice() != null) {
        if (item.getItemForeignDiscount() == null) {
            item.setItemForeignDiscount(new KualiDecimal(0));
        }/*from   www .  j  a  v  a2 s.  co  m*/
        if (item.getItemForeignDiscountType() != null && item.getItemForeignDiscountType()
                .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
            BigDecimal calculatedForeignDiscountAmt = item.getItemForeignDiscount().bigDecimalValue()
                    .multiply(new BigDecimal(0.01)).multiply(item.getItemForeignListPrice().bigDecimalValue());
            item.setItemForeignDiscountAmt(new KualiDecimal(
                    calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
            item.setItemForeignUnitCost(
                    item.getItemForeignListPrice().subtract(item.getItemForeignDiscountAmt()));
            return item;
        } else {
            item.setItemForeignDiscountAmt(item.getItemForeignDiscount());
            item.setItemForeignUnitCost(item.getItemForeignListPrice().subtract(item.getItemForeignDiscount()));
            return item;
        }
    } else {
        return item;
    }
}

From source file:com.etiansoft.haier.service.ManagerService.java

/**
 * //from  w  w  w .j a  v  a  2s.  c  o m
 * @Title: ???
 * @Description: TODO
 * @param @param page
 * @param @param name
 * @param @param phone
 * @param @param status
 * @param @return
 * @param @throws Exception
 * @return DataTablePage
 * @throws
 */
public DataTablePage getData(DataTablePage page, String name, String phone, String status, String merchant_num,
        String order_id) throws Exception {
    DataTablePage dataTable = null;

    dataTable = udsService.findPage(page, Merchant.class, MerchantVo.class, tableName, "create_date", "desc",
            makeParam(name, phone, status, merchant_num));

    List<MerchantVo> datas = (List<MerchantVo>) dataTable.getAaData();

    for (MerchantVo dataMerchant : datas) {
        Map<String, Object> mapm = new HashMap<String, Object>();
        mapm.put("merchant_id", dataMerchant.getMerchantId());
        List<Order> listm = (List<Order>) udsService.findByTimeForOrder2("order", Order.class, mapm);

        BigDecimal num = new BigDecimal(0);

        if (listm != null && listm.size() > 0) {
            for (Order or : listm) {
                if (or.getStatus().intValue() == 2 || or.getStatus().intValue() == 3
                        || or.getStatus().intValue() == 4 || or.getStatus().intValue() == 5) {
                    num = num.add(new BigDecimal(or.getFavored_amount()).add(new BigDecimal(or.getFreight())));
                }
            }
        }
        dataMerchant.setSaleVolum(num.setScale(2, RoundingMode.HALF_UP).doubleValue());
        Mpromotion promotion = (Mpromotion) udsService.findById("mpromotion", "merchant_id_",
                dataMerchant.getMerchantId(), Mpromotion.class);
        if (promotion != null) {
            dataMerchant.setPromotion_sort(promotion.getSort());
            dataMerchant.setPromotion_tag(promotion.getPromotion_tag());
        }

    }

    return dataTable;

}

From source file:org.apache.ofbiz.shipment.thirdparty.usps.UspsServices.java

public static Integer[] convertPoundsToPoundsOunces(BigDecimal decimalPounds) {
    if (decimalPounds == null)
        return null;
    Integer[] poundsOunces = new Integer[2];
    poundsOunces[0] = Integer.valueOf(decimalPounds.setScale(0, BigDecimal.ROUND_FLOOR).toPlainString());
    // (weight % 1) * 16 rounded up to nearest whole number
    poundsOunces[1] = Integer.valueOf(decimalPounds.remainder(BigDecimal.ONE).multiply(new BigDecimal("16"))
            .setScale(0, BigDecimal.ROUND_CEILING).toPlainString());
    return poundsOunces;
}

From source file:com.delmar.station.web.action.WFDetailAction.java

/**
 * ?/*from   w w  w  . ja va  2 s .  c o m*/
 * @return
 */
public String initDetail() {

    //?
    if (id != null && id > 0) {
        wfDetail = wfDetailService.getWFDetailById(id);
        if (wfDetail != null) {
            warehouseForwarder = warehouseForwarderService.selectByPrimaryKey(wfDetail.getMasterID());
        }

        init();

        //
    } else {
        warehouseForwarder = warehouseForwarderService.getWareHouseForwarderByNo(warehouseNo);
        lastWFDetail = null;
        List<String> referenceNoList = null;
        wfDetail = new WFDetail();
        if (warehouseForwarder != null) {
            WFReality wfReality = wfRealityService.getWFRealityByMasterId(warehouseForwarder.getId());
            if (wfReality != null) {
                int totalGoodsNumber = 0;
                double totalGoodsWeight = 0;
                double totalGoodsSize = 0;

                if (warehouseForwarder.getGoodsNumber() - wfReality.getGoodsNumber() > 0) {
                    totalGoodsNumber = warehouseForwarder.getGoodsNumber() - wfReality.getGoodsNumber();
                }

                if (warehouseForwarder.getGoodsWeight() - wfReality.getGoodsWeight() > 0) {
                    totalGoodsWeight = warehouseForwarder.getGoodsWeight() - wfReality.getGoodsWeight();
                }

                if (warehouseForwarder.getGoodsSize() - wfReality.getGoodsSize() > 0) {
                    totalGoodsSize = warehouseForwarder.getGoodsSize() - wfReality.getGoodsSize();
                }

                //??
                BigDecimal goodsWeight = new BigDecimal(totalGoodsWeight);
                BigDecimal goodsSize = new BigDecimal(totalGoodsSize);
                wfDetail.setGoodsNumber(totalGoodsNumber);
                wfDetail.setGoodsWeight(goodsWeight.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
                wfDetail.setGoodsSize(goodsSize.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());

            } else {

                //??
                BigDecimal goodsWeight = new BigDecimal(warehouseForwarder.getGoodsWeight());
                BigDecimal goodsSize = new BigDecimal(warehouseForwarder.getGoodsSize());
                wfDetail.setGoodsNumber(warehouseForwarder.getGoodsNumber());
                wfDetail.setGoodsWeight(goodsWeight.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
                wfDetail.setGoodsSize(goodsSize.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
            }

            wfDetail.setGoodsDesc(warehouseForwarder.getGoodsDesc());
            wfDetail.setMaiTou(warehouseForwarder.getMaiTou());
            wfDetail.setChargeData(warehouseForwarder.getChargeData());
            wfDetail.setMasterID(warehouseForwarder.getId());
            wfDetail.setTrustFileCode(warehouseForwarder.getTrustFileCode());
            wfDetail.setCompanyID(warehouseForwarder.getCompanyID());

            if (warehouseForwarder.getToWarehouse().equals(getCurrentUserThird(CARGO_PRO_WAREHOUSE))) {
                List<WFDetail> list = wfDetailService.getWFDetailByMasterId(warehouseForwarder.getId());

                //sqlorder by inDate desc ?
                if (list != null && list.size() > 0) {
                    lastWFDetail = list.get(0);
                }

                if (StringUtils.isNotEmpty(warehouseForwarder.getReferenceNo())) {
                    String referenceNo = warehouseForwarder.getReferenceNo();

                    String[] tempRreferenceNo = referenceNo.split(";");
                    referenceNoList = new ArrayList<String>();
                    for (int i = 0; i < tempRreferenceNo.length; i++) {
                        referenceNoList.add(tempRreferenceNo[i]);
                    }
                }
            }

            //???????
            wfDetail.setInDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            if (referenceNoList != null && lastWFDetail != null) {
                wfDetail.setCarDriver(lastWFDetail.getCarDriver());
                wfDetail.setCarLicenseNo(lastWFDetail.getCarLicenseNo());
            }

            if (lastWFDetail != null) {

                wfDetail.setReceiptPerson(lastWFDetail.getReceiptPerson());
                wfDetail.setShippingSpace(lastWFDetail.getShippingSpace());
            }

            UserResource ur = (UserResource) ServletActionContext.getRequest().getSession()
                    .getAttribute("resource");
            packageList = datadictService.getDatadictTrlByValue(DatadictType.PACKAGELIST,
                    ur.getLocale().toString());
            FacesUtils.setValueInHashtableOfSession("packageList", packageList);
        }
    }

    return "initDetail";
}

From source file:org.egov.ptis.domain.service.revisionPetition.RevisionPetitionService.java

public void setNoticeInfo(final PropertyImpl property, final PropertyNoticeInfo propertyNotice,
        final BasicPropertyImpl basicProperty, final RevisionPetition objection) {
    final PropertyAckNoticeInfo infoBean = new PropertyAckNoticeInfo();
    final Address ownerAddress = basicProperty.getAddress();
    BigDecimal totalTax = BigDecimal.ZERO;
    BigDecimal propertyTax = BigDecimal.ZERO;
    if (basicProperty.getPropertyOwnerInfo().size() > 1)
        infoBean.setOwnerName(basicProperty.getFullOwnerName().concat(" and others"));
    else/*from   ww  w. j ava 2 s.  c  om*/
        infoBean.setOwnerName(basicProperty.getFullOwnerName());

    infoBean.setOwnerAddress(basicProperty.getAddress().toString());
    infoBean.setApplicationNo(property.getApplicationNo());
    infoBean.setDoorNo(ownerAddress.getHouseNoBldgApt());
    if (isNotBlank(ownerAddress.getLandmark()))
        infoBean.setStreetName(ownerAddress.getLandmark());
    else
        infoBean.setStreetName("N/A");
    final SimpleDateFormat formatNowYear = new SimpleDateFormat("yyyy");
    final String occupancyYear = formatNowYear.format(basicProperty.getPropOccupationDate());
    infoBean.setInstallmentYear(occupancyYear);
    infoBean.setAssessmentNo(basicProperty.getUpicNo());
    final SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
    infoBean.setAssessmentDate(dateformat.format(basicProperty.getAssessmentdate()));
    final Ptdemand currDemand = ptDemandDAO.getNonHistoryCurrDmdForProperty(property);

    // Sets data for the current property
    prepareTaxInfoForProperty(infoBean, totalTax, propertyTax, currDemand, CURRENT);
    if (currDemand.getDmdCalculations() != null && currDemand.getDmdCalculations().getAlv() != null)
        infoBean.setNew_rev_ARV(currDemand.getDmdCalculations().getAlv());

    // Sets data for the latest history property
    final PropertyImpl historyProperty = propertyService.getLatestHistoryProperty(basicProperty.getUpicNo());
    final Ptdemand historyDemand = ptDemandDAO.getNonHistoryCurrDmdForProperty(historyProperty);
    if (historyProperty != null && historyDemand != null) {
        totalTax = BigDecimal.ZERO;
        propertyTax = BigDecimal.ZERO;
        prepareTaxInfoForProperty(infoBean, totalTax, propertyTax, historyDemand, HISTORY);
        if (historyDemand.getDmdCalculations() != null && historyDemand.getDmdCalculations().getAlv() != null)
            infoBean.setExistingARV(historyDemand.getDmdCalculations().getAlv());
    }

    final PropertyID boundaryDetails = basicProperty.getPropertyID();
    infoBean.setZoneName(boundaryDetails.getZone().getName());
    infoBean.setWardName(boundaryDetails.getWard().getName());
    infoBean.setAreaName(boundaryDetails.getArea().getName());
    infoBean.setLocalityName(boundaryDetails.getLocality().getName());
    infoBean.setNoticeDate(new Date());
    infoBean.setApplicationDate(DateUtils.getFormattedDate(objection.getCreatedDate(), DATE_FORMAT_DDMMYYY));
    infoBean.setHearingDate(DateUtils.getFormattedDate(objection.getHearings().get(0).getPlannedHearingDt(),
            DATE_FORMAT_DDMMYYY));
    infoBean.setActualHearingDate(DateUtils
            .getFormattedDate(objection.getHearings().get(0).getActualHearingDt(), DATE_FORMAT_DDMMYYY));
    final User approver = userService.getUserById(ApplicationThreadLocals.getUserId());
    infoBean.setApproverName(approver.getName());
    final BigDecimal revTax = currDemand.getBaseDemand();
    infoBean.setNewTotalTax(revTax.setScale(0, BigDecimal.ROUND_HALF_UP));
    if (property.getSource().equals(SOURCE_MEESEVA))
        infoBean.setMeesevaNo(property.getApplicationNo());
    propertyNotice.setOwnerInfo(infoBean);
}

From source file:com.cssweb.android.trade.util.TradeUtil.java

/**
 * ??//www  . j av  a 2  s  . co m
 */
public static String formatNum(String str, int len) {
    if (str == null)
        return "";
    int flag = 1;
    if (str.charAt(0) == '-' && str.charAt(1) == '.') {
        str = str.replace("-.", "-0.");
        flag = -1;
    }
    if (str.charAt(0) == '.')
        str = "0" + str;
    if (len < 0)
        len = 0;
    BigDecimal small = new BigDecimal("0");
    BigDecimal big = new BigDecimal("0");
    if (("0").equals(str) && len == 0)
        return "0";
    if (str.indexOf(".") != -1) {
        String[] ary = str.split("\\.");
        big = BigDecimal.valueOf(Double.parseDouble(ary[0]));
        small = BigDecimal.valueOf(Double.parseDouble("0." + ary[1]));
        small = small.setScale(len > 0 ? len : 1, BigDecimal.ROUND_HALF_UP);
        if (str.charAt(0) == '-') {
            return big.subtract(small).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP)
                    .toString();
        }
        return big.add(small).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP).toString();
    } else {
        return new BigDecimal(str).multiply(new BigDecimal(flag)).setScale(len, BigDecimal.ROUND_HALF_UP)
                .toString();
    }
}

From source file:org.kuali.ole.module.purap.document.service.impl.OlePurapServiceImpl.java

@Override
public OleRequisitionItem calculateForeignCurrency(OleRequisitionItem oleRequisition) {
    if (oleRequisition.getItemForeignListPrice() != null
            && oleRequisition.getItemForeignDiscountType() != null) {
        if (oleRequisition.getItemForeignDiscount() == null) {
            oleRequisition.setItemForeignDiscount(new KualiDecimal(0));
        }//from   www  . j a va 2  s . co  m
        if (oleRequisition.getItemForeignDiscountType()
                .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
            BigDecimal calculatedForeignDiscountAmt = oleRequisition.getItemForeignDiscount().bigDecimalValue()
                    .multiply(new BigDecimal(0.01))
                    .multiply(oleRequisition.getItemForeignListPrice().bigDecimalValue());
            oleRequisition.setItemForeignDiscountAmt(new KualiDecimal(
                    calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
            oleRequisition.setItemForeignUnitCost(oleRequisition.getItemForeignListPrice()
                    .subtract(oleRequisition.getItemForeignDiscountAmt()));
            return oleRequisition;
        } else {
            oleRequisition.setItemForeignDiscountAmt((oleRequisition.getItemForeignDiscount()));
            oleRequisition.setItemForeignUnitCost(new KualiDecimal(oleRequisition.getItemForeignListPrice()
                    .bigDecimalValue().subtract(oleRequisition.getItemForeignDiscount().bigDecimalValue())));
            return oleRequisition;
        }
    } else {
        return oleRequisition;
    }
}

From source file:org.kuali.ole.module.purap.document.service.impl.OlePurapServiceImpl.java

@Override
public OlePurchaseOrderItem calculateForeignCurrency(OlePurchaseOrderItem olePurchaseOrder) {
    if (olePurchaseOrder.getItemForeignListPrice() != null
            && olePurchaseOrder.getItemForeignDiscountType() != null) {
        if (olePurchaseOrder.getItemForeignDiscount() == null) {
            olePurchaseOrder.setItemForeignDiscount(new KualiDecimal(0));
        }// w w w .ja va  2s  .c  o m
        if (olePurchaseOrder.getItemForeignDiscountType()
                .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
            BigDecimal calculatedForeignDiscountAmt = olePurchaseOrder.getItemForeignDiscount()
                    .bigDecimalValue().multiply(new BigDecimal(0.01))
                    .multiply(olePurchaseOrder.getItemForeignListPrice().bigDecimalValue());
            olePurchaseOrder.setItemForeignDiscountAmt(new KualiDecimal(
                    calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
            olePurchaseOrder.setItemForeignUnitCost(olePurchaseOrder.getItemForeignListPrice()
                    .subtract(olePurchaseOrder.getItemForeignDiscountAmt()));
            return olePurchaseOrder;
        } else {
            olePurchaseOrder.setItemForeignDiscountAmt(olePurchaseOrder.getItemForeignDiscount());
            olePurchaseOrder.setItemForeignUnitCost(olePurchaseOrder.getItemForeignListPrice()
                    .subtract(olePurchaseOrder.getItemForeignDiscount()));
            return olePurchaseOrder;
        }
    } else {
        return olePurchaseOrder;
    }
}