Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

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

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:com.baidu.rigel.biplatform.tesseract.action.MetaQueryAction.java

/**
 * //from   ww w  . ja v a  2  s .  c o  m
 * @param result
 * @param sortRecord
 * @return DataModel
 */
private DataModel tonNSetting4Chart(DataModel result, SortRecord sortRecord) {
    BigDecimal sum = BigDecimal.ZERO;
    for (BigDecimal tmp : result.getColumnBaseData().get(0)) {
        //TODO ??
        if (tmp == null) {
            continue;
        }
        sum = sum.add(tmp);
    }
    // 
    result = DataModelUtils.truncModel(result, sortRecord.getRecordSize() - 1);
    BigDecimal sum1 = BigDecimal.ZERO;
    for (BigDecimal tmp : result.getColumnBaseData().get(0)) {
        //TODO ??
        if (tmp == null) {
            continue;
        }
        sum1 = sum1.add(tmp);
    }
    BigDecimal other = null;
    if (sum1 != BigDecimal.ZERO) {
        other = sum.subtract(sum1);
    }
    result.getColumnBaseData().get(0).add(other);
    HeadField otherRowField = DeepcopyUtils.deepCopy(result.getRowHeadFields().get(0));
    otherRowField.setSummarizeData(other);
    String caption = "";
    otherRowField.setCaption(caption);
    String dimName = MetaNameUtil.getDimNameFromUniqueName(otherRowField.getValue());
    String uniqueName = "[" + dimName + "].[" + caption + "]";
    String nodeUniqueName = "{" + uniqueName + "}";
    otherRowField.setNodeUniqueName(nodeUniqueName);
    otherRowField.setValue(uniqueName);
    result.getRowHeadFields().add(otherRowField);
    return result;
}

From source file:com.aan.girsang.server.service.impl.TransaksiServiceImpl.java

private void simpanHutang() {
    List<Supplier> suppliers = supplierDao.semua();
    for (Supplier s : suppliers) {
        List<Pembelian> pembelians = pembelianDao.cariSupplier(s);
        List<PelunasanHutang> hutangs = pelunasanHutangDao.cariSupplier(s);

        BigDecimal hutangPembelian = new BigDecimal(0);
        BigDecimal pembayaranHutang = new BigDecimal(0);

        for (int i = 0; i < pembelians.size(); i++) {
            Pembelian p = pembelians.get(i);
            hutangPembelian = hutangPembelian.add(p.getDaftarKredit().getSisaKredit());
        }/*  w  ww  .ja  va 2s.c  o  m*/

        for (int i = 0; i < hutangs.size(); i++) {
            PelunasanHutang pH = hutangs.get(i);
            pembayaranHutang = pembayaranHutang.add(pH.getJlhBayar());
        }
        s.setSaldoHutang(hutangPembelian.subtract(pembayaranHutang));

        supplierDao.simpan(s);
    }
}

From source file:module.siadap.domain.SiadapEvaluationUniverse.java

private BigDecimal getEvaluationScoring(List<? extends SiadapEvaluationItem> evaluations) {

    if (!isEvaluationScoringComplete(evaluations)) {
        return BigDecimal.ZERO;
    }/*from  w  w  w . j  a v a2s.c  o m*/

    BigDecimal result = new BigDecimal(0);
    for (SiadapEvaluationItem evaluation : evaluations) {
        IScoring itemEvaluation = evaluation.getItemEvaluation();
        if (itemEvaluation == null) {
            throw new SiadapException("error.siadapEvaluation.mustFillAllItems");
        }
        result = result.add(itemEvaluation.getPoints());
    }

    if (evaluations.size() == 0) {
        return BigDecimal.ZERO;
    }
    return result.divide(new BigDecimal(evaluations.size()), PRECISION, ROUND_MODE);
}

From source file:com.aan.girsang.server.service.impl.TransaksiServiceImpl.java

private void simpanPiutang() {
    List<Pelanggan> daftarPelanggan = pelangganDao.semua();
    for (Pelanggan p : daftarPelanggan) {
        List<Penjualan> daftarPenjualan = penjualanDao.cariPelanggan(p);
        //List<PelunasanHutang> hutangs = pelunasanHutangDao.cariSupplier(p);

        BigDecimal piutang = new BigDecimal(0);
        //            BigDecimal pembayaranHutang = new BigDecimal(0);

        for (int i = 0; i < daftarPenjualan.size(); i++) {
            Penjualan jual = daftarPenjualan.get(i);
            piutang = piutang.add(jual.getPiutangAwal());
        }// w  w w  .  j  a v a  2s.  c  om

        //            for(int i=0;i<hutangs.size();i++){
        //                PelunasanHutang pH = hutangs.get(i);
        //                pembayaranHutang = pembayaranHutang.add(pH.getJlhBayar());
        //            }
        p.setSaldoPiutang(piutang);

        pelangganDao.simpan(p);
    }
}

From source file:com.chinamobile.bcbsp.ml.math.DenseDoubleVector.java

@Override
public double dotUnsafe(DoubleVector vector) {
    BigDecimal dotProduct = BigDecimal.valueOf(0.0d);
    for (int i = 0; i < getLength(); i++) {
        dotProduct = dotProduct
                .add(BigDecimal.valueOf(this.get(i)).multiply(BigDecimal.valueOf(vector.get(i))));
    }//from  w  ww.j  av a2s  .  c om
    return dotProduct.doubleValue();
}

From source file:com.salesmanager.core.module.impl.application.prices.OneTimePriceModule.java

public OrderTotalSummary calculateOrderPrice(Order order, OrderTotalSummary orderSummary,
        OrderProduct orderProduct, OrderProductPrice productPrice, String currency, Locale locale) {
    // TODO Auto-generated method stub

    /**// w w  w .  j  a  va  2  s.  c o m
     * activation price goes in the oneTime fees
     */

    BigDecimal finalPrice = null;
    // BigDecimal discountPrice=null;

    // order price this type of price needs an upfront payment
    BigDecimal otprice = orderSummary.getOneTimeSubTotal();
    if (otprice == null) {
        otprice = new BigDecimal(0);
    }

    // the final price is in the product price
    finalPrice = productPrice.getProductPriceAmount();
    int quantity = orderProduct.getProductQuantity();
    finalPrice = finalPrice.multiply(new BigDecimal(quantity));

    otprice = otprice.add(finalPrice);
    orderSummary.setOneTimeSubTotal(otprice);

    ProductPriceSpecial pps = productPrice.getSpecial();

    // Build text

    StringBuffer notes = new StringBuffer();
    notes.append(quantity).append(" x ");
    notes.append(orderProduct.getProductName());
    notes.append(" ");
    notes.append(
            CurrencyUtil.displayFormatedAmountWithCurrency(productPrice.getProductPriceAmount(), currency));
    notes.append(" ");

    notes.append(productPrice.getProductPriceName());

    BigDecimal originalPrice = orderProduct.getOriginalProductPrice();
    if (!productPrice.isDefaultPrice()) {
        originalPrice = productPrice.getProductPriceAmount();
    }

    if (pps != null) {
        if (pps.getProductPriceSpecialStartDate() != null && pps.getProductPriceSpecialEndDate() != null) {
            if (pps.getProductPriceSpecialStartDate().before(order.getDatePurchased())
                    && pps.getProductPriceSpecialEndDate().after(order.getDatePurchased())) {

                BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue());

                if (dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) {

                    BigDecimal subTotal = originalPrice
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                    BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount()
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));

                    BigDecimal credit = subTotal.subtract(creditSubTotal);

                    StringBuffer spacialNote = new StringBuffer();
                    spacialNote.append("<font color=\"red\">[");

                    spacialNote.append(productPrice.getProductPriceName());

                    // spacialNote.append(getPriceText(currency,locale));

                    spacialNote.append(" ");
                    spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));

                    spacialNote.append("]</font>");

                    if (productPrice.getProductPriceAmount().doubleValue() > pps.getProductPriceSpecialAmount()
                            .doubleValue()) {

                        OrderTotalLine line = new OrderTotalLine();
                        line.setText(spacialNote.toString());
                        line.setCost(credit);
                        line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                        orderSummary.addDueNowCredits(line);

                        BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge();
                        oneTimeCredit = oneTimeCredit.add(credit);
                        orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit);
                    }
                }

            } else if (pps.getProductPriceSpecialDurationDays() > -1) {

                Date dt = new Date();

                int numDays = pps.getProductPriceSpecialDurationDays();
                Date purchased = order.getDatePurchased();
                Calendar c = Calendar.getInstance();
                c.setTime(dt);
                c.add(Calendar.DATE, numDays);

                BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue());

                if (dt.before(c.getTime())
                        && dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) {

                    BigDecimal subTotal = originalPrice
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                    BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount()
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));

                    BigDecimal credit = subTotal.subtract(creditSubTotal);

                    StringBuffer spacialNote = new StringBuffer();
                    spacialNote.append("<font color=\"red\">[");

                    spacialNote.append(productPrice.getProductPriceName());

                    // spacialNote.append(getPriceText(currency,locale));
                    spacialNote.append(" ");
                    spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));

                    spacialNote.append("]</font>");

                    if (productPrice.getProductPriceAmount().doubleValue() > pps.getProductPriceSpecialAmount()
                            .doubleValue()) {

                        OrderTotalLine line = new OrderTotalLine();

                        line.setText(spacialNote.toString());
                        line.setCost(credit);
                        line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                        orderSummary.addDueNowCredits(line);

                        BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge();
                        oneTimeCredit = oneTimeCredit.add(credit);
                        orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit);

                    }

                }

            }
        }

    }

    if (!productPrice.isDefaultPrice()) {

        // add a price description
        OrderTotalLine scl = new OrderTotalLine();
        scl.setText(notes.toString());
        scl.setCost(finalPrice);
        scl.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
        orderSummary.addOtherDueNowPrice(scl);
    }

    return orderSummary;

}

From source file:mx.edu.um.mateo.inventario.web.SalidaController.java

@RequestMapping("/ver/{id}")
public String ver(@PathVariable Long id, Model modelo) {
    log.debug("Mostrando salida {}", id);
    Salida salida = salidaDao.obtiene(id);
    switch (salida.getEstatus().getNombre()) {
    case Constantes.ABIERTA:
        modelo.addAttribute("puedeEditar", true);
        modelo.addAttribute("puedeEliminar", true);
        modelo.addAttribute("puedeCerrar", true);
        break;/*from   w  w  w  . j a  va2s.  com*/
    case Constantes.CERRADA:
        modelo.addAttribute("puedeCancelar", true);
        modelo.addAttribute("puedeReporte", true);
        break;
    case Constantes.CANCELADA:
        log.debug("Puede ver reporte");
        modelo.addAttribute("puedeReporte", true);
        break;
    }

    modelo.addAttribute("salida", salida);

    BigDecimal subtotal = new BigDecimal("0").setScale(2, RoundingMode.HALF_UP);
    BigDecimal iva = new BigDecimal("0").setScale(2, RoundingMode.HALF_UP);
    for (LoteSalida lote : salida.getLotes()) {
        subtotal = subtotal.add(lote.getPrecioUnitario().multiply(lote.getCantidad()));
        iva = iva.add(lote.getIva());
    }
    BigDecimal total = subtotal.add(iva);
    modelo.addAttribute("subtotal", subtotal.setScale(2, RoundingMode.HALF_UP));
    modelo.addAttribute("iva", iva);
    modelo.addAttribute("total", total.setScale(2, RoundingMode.HALF_UP));
    if (iva.compareTo(salida.getIva()) == 0 && total.compareTo(salida.getTotal()) == 0) {
        modelo.addAttribute("estiloTotales", "label label-success");
    } else {
        BigDecimal variacion = new BigDecimal("0.05");
        BigDecimal topeIva = salida.getIva().multiply(variacion);
        BigDecimal topeTotal = salida.getTotal().multiply(variacion);
        log.debug("Estilos {} {} {} {} {} {}",
                new Object[] { iva, salida.getIva(), topeIva, total, salida.getTotal(), topeTotal });
        if (iva.compareTo(salida.getIva()) < 0 || total.compareTo(salida.getTotal()) < 0) {
            log.debug("La diferencia es menor");
            if (iva.compareTo(salida.getIva().subtract(topeIva)) >= 0
                    && total.compareTo(salida.getTotal().subtract(topeTotal)) >= 0) {
                modelo.addAttribute("estiloTotales", "label label-warning");
            } else {
                modelo.addAttribute("estiloTotales", "label label-important");
            }
        } else {
            log.debug("La diferencia es mayor {} {}",
                    new Object[] { iva.compareTo(salida.getIva().add(topeIva)),
                            total.compareTo(salida.getTotal().add(topeTotal)) });
            if (iva.compareTo(salida.getIva().add(topeIva)) <= 0
                    && total.compareTo(salida.getTotal().add(topeTotal)) <= 0) {
                log.debug("estilo warning");
                modelo.addAttribute("estiloTotales", "label label-warning");
            } else {
                log.debug("estilo error");
                modelo.addAttribute("estiloTotales", "label label-important");
            }
        }
    }

    return "inventario/salida/ver";
}

From source file:cpcc.core.base.PolygonZone.java

/**
 * @return the coordinates of the center of gravity.
 *//*from w w w  . j a  v  a  2s .c  o m*/
public PolarCoordinate getCenterOfGravity() {
    BigDecimal x = new BigDecimal(0), y = new BigDecimal(0);
    BigDecimal doubleArea = new BigDecimal(0);

    for (int k = 0, l = vertices.length - 1; k < l; ++k) {
        BigDecimal ax = new BigDecimal(vertices[k].x);
        BigDecimal ay = new BigDecimal(vertices[k].y);
        BigDecimal bx = new BigDecimal(vertices[k + 1].x);
        BigDecimal by = new BigDecimal(vertices[k + 1].y);
        BigDecimal t = ax.multiply(by).subtract(bx.multiply(ay));
        x = x.add(ax.add(bx).multiply(t));
        y = y.add(ay.add(by).multiply(t));
        doubleArea = doubleArea.add(ax.multiply(by).subtract(bx.multiply(ay)));
    }

    double sixTimesArea = 3.0 * doubleArea.doubleValue();
    return new PolarCoordinate(x.doubleValue() / sixTimesArea, y.doubleValue() / sixTimesArea, 0);
}

From source file:com.dp2345.entity.Cart.java

/**
 * ??/*  w w  w.  ja  va 2s .c om*/
 * 
 * @param promotion
 *            
 * @return ?
 */
@Transient
private BigDecimal getPrice(Promotion promotion) {
    BigDecimal price = new BigDecimal(0);
    for (CartItem cartItem : getCartItems(promotion)) {
        if (cartItem != null && cartItem.getSubtotal() != null) {
            price = price.add(cartItem.getSubtotal());
        }
    }
    return price;
}

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 {//from w  w w.  j  av a 2  s . com
            price = new BigDecimal("0.00");
            sci.setPounds(new BigDecimal("0.0"));
        }

        sci.setPrice(price);
        total = total.add(sci.getPrice()).setScale(2);
        cart.setTotal(total);
    }
}