Example usage for java.math RoundingMode HALF_UP

List of usage examples for java.math RoundingMode HALF_UP

Introduction

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

Prototype

RoundingMode HALF_UP

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

Click Source Link

Document

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

Usage

From source file:org.mifos.config.AccountingRulesIntegrationTest.java

@Test
public void testGetInitialRoundingMode() {
    RoundingMode configuredMode = AccountingRules.getInitialRoundingMode();
    String roundingMode = "FLOOR";
    RoundingMode configRoundingMode = RoundingMode.FLOOR;
    ConfigurationManager configMgr = ConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE, roundingMode);
    // return value from accounting rules class has to be the value defined
    // in the config file
    Assert.assertEquals(configRoundingMode, AccountingRules.getInitialRoundingMode());
    // clear the RoundingRule property from the config file
    configMgr.clearProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE);
    RoundingMode defaultValue = AccountingRules.getInitialRoundingMode();
    Assert.assertEquals(defaultValue, RoundingMode.HALF_UP);
    // now set a wrong rounding mode in config
    roundingMode = "UP";
    configMgr.addProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE, roundingMode);
    try {/*from  w ww . java 2s  .  c  o m*/
        AccountingRules.getInitialRoundingMode();
    } catch (RuntimeException e) {
        Assert.assertEquals(e.getMessage(),
                "InitialRoundingMode defined in the config file is not CEILING, FLOOR, HALF_UP. It is "
                        + roundingMode);
    }
    // save it back
    configMgr.setProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE, configuredMode.toString());

}

From source file:services.kpi.PortfolioEntryProgressKpi.java

@Override
public BigDecimal computeAdditional2(IPreferenceManagerPlugin preferenceManagerPlugin,
        IScriptService scriptService, Kpi kpi, Long objectId) {
    PortfolioEntry portfolioEntry = PortfolioEntryDao.getPEById(objectId);

    BigDecimal value = BigDecimal.ZERO;

    for (PortfolioEntryPlanningPackage planningPackage : portfolioEntry.planningPackages) {
        value = value.add(TimesheetDao.getTimesheetLogAsTotalHoursByPEPlanningPackage(planningPackage));
    }//from  ww w. j a  va2s . c  o m

    return value.divide(TimesheetDao.getTimesheetReportHoursPerDay(preferenceManagerPlugin),
            RoundingMode.HALF_UP);
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.MultipleRunoffReader.java

public void readKM() {
    try {/*from   www .j  ava 2s  .  com*/
        final FileFilter kmFilter = FileFilterUtils.suffixFileFilter(".km", IOCase.INSENSITIVE); //$NON-NLS-1$
        final File[] kmFiles = m_kmDir.listFiles(kmFilter);

        // REMARK: the way we read km/polynomial files it's bit tricky to get the slope
        // However this is not a problem, as we are calculating we a uniform steady slope,
        // which is defined in the calculation
        final BigDecimal startSlope = m_calculation.getStartSlope();
        final BigDecimal slope = startSlope.setScale(5, RoundingMode.HALF_UP);

        final KMFileReader reader = new KMFileReader(kmFiles, m_log, m_intervalIndex, slope);
        reader.read();
    } catch (final Throwable e) {
        m_log.log(e, Messages.getString("org.kalypso.model.wspm.tuhh.schema.simulation.KMProcessor.0"), //$NON-NLS-1$
                e.getLocalizedMessage());
    }
}

From source file:de.andreasschoknecht.LS3.LSSMCalculator.java

double round(double value, int places) {
    if (places < 0)
        throw new IllegalArgumentException();

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:org.cirdles.geoapp.LatLongToUTM.java

private static int calcZoneNumber(BigDecimal longitude) {
    int zoneNumber;
    BigDecimal six = new BigDecimal(6);

    if (longitude.signum() < 0) {

        BigDecimal oneEighty = new BigDecimal(180);
        zoneNumber = ((oneEighty.add(longitude)).divide(six, precision, RoundingMode.HALF_UP)).intValue() + 1;
    }//w w  w . jav a 2 s  .  co m

    else {

        BigDecimal thirtyOne = new BigDecimal(31);
        zoneNumber = ((longitude.divide(six, precision, RoundingMode.HALF_UP)).abs().add(thirtyOne)).intValue();
    }

    return zoneNumber;

}

From source file:org.yes.cart.payment.impl.PayPalProPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from w  ww .j a  v  a 2s. c o m
 */
public Payment capture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(CAPTURE);
    final NvpBuilder npvs = new NvpBuilder();
    npvs.addRaw("AUTHORIZATIONID", payment.getTransactionReferenceId());
    npvs.addRaw("AMT", payment.getPaymentAmount().setScale(2, RoundingMode.HALF_UP).toString());
    npvs.addRaw("COMPLETETYPE", "NotComplete");
    npvs.addRaw("CURRENCYCODE", payment.getOrderCurrency());
    npvs.addEncoded("INVNUM", payment.getOrderShipment());
    return runTransaction("DoCapture", npvs.toMap(), payment, CAPTURE);

}

From source file:com.scf.core.EnvTest.java

public static String formatMoney(BigDecimal money, int len) {
    NumberFormat formater = null;
    if (len == 0) {
        formater = new DecimalFormat("###,###");
    } else {/*from   w  w w  .  jav  a2 s.  c  o m*/
        StringBuffer buff = new StringBuffer();
        buff.append("###,##0.");
        for (int i = 0; i < len; i++) {
            buff.append("0");
        }
        formater = new DecimalFormat(buff.toString());
        formater.setRoundingMode(RoundingMode.HALF_UP);
    }
    return formater.format(money);
}

From source file:org.cirdles.ambapo.LatLongToUTM.java

/**
 * Returns the zone number that the longitude corresponds to on the UTM map
 * /*from   www.  j  av a 2 s . c om*/
 * @param longitude
 * @return int zone number
 * 
 * 
 */
private static int calcZoneNumber(BigDecimal longitude) {
    int zoneNumber;
    BigDecimal six = new BigDecimal(6);

    if (longitude.signum() < 0) {

        BigDecimal oneEighty = new BigDecimal(180);
        zoneNumber = ((oneEighty.add(longitude)).divide(six, PRECISION, RoundingMode.HALF_UP)).intValue() + 1;
    }

    else {

        BigDecimal thirtyOne = new BigDecimal(31);
        zoneNumber = ((longitude.divide(six, PRECISION, RoundingMode.HALF_UP)).abs().add(thirtyOne)).intValue();
    }

    if (zoneNumber > 60)
        zoneNumber = 60;

    if (zoneNumber < 1)
        zoneNumber = 1;

    return zoneNumber;

}

From source file:org.codelibs.fess.taglib.FessFunctions.java

public static String formatNumber(final long value) {
    int ratio = 1;
    String unit = "";
    String format = "0.#";
    if (value < 1024) {
        format = "0";
    } else if (value < (1024 * 1024)) {
        ratio = 1024;/*w  w  w .  ja v  a2s.c  om*/
        unit = "K";
    } else if (value < (1024 * 1024 * 1024)) {
        ratio = 1024 * 1024;
        unit = "M";
    } else {
        ratio = 1024 * 1024 * 1024;
        unit = "G";
    }
    final DecimalFormat df = new DecimalFormat(format + unit);
    df.setRoundingMode(RoundingMode.HALF_UP);
    return df.format((double) value / ratio);
}

From source file:edu.nwpu.gemfire.monitor.service.ClusterMemberService.java

private double truncate(double value, int places) {
    return new BigDecimal(value).setScale(places, RoundingMode.HALF_UP).doubleValue();
}