Example usage for java.math BigDecimal multiply

List of usage examples for java.math BigDecimal multiply

Introduction

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

Prototype

public BigDecimal multiply(BigDecimal multiplicand) 

Source Link

Document

Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()) .

Usage

From source file:com.marcosanta.service.impl.KalturaServiceImpl.java

private int GeneraReporte2(List<CatReporteXls> reporteGlobal, List<Object[]> objs, int totalentrys,
        String nombre, String valorUnitarioMIN, String valorUnitarioTam, String cuenta) {
    for (Object[] obj : objs) {
        SistemaReporte sr = new SistemaReporte((String) obj[0], (Integer) obj[1], (long) obj[2], (long) obj[3],
                (String) obj[4], (String) obj[5], (String) obj[6], (Date) obj[7]);
        sr.setNombre(sr.getEntryId());//from   w  ww.  ja  va  2s. co m
        sr.setDuracion(0L);
        sr.setFechaCorte(new Date());
        BigDecimal tamanioDeci = new BigDecimal(sr.getTamanio())
                .divide(new BigDecimal(1024), MathContext.DECIMAL128)
                .divide(new BigDecimal(1024), MathContext.DECIMAL128);
        BigDecimal taDeci = new BigDecimal(sr.getTamanio()).divide(new BigDecimal(1024), MathContext.DECIMAL128)
                .divide(new BigDecimal(1024), MathContext.DECIMAL128);
        if (reporteGlobal.contains(new CatReporteXls(sr.getNombre()))) {
            CatReporteXls caRepTmp = reporteGlobal
                    .get(reporteGlobal.indexOf(new CatReporteXls(sr.getNombre())));
            caRepTmp.setMinVistos(caRepTmp.getMinVistos().add(new BigDecimal(sr.getTiempoVisto())));
            caRepTmp.setDuration(caRepTmp.getDuration().add(new BigDecimal(sr.getDuracion())));
            caRepTmp.setTamanio(caRepTmp.getTamanio().add(tamanioDeci));
            caRepTmp.setTotalEntrys(new BigDecimal(totalentrys));
            caRepTmp.setTamUni(caRepTmp.getTamUni()
                    .add(tamanioDeci.multiply(new BigDecimal(Double.parseDouble(valorUnitarioTam)))));
            caRepTmp.setMinVisUni(caRepTmp.getMinVisUni().add(new BigDecimal(sr.getTiempoVisto())));
        } else {
            reporteGlobal.add(new CatReporteXls(sr.getNombre(), sr.getNombre(), sr.getNombreFabrica(),
                    sr.getNombrePrograma(), cuenta, sr.getNombre(), sr.getNombreUnidad(), tamanioDeci,
                    new BigDecimal(sr.getDuracion()), new BigDecimal(sr.getTiempoVisto()), sr.getFechaCorte(),
                    sr.getFechaCreacion(),
                    new BigDecimal(sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)),
                    new BigDecimal(tamanioDeci.floatValue() * Double.parseDouble(valorUnitarioTam)),
                    new BigDecimal(totalentrys)));

        }
        totalentrys++;
    }
    return totalentrys;
}

From source file:org.apache.fineract.portfolio.loanaccount.domain.LoanCharge.java

public void update(final BigDecimal amount, final LocalDate dueDate, final BigDecimal loanPrincipal,
        Integer numberOfRepayments, BigDecimal loanCharge) {
    if (dueDate != null) {
        this.dueDate = dueDate.toDate();
    }/* w w  w .  j  a  v  a  2 s.c o  m*/

    if (amount != null) {
        switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
            break;
        case FLAT:
            if (isInstalmentFee()) {
                if (numberOfRepayments == null) {
                    numberOfRepayments = this.loan.fetchNumberOfInstallmensAfterExceptions();
                }
                this.amount = amount.multiply(BigDecimal.valueOf(numberOfRepayments));
            } else {
                this.amount = amount;
            }
            break;
        case PERCENT_OF_AMOUNT:
        case PERCENT_OF_AMOUNT_AND_INTEREST:
        case PERCENT_OF_INTEREST:
        case PERCENT_OF_DISBURSEMENT_AMOUNT:
            this.percentage = amount;
            this.amountPercentageAppliedTo = loanPrincipal;
            if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
                loanCharge = percentageOf(this.amountPercentageAppliedTo);
            }
            this.amount = minimumAndMaximumCap(loanCharge);
            break;
        }
        this.amountOrPercentage = amount;
        this.amountOutstanding = calculateOutstanding();
        if (this.loan != null && isInstalmentFee()) {
            updateInstallmentCharges();
        }
    }
}

From source file:org.kuali.kfs.module.bc.document.service.impl.SalarySettingServiceImpl.java

/**
 * @see org.kuali.kfs.module.bc.document.service.SalarySettingService#calculateFteQuantity(java.lang.Integer, java.lang.Integer,
 *      java.math.BigDecimal)// w  w  w. java2  s  . co  m
 */
public BigDecimal calculateFteQuantity(Integer payMonth, Integer fundingMonth,
        BigDecimal requestedTimePercent) {
    LOG.debug("calculateFteQuantity() start");

    if (payMonth == null || fundingMonth == null || requestedTimePercent == null) {
        return BigDecimal.ZERO;
    }

    BigDecimal payMonthAsDecimal = BigDecimal.valueOf(payMonth);
    BigDecimal fundingMonthAsDecimal = BigDecimal.valueOf(fundingMonth);
    BigDecimal fundingMonthPercent = fundingMonthAsDecimal.divide(payMonthAsDecimal, 5,
            BigDecimal.ROUND_HALF_UP);

    BigDecimal fteQuantity = requestedTimePercent.multiply(fundingMonthPercent)
            .divide(KFSConstants.ONE_HUNDRED.bigDecimalValue());

    return fteQuantity.setScale(5, BigDecimal.ROUND_HALF_UP);
}

From source file:com.marcosanta.service.impl.KalturaServiceImpl.java

private int GeneraReporte(List<CatReporteXls> reporteGlobal, List<CatReporteXls> reporteEntrys,
        List<Object[]> objs, int totalentrys, String nombre, String valorUnitarioMIN, String valorUnitarioTam,
        String partnerId) {/*from   www . j  a v a 2 s  .  co m*/
    for (Object[] obj : objs) {
        SistemaReporte sr = new SistemaReporte((String) obj[0], (int) obj[1], (long) obj[2]);
        sr.setDuracion(0L);
        sr.setFechaCorte(new Date());
        BigDecimal tamanioDeci = new BigDecimal(sr.getTamanio())
                .divide(new BigDecimal(1024), MathContext.DECIMAL128)
                .divide(new BigDecimal(1024), MathContext.DECIMAL128);
        BigDecimal taDeci = new BigDecimal(sr.getTamanio()).divide(new BigDecimal(1024), MathContext.DECIMAL128)
                .divide(new BigDecimal(1024), MathContext.DECIMAL128);
        if (reporteGlobal.contains(new CatReporteXls(nombre))) {
            reporteEntrys.add(new CatReporteXls(sr.getEntryId(), partnerId));
            CatReporteXls caRepTmp = reporteGlobal.get(reporteGlobal.indexOf(new CatReporteXls(nombre)));
            caRepTmp.setMinVistos(caRepTmp.getMinVistos().add(new BigDecimal(sr.getTiempoVisto())));
            caRepTmp.setDuration(caRepTmp.getDuration().add(new BigDecimal(sr.getDuracion())));
            caRepTmp.setTamanio(caRepTmp.getTamanio().add(tamanioDeci));
            caRepTmp.setTotalEntrys(new BigDecimal(totalentrys));
            caRepTmp.setTamUni(caRepTmp.getTamUni()
                    .add(tamanioDeci.multiply(new BigDecimal(Double.parseDouble(valorUnitarioTam)))));
            caRepTmp.setMinVisUni(caRepTmp.getMinVisUni().add(new BigDecimal(sr.getTiempoVisto())));
        } else {
            reporteEntrys.add(new CatReporteXls(sr.getEntryId(), partnerId));
            reporteGlobal.add(new CatReporteXls(nombre, new BigDecimal(sr.getTiempoVisto()), tamanioDeci,
                    new BigDecimal(sr.getDuracion()), sr.getFechaCorte(),
                    new BigDecimal(sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)),
                    new BigDecimal(tamanioDeci.floatValue() * Double.parseDouble(valorUnitarioTam)),
                    new BigDecimal(totalentrys)));

        }
        totalentrys++;
    }
    return totalentrys;
}

From source file:org.kuali.kfs.module.bc.document.service.impl.SalarySettingServiceImpl.java

/**
 * @see org.kuali.kfs.module.bc.document.service.SalarySettingService#calculateCSFFteQuantity(java.lang.Integer,
 *      java.lang.Integer, java.math.BigDecimal)
 *//*from w w w  .  j  a  va 2 s.co  m*/
public BigDecimal calculateCSFFteQuantity(Integer payMonth, Integer normalWorkMonth,
        BigDecimal requestedCSFTimePercent) {
    LOG.debug("calculateCSFFteQuantity() start");

    if (payMonth == null || normalWorkMonth == null || requestedCSFTimePercent == null) {
        return BigDecimal.ZERO;
    }

    BigDecimal payMonthAsDecimal = BigDecimal.valueOf(payMonth);
    BigDecimal normalMonthAsDecimal = BigDecimal.valueOf(normalWorkMonth);
    BigDecimal fundingMonthPercent = normalMonthAsDecimal.divide(payMonthAsDecimal, 5,
            BigDecimal.ROUND_HALF_UP);

    BigDecimal fteQuantity = requestedCSFTimePercent.multiply(fundingMonthPercent)
            .divide(KFSConstants.ONE_HUNDRED.bigDecimalValue());

    return fteQuantity.setScale(5, BigDecimal.ROUND_HALF_UP);
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * Trigonometric cosine./*from w w w  . j a  va  2s.  co m*/
 *
 * @param x The argument in radians.
 * @return cos(x) in the range -1 to 1.
 */
static public BigDecimal cos(final BigDecimal x) {
    if (x.compareTo(BigDecimal.ZERO) < 0) {
        return cos(x.negate());
    } else if (x.compareTo(BigDecimal.ZERO) == 0) {
        return BigDecimal.ONE;
    } else {
        /* reduce modulo 2pi
         */
        BigDecimal res = mod2pi(x);
        double errpi = 0.5 * Math.abs(x.ulp().doubleValue());
        int val = +err2prec(FastMath.PI, errpi);
        MathContext mc = new MathContext(val);
        BigDecimal p = pi(mc);
        mc = new MathContext(x.precision());
        if (res.compareTo(p) > 0) {
            /* pi<x<=2pi: cos(x)= - cos(x-pi)
             */
            return cos(subtractRound(res, p)).negate();
        } else if (res.multiply(new BigDecimal("2")).compareTo(p) > 0) {
            /* pi/2<x<=pi: cos(x)= -cos(pi-x)
             */
            return cos(subtractRound(p, res)).negate();
        } else {
            /* for the range 0<=x<Pi/2 one could use cos(2x)= 1-2*sin^2(x)
             * to split this further, or use the cos up to pi/4 and the sine higher up.
            throw new ProviderException("Unimplemented cosine ") ;
             */
            if (res.multiply(new BigDecimal("4")).compareTo(p) > 0) {
                /* x>pi/4: cos(x) = sin(pi/2-x)
                 */
                return sin(subtractRound(p.divide(new BigDecimal("2")), res));
            } else {
                /* Simple Taylor expansion, sum_{i=0..infinity} (-1)^(..)res^(2i)/(2i)! */
                BigDecimal resul = BigDecimal.ONE;
                /* x^i */
                BigDecimal xpowi = BigDecimal.ONE;
                /* 2i factorial */
                BigInteger ifac = BigInteger.ONE;
                /* The absolute error in the result is the error in x^2/2 which is x times the error in x.
                 */
                double xUlpDbl = 0.5 * res.ulp().doubleValue() * res.doubleValue();
                /* The error in the result is set by the error in x^2/2 itself, xUlpDbl.
                 * We need at most k terms to push x^(2k+1)/(2k+1)! below this value.
                 * x^(2k) < xUlpDbl; (2k)*log(x) < log(xUlpDbl);
                 */
                int k = (int) (Math.log(xUlpDbl) / Math.log(res.doubleValue())) / 2;
                MathContext mcTay = new MathContext(err2prec(1., xUlpDbl / k));
                for (int i = 1;; i++) {
                    /* TBD: at which precision will 2*i-1 or 2*i overflow?
                     */
                    ifac = ifac.multiply(new BigInteger("" + (2 * i - 1)));
                    ifac = ifac.multiply(new BigInteger("" + (2 * i)));
                    xpowi = xpowi.multiply(res).multiply(res).negate();
                    BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
                    resul = resul.add(corr);
                    if (corr.abs().doubleValue() < 0.5 * xUlpDbl) {
                        break;
                    }
                }
                /* The error in the result is governed by the error in x itself.
                 */
                mc = new MathContext(err2prec(resul.doubleValue(), xUlpDbl));
                return resul.round(mc);
            }
        }
    }
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * Trigonometric sine.//from   w ww  .  ja va2  s  .co  m
 *
 * @param x The argument in radians.
 * @return sin(x) in the range -1 to 1.
 */
static public BigDecimal sin(final BigDecimal x) {
    if (x.compareTo(BigDecimal.ZERO) < 0) {
        return sin(x.negate()).negate();
    } else if (x.compareTo(BigDecimal.ZERO) == 0) {
        return BigDecimal.ZERO;
    } else {
        /* reduce modulo 2pi
         */
        BigDecimal res = mod2pi(x);
        double errpi = 0.5 * Math.abs(x.ulp().doubleValue());
        int val = 2 + err2prec(FastMath.PI, errpi);
        MathContext mc = new MathContext(val);
        BigDecimal p = pi(mc);
        mc = new MathContext(x.precision());
        if (res.compareTo(p) > 0) {
            /* pi<x<=2pi: sin(x)= - sin(x-pi)
             */
            return sin(subtractRound(res, p)).negate();
        } else if (res.multiply(new BigDecimal("2")).compareTo(p) > 0) {
            /* pi/2<x<=pi: sin(x)= sin(pi-x)
             */
            return sin(subtractRound(p, res));
        } else {
            /* for the range 0<=x<Pi/2 one could use sin(2x)=2sin(x)cos(x)
             * to split this further. Here, use the sine up to pi/4 and the cosine higher up.
             */
            if (res.multiply(new BigDecimal("4")).compareTo(p) > 0) {
                /* x>pi/4: sin(x) = cos(pi/2-x)
                 */
                return cos(subtractRound(p.divide(new BigDecimal("2")), res));
            } else {
                /* Simple Taylor expansion, sum_{i=1..infinity} (-1)^(..)res^(2i+1)/(2i+1)! */
                BigDecimal resul = res;
                /* x^i */
                BigDecimal xpowi = res;
                /* 2i+1 factorial */
                BigInteger ifac = BigInteger.ONE;
                /* The error in the result is set by the error in x itself.
                 */
                double xUlpDbl = res.ulp().doubleValue();
                /* The error in the result is set by the error in x itself.
                 * We need at most k terms to squeeze x^(2k+1)/(2k+1)! below this value.
                 * x^(2k+1) < x.ulp; (2k+1)*log10(x) < -x.precision; 2k*log10(x)< -x.precision;
                 * 2k*(-log10(x)) > x.precision; 2k*log10(1/x) > x.precision
                 */
                int k = (int) (res.precision() / Math.log10(1.0 / res.doubleValue())) / 2;
                MathContext mcTay = new MathContext(err2prec(res.doubleValue(), xUlpDbl / k));
                for (int i = 1;; i++) {
                    /* TBD: at which precision will 2*i or 2*i+1 overflow?
                     */
                    ifac = ifac.multiply(new BigInteger("" + (2 * i)));
                    ifac = ifac.multiply(new BigInteger("" + (2 * i + 1)));
                    xpowi = xpowi.multiply(res).multiply(res).negate();
                    BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
                    resul = resul.add(corr);
                    if (corr.abs().doubleValue() < 0.5 * xUlpDbl) {
                        break;
                    }
                }
                /* The error in the result is set by the error in x itself.
                 */
                mc = new MathContext(res.precision());
                return resul.round(mc);
            }
        }
    } /* sin */
}

From source file:fr.bmartel.speedtest.SpeedTestTask.java

/**
 * get a download/upload report./*from w  w w .j  a va 2  s. c om*/
 *
 * @param mode speed test mode requested
 * @return speed test report
 */
public SpeedTestReport getReport(final SpeedTestMode mode) {

    BigDecimal temporaryPacketSize = BigDecimal.ZERO;
    BigDecimal totalPacketSize = BigDecimal.ZERO;

    switch (mode) {
    case DOWNLOAD:
        temporaryPacketSize = new BigDecimal(mDownloadTemporaryPacketSize);
        totalPacketSize = mDownloadPckSize;
        break;
    case UPLOAD:
        temporaryPacketSize = new BigDecimal(mUploadTempFileSize);
        totalPacketSize = mUploadFileSize;
        break;
    default:
        break;
    }

    long currentTime;
    if (mTimeEnd == 0) {
        currentTime = System.currentTimeMillis();
    } else {
        currentTime = mTimeEnd;
    }

    BigDecimal transferRateOps = BigDecimal.ZERO;

    final int scale = mSocketInterface.getDefaultScale();
    final RoundingMode roundingMode = mSocketInterface.getDefaultRoundingMode();

    if (shallCalculateTransferRate(currentTime, mode)) {
        transferRateOps = temporaryPacketSize.divide(new BigDecimal(currentTime - mTimeStart)
                .divide(SpeedTestConst.MILLIS_DIVIDER, scale, roundingMode), scale, roundingMode);
    }

    final BigDecimal transferRateBitps = transferRateOps.multiply(SpeedTestConst.BIT_MULTIPLIER);

    BigDecimal percent = BigDecimal.ZERO;

    SpeedTestReport report;

    if (mRepeatWrapper.isRepeat()) {

        report = mRepeatWrapper.getRepeatReport(scale, roundingMode, mode, currentTime, transferRateOps);

    } else {

        if (totalPacketSize != BigDecimal.ZERO) {

            percent = temporaryPacketSize.multiply(SpeedTestConst.PERCENT_MAX).divide(totalPacketSize, scale,
                    roundingMode);
        }

        report = new SpeedTestReport(mode, percent.floatValue(), mTimeStart, currentTime,
                temporaryPacketSize.longValueExact(), totalPacketSize.longValueExact(), transferRateOps,
                transferRateBitps, 1);
    }
    return report;
}

From source file:org.kuali.ole.select.businessobject.OleInvoiceItem.java

public BigDecimal calculateItemExtendedPrice() {
    BigDecimal extendedPrice = BigDecimal.ZERO;
    BigDecimal itemUnitPrice = getItemUnitPrice();
    if (ObjectUtils.isNotNull(itemUnitPrice)) {
        if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
            // SERVICE ITEM: return unit price as extended price
            extendedPrice = itemUnitPrice;
        } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
            BigDecimal calcExtendedPrice = itemUnitPrice.multiply(this.getItemQuantity().bigDecimalValue());
            // ITEM TYPE (qty driven): return (unitPrice x qty)
            extendedPrice = calcExtendedPrice.setScale(4, KualiDecimal.ROUND_BEHAVIOR);
        }//  w w w .j  a v  a 2 s. co m
    }
    return extendedPrice;
}

From source file:com.lp.server.artikel.fastlanereader.ArtikellisteHandler.java

protected void prepareVkPreis(HashMap hmRabattsatzFixpreis, HashMap hmPreisbasis, Object[] source,
        Object[] target) {/*ww  w .jav a2 s .c  o m*/
    // VK-Preis Berechnen
    BigDecimal vkPreis = null;

    BigDecimal vkPreisbasis = new BigDecimal(0);
    BigDecimal vkRabattsatz = new BigDecimal(0);
    BigDecimal vkFixpreis = new BigDecimal(0);

    if (hmRabattsatzFixpreis.containsKey(source[0])) {
        Object[] oTemp = (Object[]) hmRabattsatzFixpreis.get(source[0]);
        vkRabattsatz = (BigDecimal) oTemp[1];
        vkFixpreis = (BigDecimal) oTemp[2];
    }
    if (hmPreisbasis.containsKey(source[0])) {
        vkPreisbasis = (BigDecimal) hmPreisbasis.get(source[0]);
    }

    if (vkFixpreis != null) {
        vkPreis = vkFixpreis;
    } else {
        if (vkRabattsatz != null && vkPreisbasis != null) {
            BigDecimal bdRabattsumme = vkPreisbasis.multiply(vkRabattsatz.movePointLeft(2));
            vkPreis = vkPreisbasis.subtract(bdRabattsumme);
        } else {
            vkPreis = vkPreisbasis;
        }
    }
    target[getTableColumnInformation().getViewIndex("lp.preis")] = vkPreis;
}