Example usage for java.math RoundingMode HALF_EVEN

List of usage examples for java.math RoundingMode HALF_EVEN

Introduction

In this page you can find the example usage for java.math RoundingMode HALF_EVEN.

Prototype

RoundingMode HALF_EVEN

To view the source code for java.math RoundingMode HALF_EVEN.

Click Source Link

Document

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

Usage

From source file:org.apache.hadoop.hbase.client.coprocessor.BigDecimalColumnInterpreter.java

@Override
public BigDecimal getValue(byte[] family, byte[] qualifier, KeyValue kv) throws IOException {
    if ((kv == null || kv.getValue() == null))
        return null;
    return Bytes.toBigDecimal(kv.getValue()).setScale(2, RoundingMode.HALF_EVEN);
}

From source file:org.apache.hadoop.hbase.client.coprocessor.BigDecimalColumnInterpreter.java

@Override
public BigDecimal add(BigDecimal val1, BigDecimal val2) {
    if ((((val1 == null) ? 1 : 0) ^ ((val2 == null) ? 1 : 0)) != 0) {
        return ((val1 == null) ? val2 : val1);
    }//from   w  w  w. j  ava 2 s.c  o  m
    if (val1 == null)
        return null;
    return val1.add(val2).setScale(2, RoundingMode.HALF_EVEN);
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static String formatNumber(BigDecimal value) {
    if (value == null || value.equals(BigDecimal.ZERO)) {
        return "0";
    } else {/*from  w  w  w  .ja  v  a  2s .  c  om*/
        NumberFormat formater = NumberFormat.getInstance();
        formater.setMaximumFractionDigits(0);
        formater.setMinimumFractionDigits(0);
        return formater.format(value.setScale(0, RoundingMode.HALF_EVEN));
    }
}

From source file:org.mifos.reports.branchreport.BranchReportClientSummaryBO.java

public BranchReportClientSummaryBO(String fieldName, BigDecimal total, BigDecimal veryPoorTotal) {
    this.fieldName = fieldName;
    this.total = total.setScale(2, RoundingMode.HALF_EVEN).toPlainString();
    if (veryPoorTotal != null) {
        this.veryPoorTotal = veryPoorTotal.setScale(2, RoundingMode.HALF_EVEN).toPlainString();
    }/*from  w w  w . j  av  a  2 s  .co m*/
}

From source file:org.apache.hadoop.hbase.client.coprocessor.BigDecimalColumnInterpreter.java

@Override
public BigDecimal multiply(BigDecimal val1, BigDecimal val2) {
    return (((val1 == null) || (val2 == null)) ? null
            : val1.multiply(val2).setScale(2, RoundingMode.HALF_EVEN));
}

From source file:org.fenixedu.academic.domain.accounting.events.gratuity.ExternalScholarshipGratuityExemption.java

public BigDecimal calculateDiscountPercentage(Money amount) {
    final BigDecimal amountToDiscount = new BigDecimal(getValue().toString());
    return amountToDiscount.divide(amount.getAmount(), 10, RoundingMode.HALF_EVEN);
}

From source file:org.amanzi.awe.statistics.ui.table.StatisticsLabelProvider.java

@Override
public String getColumnText(final Object element, int columnIndex) {
    if (columnIndex == 0) {
        return StringUtils.EMPTY;
    } else {/*from w w w .  j ava  2s  .com*/
        columnIndex--;
    }

    if (element instanceof IStatisticsRow) {
        final IStatisticsRow statisticsRow = (IStatisticsRow) element;

        if (!statisticsRow.equals(previousRow)) {
            initializeCellList(statisticsRow);

            previousRow = statisticsRow;
        }

        switch (columnIndex) {
        case 0:
            return statisticsRow.getStatisticsGroup().getPropertyValue();
        case 1:
            return getStatisticsRowName(statisticsRow);
        default:
            final Number value = cellList.get(columnIndex - 2).getValue();
            if (value != null) {
                final float floatValue = value.floatValue();
                final BigDecimal bd = new BigDecimal(floatValue).setScale(DECIMAL_SIZE, RoundingMode.HALF_EVEN);
                return bd.toString();
            }
        }
    }

    return StringUtils.EMPTY;
}

From source file:biz.c24.io.spring.integration.samples.fpml.FpmlGenerator.java

private static TradeConfirmed randomizeFpML(TradeConfirmed tradeConfirmed) throws CloneNotSupportedException {
    ISO8601DateTime creationDate = new ISO8601DateTime(new Date());
    ISO8601Date tradeDate = new ISO8601Date(new GregorianCalendar(2011, Calendar.JULY, 5).getTime());
    ISO8601Date expiryDate = new ISO8601Date(new GregorianCalendar(2012, Calendar.JANUARY, 5).getTime());
    ISO8601Date settlementDate = new ISO8601Date(new GregorianCalendar(2011, Calendar.JULY, 7).getTime());
    ISO8601Date valueDate = new ISO8601Date(new GregorianCalendar(2012, Calendar.JANUARY, 9).getTime());

    Random random = new Random();

    BigDecimal putAmount = new BigDecimal((1 + random.nextInt(999)) * 100000.);
    BigDecimal callAmount = new BigDecimal((1 + random.nextInt(999)) * 100000.);
    BigDecimal fxRate = callAmount.divide(putAmount, 8, RoundingMode.HALF_EVEN).setScale(5,
            BigDecimal.ROUND_HALF_UP);
    BigDecimal premiumValue = new BigDecimal(0.001).setScale(5, BigDecimal.ROUND_HALF_UP);
    BigDecimal premiumAmount = callAmount.multiply(premiumValue).setScale(2, BigDecimal.ROUND_HALF_UP);

    String sendTo = "SendTo" + random.nextInt(999999);
    String sentBy = "SentBy" + random.nextInt(999999);
    String msgId = "Msg" + random.nextInt(999999);
    String conversationId = "Conv" + random.nextInt(999999);
    String tradeId1 = "ID1:" + random.nextInt(999999);
    String tradeId2 = "ID2:" + random.nextInt(999999);

    // Set the header
    NotificationMessageHeader header = tradeConfirmed.getHeader();
    header.getMessageHeadermodel().setCreationTimestamp(creationDate);
    header.getConversationId().setValue(conversationId);
    header.getMessageId().setValue(msgId);
    header.getMessageHeadermodel().getSentBy().setValue(sentBy);
    header.getMessageHeadermodel().getSendTo()[0].setValue(sendTo);

    // Set the TradeHeader
    TradeHeader tradeHeader = tradeConfirmed.getTrade().getTradeHeader();
    tradeHeader.getPartyTradeIdentifier()[0].getTradeIdentifierSG1()[0].getTradeId().setValue(tradeId1);
    tradeHeader.getPartyTradeIdentifier()[1].getTradeIdentifierSG1()[0].getTradeId().setValue(tradeId2);
    tradeHeader.getTradeDate().setValue(tradeDate);

    FxOptionLeg fxOptionLeg = (FxOptionLeg) tradeConfirmed.getTrade().getProduct();
    fxOptionLeg.getExpiryDateTime().setExpiryDate(expiryDate);

    FxOptionPremium optionPremium = fxOptionLeg.getFxOptionPremium()[0];
    optionPremium.getPremiumAmount().setAmount(premiumAmount);
    optionPremium.setPremiumSettlementDate(settlementDate);
    SettlementInstruction settlementInstruction = optionPremium.getSettlementInformation()
            .getSettlementInstruction();
    settlementInstruction.getCorrespondentInformation().getRoutingIdentificationmodel().getRoutingIds()
            .getRoutingId()[0].setValue(sendTo);
    settlementInstruction.getBeneficiary().getRoutingIdentificationmodel().getRoutingIds().getRoutingId()[0]
            .setValue(sentBy);/*ww  w  .jav a2s . c  o  m*/
    optionPremium.getPremiumQuote().setPremiumValue(premiumValue);
    fxOptionLeg.setValueDate(valueDate);

    fxOptionLeg.getPutCurrencyAmount().getCurrency().setValue("AUD");
    fxOptionLeg.getPutCurrencyAmount().setAmount(putAmount);

    fxOptionLeg.getPutCurrencyAmount().getCurrency().setValue("USD");
    fxOptionLeg.getCallCurrencyAmount().setAmount(callAmount);

    fxOptionLeg.getFxStrikePrice().setRate(fxRate);

    fxOptionLeg.getQuotedAs().getOptionOnCurrency().setValue("AUD");
    fxOptionLeg.getQuotedAs().getFaceOnCurrency().setValue("USD");
    fxOptionLeg.getQuotedAs().getQuotedTenor().setPeriod("M");
    fxOptionLeg.getQuotedAs().getQuotedTenor().setPeriodMultiplier(new BigInteger("6"));

    tradeConfirmed.getParty()[0].getPartyId()[0].setValue(sendTo);
    tradeConfirmed.getParty()[1].getPartyId()[0].setValue(sentBy);

    return (TradeConfirmed) tradeConfirmed.cloneDeep();
}

From source file:net.sourceforge.fenixedu.domain.oldInquiries.StudentInquiriesCourseResult.java

private Double getValueForPresentation(Double value) {
    // TODO: ugly hack, refactor
    if (value == null) {
        return new Double(0);
    }//from  w ww .  j  a va2 s.co m
    BigDecimal round = new BigDecimal(value);
    round.setScale(2, RoundingMode.HALF_EVEN);
    return round.doubleValue();
}

From source file:com.skratchdot.electribe.model.esx.impl.SampleTuneImpl.java

/**
 * <!-- begin-user-doc -->/*from   w  ww.ja v  a 2  s .  c  om*/
 * Calculates the SampleTune value from the given sampleRate (using a
 * baseSamplingRate of 44100)
 * <p>Formula Used:</p>
 * <table>
 * <tr><td></td><td align="center">log(sampleRate/44100)</td><td></td></tr>
 * <tr><td>12 *</td><td align="center">----------------------</td><td>= SampleTune</td></tr>
 * <tr><td></td><td align="center">log(2)</td><td></td></tr>
 * </table>
 * <!-- end-user-doc -->
 * @generated NOT
 */
public float calculateSampleTuneFromSampleRate(int sampleRate) {
    float x = ((float) sampleRate) / 44100;
    float y = (float) Math.log(x);
    float z = (float) (y / Math.log(2));
    BigDecimal bd = new BigDecimal(12 * z).setScale(2, RoundingMode.HALF_EVEN);
    return bd.floatValue();
}