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:ca.travelagency.salesstats.InvoiceSales.java

public BigDecimal getCommissionVPayable() {
    if (systemUser == null) {
        return MoneyUtils.ZERO_VALUE;
    }//from  w  w  w. j  a v a2  s.  c  o m
    BigDecimal commissionVerified = getTotalSales().getCommissionVerified();
    BigDecimal commissionRate = new BigDecimal(systemUser.getCommissionRate() / 100);
    return MoneyUtils.round(commissionVerified.multiply(commissionRate));
}

From source file:org.whispersystems.bithub.controllers.GithubController.java

private String getCommitCommentStringForPayment(BigDecimal payment, BigDecimal exchangeRate) {
    if (isViablePaymentAmount(payment)) {
        BigDecimal paymentUsd = payment.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
        return "Thanks! BitHub has sent payment of  $" + paymentUsd.toPlainString() + "USD for this commit.";
    } else {/*  w w w  .ja v  a  2 s. c  o m*/
        return "Thanks! Unfortunately our BitHub balance is $0.00, so no payout can be made.";
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.states.MaintenanceEventStateValidationService.java

private Integer calculatePossibleDeviation(Integer progressTime, BigDecimal possibleDeviationPercent) {
    BigDecimal percent = possibleDeviationPercent.divide(new BigDecimal(100), numberService.getMathContext());
    BigDecimal possibleDeviation = percent.multiply(new BigDecimal(progressTime));
    return possibleDeviation.intValue();
}

From source file:org.apache.hadoop.hive.common.type.HiveIntervalDayTime.java

public void set(BigDecimal totalSecondsBd) {
    long totalSeconds = totalSecondsBd.longValue();
    BigDecimal fractionalSecs = totalSecondsBd.remainder(BigDecimal.ONE);
    int nanos = fractionalSecs.multiply(IntervalDayTimeUtils.NANOS_PER_SEC_BD).intValue();
    set(totalSeconds, nanos);//from   w w  w .j  a  va  2 s. c o  m
}

From source file:org.jumpmind.symmetric.io.data.transform.AdditiveColumnTransform.java

public String transform(IDatabasePlatform platform, DataContext context, TransformColumn column,
        TransformedData data, Map<String, String> sourceValues, String newValue, String oldValue)
        throws IgnoreColumnException, IgnoreRowException {

    BigDecimal multiplier = new BigDecimal(1.00);

    if (StringUtils.isNotBlank(column.getTransformExpression())) {
        multiplier = new BigDecimal(column.getTransformExpression());
    }// w w w  .  j  a  va 2 s. c  o  m

    Table table = platform.getTableFromCache(data.getCatalogName(), data.getSchemaName(), data.getTableName(),
            false);
    if (table == null) {
        if (log.isDebugEnabled()) {
            log.debug("Could not find the target table {}", data.getFullyQualifiedTableName());
        }
        throw new IgnoreColumnException();
    } else if (table.getColumnWithName(column.getTargetColumnName()) == null) {
        if (log.isDebugEnabled()) {
            log.debug("Could not find the target column {}", column.getTargetColumnName());
        }
        throw new IgnoreColumnException();
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Old, new, transform expression as received: " + oldValue + ", " + newValue + ", "
                    + column.getTransformExpression());
        }

        if (!StringUtils.isNotBlank(newValue) || data.getSourceDmlType() == DataEventType.DELETE) {
            newValue = "0";
        }
        if (!StringUtils.isNotBlank(oldValue)) {
            oldValue = "0";
        }

        BigDecimal delta = new BigDecimal(newValue);
        delta = delta.subtract(new BigDecimal(oldValue));
        delta = delta.multiply(multiplier);
        newValue = delta.toString();

        String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn()
                ? platform.getDatabaseInfo().getDelimiterToken()
                : "";
        StringBuilder sql = new StringBuilder(String.format("update %s set %s=%s+(%s) where ",
                getFullyQualifiedTableName(platform, data.getSchemaName(), data.getCatalogName(),
                        data.getTableName()),
                quote + column.getTargetColumnName() + quote, quote + column.getTargetColumnName() + quote,
                newValue));

        String[] keyNames = data.getKeyNames();
        List<Column> columns = new ArrayList<Column>();
        List<String> keyValuesList = new ArrayList<String>();
        boolean addedFirstKey = false;
        for (int i = 0; i < keyNames.length; i++) {
            Column targetCol = table.getColumnWithName(keyNames[i]);
            if (targetCol != null) {
                columns.add(targetCol);
                keyValuesList.add(sourceValues.get(keyNames[i]));
                if (addedFirstKey) {
                    sql.append("and ");
                } else {
                    addedFirstKey = true;
                }
                sql.append(quote);
                sql.append(keyNames[i]);
                sql.append(quote);
                sql.append("=? ");
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("SQL: " + sql);
        }
        ISqlTransaction transaction = context.findTransaction();
        if (0 < transaction.prepareAndExecute(sql.toString(),
                platform.getObjectValues(context.getBatch().getBinaryEncoding(),
                        keyValuesList.toArray(new String[keyValuesList.size()]),
                        columns.toArray(new Column[columns.size()])))) {
            throw new IgnoreColumnException();
        }

    }

    return newValue;
}

From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java

public KmerRangePartition[] getEqualAreaPartitions() {
    KmerRangePartition[] partitions = new KmerRangePartition[this.numPartitions];

    // calc 4^kmerSize
    BigInteger kmerend = BigInteger.valueOf(4).pow(this.kmerSize);
    BigDecimal bdkmerend = new BigDecimal(kmerend);
    // moves between x (0~1) y (0~1)
    // sum of area (0.5)
    double kmerArea = 0.5;
    double sliceArea = kmerArea / this.numPartitions;

    // we think triangle is horizontally flipped so calc get easier.
    double x1 = 0;

    List<BigInteger> widths = new ArrayList<BigInteger>();
    BigInteger widthSum = BigInteger.ZERO;
    for (int i = 0; i < this.numPartitions; i++) {
        // x2*x2 = 2*sliceArea + x1*x1
        double temp = (2 * sliceArea) + (x1 * x1);
        double x2 = Math.sqrt(temp);

        BigDecimal bdx1 = BigDecimal.valueOf(x1);
        BigDecimal bdx2 = BigDecimal.valueOf(x2);

        // if i increases, bdw will be decreased
        BigDecimal bdw = bdx2.subtract(bdx1);

        BigInteger bw = bdw.multiply(bdkmerend).toBigInteger();
        if (bw.compareTo(BigInteger.ZERO) <= 0) {
            bw = BigInteger.ONE;//ww w. j  a v  a  2  s . c  o m
        }

        if (widthSum.add(bw).compareTo(kmerend) > 0) {
            bw = kmerend.subtract(widthSum);
        }

        if (i == this.numPartitions - 1) {
            // last case
            if (widthSum.add(bw).compareTo(kmerend) < 0) {
                bw = kmerend.subtract(widthSum);
            }
        }

        // save it
        widths.add(bw);
        widthSum = widthSum.add(bw);

        x1 = x2;
    }

    BigInteger cur_begin = BigInteger.ZERO;
    for (int i = 0; i < this.numPartitions; i++) {
        BigInteger slice_width = widths.get(this.numPartitions - 1 - i);

        BigInteger slice_begin = cur_begin;

        if (slice_begin.add(slice_width).compareTo(kmerend) > 0) {
            slice_width = kmerend.subtract(slice_begin);
        }

        BigInteger slice_end = cur_begin.add(slice_width).subtract(BigInteger.ONE);

        KmerRangePartition slice = new KmerRangePartition(this.kmerSize, this.numPartitions, i, slice_width,
                slice_begin, slice_end);
        partitions[i] = slice;

        cur_begin = cur_begin.add(slice_width);
    }

    return partitions;
}

From source file:org.whispersystems.bithub.controllers.GithubController.java

private void sendPaymentsFor(Repository repository, List<Commit> commits, BigDecimal balance,
        BigDecimal exchangeRate) {
    for (Commit commit : commits) {
        try {//from www. j a  v a  2 s  .  c o  m
            BigDecimal payout = balance.multiply(payoutRate);

            if (isViablePaymentAmount(payout)) {
                coinbaseClient.sendPayment(commit.getAuthor(), payout, commit.getUrl());
            }

            balance = balance.subtract(payout);

            githubClient.addCommitComment(repository, commit,
                    getCommitCommentStringForPayment(payout, exchangeRate));
        } catch (TransferFailedException e) {
            logger.warn("Transfer failed", e);
        }
    }
}

From source file:org.apache.hive.storage.jdbc.spitter.DecimalIntervalSplitter.java

@Override
public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions,
        TypeInfo typeInfo) {//  www  . j a v  a  2s.c o  m
    List<MutablePair<String, String>> intervals = new ArrayList<>();
    DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo;
    int scale = decimalTypeInfo.getScale();
    BigDecimal decimalLower = new BigDecimal(lowerBound);
    BigDecimal decimalUpper = new BigDecimal(upperBound);
    BigDecimal decimalInterval = (decimalUpper.subtract(decimalLower)).divide(new BigDecimal(numPartitions),
            MathContext.DECIMAL64);
    BigDecimal splitDecimalLower, splitDecimalUpper;
    for (int i = 0; i < numPartitions; i++) {
        splitDecimalLower = decimalLower.add(decimalInterval.multiply(new BigDecimal(i))).setScale(scale,
                RoundingMode.HALF_EVEN);
        splitDecimalUpper = decimalLower.add(decimalInterval.multiply(new BigDecimal(i + 1))).setScale(scale,
                RoundingMode.HALF_EVEN);
        if (splitDecimalLower.compareTo(splitDecimalUpper) < 0) {
            intervals.add(new MutablePair<String, String>(splitDecimalLower.toPlainString(),
                    splitDecimalUpper.toPlainString()));
        }
    }
    return intervals;
}

From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java

private Criterion getPercentRange() {
    BigDecimal bdValue = new BigDecimal(value.toString());

    BigDecimal range = bdValue.multiply(new BigDecimal(diff).divide(new BigDecimal(100)));

    BigDecimal bdValueFrom = bdValue.subtract(range);
    BigDecimal bdValueTo = bdValue.add(range);
    return Restrictions.and(Restrictions.ge(fullKey, bdValueFrom), Restrictions.le(fullKey, bdValueTo));
}

From source file:edu.harvard.hul.ois.fits.EbuCoreNormalizedRatio.java

private void normalizeRatio(String numerator, String denominator) {

    // Verify that the strings passed in are both numbers
    if (!NumberUtils.isNumber(numerator) || !NumberUtils.isNumber(denominator)) {
        return;//from w w w  .  j a  v  a 2s.  co m
    }

    // We only need to normalize the values if one contains a decimal
    if (numerator.contains(DECIMAL) || denominator.contains(DECIMAL)) {
        BigDecimal numBD = new BigDecimal(numerator);
        BigDecimal denomBD = new BigDecimal(denominator);

        double multiplier = getMultiplierForRatio(numBD, denomBD);
        this.normalizedNumerator = numBD.multiply(new BigDecimal(multiplier)).intValue();
        this.normalizedDenominator = denomBD.multiply(new BigDecimal(multiplier)).intValue();

    }
    // Must be an integer
    else {
        // set the denormalized value
        this.normalizedNumerator = new Integer(numerator).intValue();
        this.normalizedDenominator = new Integer(denominator).intValue();
    }

}