Example usage for java.math BigDecimal ROUND_DOWN

List of usage examples for java.math BigDecimal ROUND_DOWN

Introduction

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

Prototype

int ROUND_DOWN

To view the source code for java.math BigDecimal ROUND_DOWN.

Click Source Link

Document

Rounding mode to round towards zero.

Usage

From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java

public static Date parseTimelineHour(final String hourString, final int year) {
    final BigDecimal hours = NumberUtils.parseQuietDecimal(hourString);
    if (hours == null)
        return null;

    // REMARK: we read the calculation core time with the time zone, as defined in Kalypso Preferences
    final Calendar calendar = Calendar.getInstance(KalypsoCorePlugin.getDefault().getTimeZone());
    calendar.clear();/*from  ww  w. j a va2s .c  om*/
    calendar.set(year, 0, 1);

    BigDecimal wholeHours = hours.setScale(0, BigDecimal.ROUND_DOWN);
    final BigDecimal wholeMinutes = hours.subtract(wholeHours).multiply(new BigDecimal("60")); //$NON-NLS-1$
    if (wholeHours.intValue() > 1) {
        wholeHours = new BigDecimal(wholeHours.intValue() - 1);
    }
    calendar.add(Calendar.HOUR, wholeHours.intValue());
    calendar.add(Calendar.MINUTE, wholeMinutes.intValue());

    final boolean lBoolLeapYear = DateUtilities.isLeapYear(calendar);
    if (lBoolLeapYear && calendar.get(Calendar.DAY_OF_YEAR) > 59) {
        calendar.clear();
        calendar.set(year, 0, 1);
        calendar.add(Calendar.HOUR, wholeHours.intValue() - 24);
        calendar.add(Calendar.MINUTE, wholeMinutes.intValue());
    }

    return calendar.getTime();
}

From source file:org.kawanfw.sql.jdbc.CallableStatementHttp.java

@Override
public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
    testIfClosed();/*from   w  ww. j a  v  a  2 s. c  o m*/

    if (scale < 0) {
        throw new SQLException("invalid scale: " + scale + ". Scale must be >= 0");
    }

    BigDecimal bd = (BigDecimal) callableStatementHolder.getParameter(parameterIndex);

    if (bd != null) {
        bd = bd.setScale(scale, BigDecimal.ROUND_DOWN);
    }

    return bd;

}

From source file:org.kawanfw.sql.jdbc.ResultSetHttp.java

/**
 * Retrieves the value of the designated column in the current row of this
 * <code>ResultSet</code> object as a <code>java.sql.BigDecimal</code> in
 * the Java programming language./*  w  ww.  j a  va2 s.co  m*/
 * 
 * @param columnIndex
 *            the first column is 1, the second is 2, ...
 * @param scale
 *            the number of digits to the right of the decimal point
 * @return the column value; if the value is SQL <code>NULL</code>, the
 *         value returned is <code>null</code>
 * @exception SQLException
 *                if a database access error occurs
 * @deprecated
 */
@Override
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {

    if (scale < 0) {
        throw new SQLException("invalid scale: " + scale + ". Scale must be >= 0");
    }

    BigDecimal bd = getBigDecimal(columnIndex);

    if (bd != null) {
        bd = bd.setScale(scale, BigDecimal.ROUND_DOWN);
    }

    return bd;
}

From source file:org.kuali.kfs.gl.batch.service.impl.PosterServiceImpl.java

/**
 * Generates a percent of a KualiDecimal amount (great for finding out how much of an origin entry should be recouped by
 * indirect cost recovery)//from   www  .  ja  v  a2  s .co  m
 *
 * @param amount the original amount
 * @param percent the percentage of that amount to calculate
 * @return the percent of the amount
 */
protected KualiDecimal getPercentage(KualiDecimal amount, BigDecimal percent) {
    BigDecimal result = amount.bigDecimalValue().multiply(percent).divide(BDONEHUNDRED, 2,
            BigDecimal.ROUND_DOWN);
    return new KualiDecimal(result);
}

From source file:org.kuali.kfs.module.ar.document.service.impl.ContractsGrantsInvoiceDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.document.service.ContractsGrantsInvoiceDocumentService#prorateBill(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)
 *///from ww w . ja  va 2  s . c  om
@Override
public void prorateBill(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument)
        throws WorkflowException {
    KualiDecimal totalCost = new KualiDecimal(0); // Amount to be billed on this invoice
    // must iterate through the invoice details because the user might have manually changed the value
    for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
        totalCost = totalCost.add(invD.getInvoiceAmount());
    }
    KualiDecimal billedTotalCost = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail()
            .getTotalPreviouslyBilled(); // Total Billed so far
    KualiDecimal accountAwardTotal = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAwardTotal(); // AwardTotal

    if (accountAwardTotal.subtract(billedTotalCost).isGreaterEqual(new KualiDecimal(0))) {
        KualiDecimal amountEligibleForBilling = accountAwardTotal.subtract(billedTotalCost);
        // only recalculate if the current invoice is over what's billable.

        if (totalCost.isGreaterThan(amountEligibleForBilling)) {
            // use BigDecimal because percentage should not have only a scale of 2, we need more for accuracy
            BigDecimal percentage = amountEligibleForBilling.bigDecimalValue()
                    .divide(totalCost.bigDecimalValue(), 10, BigDecimal.ROUND_HALF_DOWN);
            KualiDecimal amountToBill = new KualiDecimal(0); // use to check if rounding has left a few cents off

            ContractsGrantsInvoiceDetail largestCostCategory = null;
            BigDecimal largestAmount = BigDecimal.ZERO;
            for (ContractsGrantsInvoiceDetail invD : contractsGrantsInvoiceDocument.getInvoiceDetails()) {
                BigDecimal newValue = invD.getInvoiceAmount().bigDecimalValue().multiply(percentage);
                KualiDecimal newKualiDecimalValue = new KualiDecimal(
                        newValue.setScale(2, BigDecimal.ROUND_DOWN));
                invD.setInvoiceAmount(newKualiDecimalValue);
                amountToBill = amountToBill.add(newKualiDecimalValue);
                if (newValue.compareTo(largestAmount) > 0) {
                    largestAmount = newKualiDecimalValue.bigDecimalValue();
                    largestCostCategory = invD;
                }
            }
            if (!amountToBill.equals(amountEligibleForBilling)) {
                KualiDecimal remaining = amountEligibleForBilling.subtract(amountToBill);
                if (ObjectUtils.isNull(largestCostCategory)
                        && CollectionUtils.isNotEmpty(contractsGrantsInvoiceDocument.getInvoiceDetails())) {
                    largestCostCategory = contractsGrantsInvoiceDocument.getInvoiceDetails().get(0);
                }
                if (ObjectUtils.isNotNull(largestCostCategory)) {
                    largestCostCategory.setInvoiceAmount(largestCostCategory.getInvoiceAmount().add(remaining));
                }
            }
            recalculateTotalAmountBilledToDate(contractsGrantsInvoiceDocument);
        }
    }
}

From source file:org.kuali.kpme.core.earncode.service.EarnCodeServiceImpl.java

@Override
public BigDecimal roundHrsWithEarnCode(BigDecimal hours, EarnCodeContract earnCode) {
    String roundOption = HrConstants.ROUND_OPTION_MAP.get(earnCode.getRoundingOption());
    BigDecimal fractScale = new BigDecimal(earnCode.getFractionalTimeAllowed());
    if (roundOption == null) {
        LOG.error("Rounding option of Earn Code " + earnCode.getEarnCode() + " is not recognized.");
        return null;
        //         throw new RuntimeException("Rounding option of Earn Code " + earnCode.getEarnCode() + " is not recognized.");
    }/*from  w w w .  j a v  a  2  s . com*/
    BigDecimal roundedHours = hours;
    if (roundOption.equals("Traditional")) {
        roundedHours = hours.setScale(fractScale.scale(), BigDecimal.ROUND_HALF_EVEN);
    } else if (roundOption.equals("Truncate")) {
        roundedHours = hours.setScale(fractScale.scale(), BigDecimal.ROUND_DOWN);
    }
    return roundedHours;
}

From source file:org.libreplan.business.qualityforms.entities.QualityForm.java

private void updatePercentageByItems() {
    if (qualityFormItems.size() > 0) {
        BigDecimal percentageTotal = new BigDecimal(100).setScale(2);
        BigDecimal numItems = new BigDecimal(qualityFormItems.size()).setScale(2);
        BigDecimal percentageByItem = percentageTotal.divide(numItems, 2, BigDecimal.ROUND_DOWN);
        for (QualityFormItem item : qualityFormItems) {
            item.setPercentage(percentageByItem);
        }/*  w  w w. java  2 s.  c om*/

        // Calculate the division remainder
        BigDecimal sumByItems = (percentageByItem.multiply(numItems)).setScale(2);
        BigDecimal remainder = (percentageTotal.subtract(sumByItems)).setScale(2);
        QualityFormItem lastItem = qualityFormItems.get(qualityFormItems.size() - 1);
        BigDecimal lastPercentage = (lastItem.getPercentage().add(remainder)).setScale(2);
        lastItem.setPercentage(lastPercentage);
    }
}

From source file:org.libreplan.web.orders.HoursGroupWrapper.java

private BigDecimal getPercentageInOrderLineGroup(Integer workHours) {
    BigDecimal workingHours = new BigDecimal(hoursGroup.getWorkingHours()).setScale(2);
    BigDecimal total = new BigDecimal(workHours).setScale(2);

    return total.equals(new BigDecimal(0).setScale(2)) ? new BigDecimal(0).setScale(2)
            : workingHours.divide(total, BigDecimal.ROUND_DOWN).scaleByPowerOfTen(2);
}

From source file:org.libreplan.web.orders.HoursGroupWrapper.java

public void setPercentage(BigDecimal percentage) {
    if (percentage != null) {
        BigDecimal proportion = percentage.divide(new BigDecimal(100), BigDecimal.ROUND_DOWN);
        hoursGroup.setPercentage(proportion);
    } else {/*from   w w  w . j  a v  a  2 s.  com*/
        hoursGroup.setPercentage(new BigDecimal(0).setScale(2));
    }

}

From source file:org.netxilia.functions.MathFunctions.java

public double ROUNDDOWN(double number, int count) {
    return MathUtils.round(number, count, BigDecimal.ROUND_DOWN);
}