Example usage for java.math BigDecimal ROUND_HALF_UP

List of usage examples for java.math BigDecimal ROUND_HALF_UP

Introduction

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

Prototype

int ROUND_HALF_UP

To view the source code for java.math BigDecimal ROUND_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:com.norconex.importer.handler.tagger.impl.TextStatisticsTagger.java

private String divide(long value, long divisor) {
    return BigDecimal.valueOf(value).divide(BigDecimal.valueOf(divisor), 1, BigDecimal.ROUND_HALF_UP)
            .toString();/*from   w w  w .j  a va2s.  c  o  m*/
}

From source file:org.egov.wtms.service.es.WaterChargeElasticSearchService.java

/**
 * API returns the current year total demand from WaterCharge index
 *
 * @return BigDecimal//from   www  . j a v a 2  s.co  m
 */
public BigDecimal getTotalDemand() {
    final SearchQuery searchQuery = new NativeSearchQueryBuilder().withIndices(WATER_TAX_INDEX_NAME)
            .addAggregation(AggregationBuilders.sum(WaterTaxConstants.WATERCHARGETOTALDEMAND)
                    .field(WaterTaxConstants.WATERCHARGETOTALDEMAND))
            .build();

    final Aggregations aggregations = elasticsearchTemplate.query(searchQuery,
            response -> response.getAggregations());

    final Sum aggr = aggregations.get(WaterTaxConstants.WATERCHARGETOTALDEMAND);
    return BigDecimal.valueOf(aggr.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP);
}

From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java

private static String round(Double value) {
    if (value == null) {
        return "N/A";
    }/* w  w  w .j a  v a2 s .  c o m*/

    int decimals = 2;
    if (value >= 1000) {
        decimals = 0;
    } else if (value >= 100) {
        decimals = 1;
    }

    return BigDecimal.valueOf(value).setScale(decimals, BigDecimal.ROUND_HALF_UP).toString();
}

From source file:com.salesmanager.core.util.CurrencyUtil.java

/**
 * Get the measure according to the appropriate measure base. If the measure
 * configured in store is IN and it needs CM or vise versa then the
 * appropriate calculation is done//  w  w w  . j  a v a2  s. co  m
 * 
 * @param weight
 * @param store
 * @param base
 * @return
 */
public static double getMeasure(double measure, MerchantStore store, String base) {

    if (base.equals(Constants.INCH_SIZE_UNIT)) {
        if (store.getSeizeunitcode().equals(Constants.INCH_SIZE_UNIT)) {
            return new BigDecimal(String.valueOf(measure)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        } else {// centimeter (inch to centimeter)
            double measureConstant = 2.54;

            double answer = measure * measureConstant;
            BigDecimal w = new BigDecimal(answer);
            return w.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        }
    } else {// need CM
        if (store.getSeizeunitcode().equals(Constants.CM_SIZE_UNIT)) {
            return new BigDecimal(String.valueOf(measure)).setScale(2).doubleValue();
        } else {// in (centimeter to inch)
            double measureConstant = 0.39;

            double answer = measure * measureConstant;
            BigDecimal w = new BigDecimal(answer);
            return w.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        }
    }

}

From source file:org.kalypso.model.wspm.tuhh.core.wprof.BCEShapeWPRofContentProvider.java

@Override
public BigDecimal getDistance() {
    checkPropertyExists("DISTANCE");//$NON-NLS-1$

    final double distance = getProperty("DISTANCE", Double.class, Double.NaN); //$NON-NLS-1$
    if (Double.isNaN(distance))
        return null;

    final BigDecimal bigDecimal = new BigDecimal(distance);
    bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP);
    return bigDecimal;
}

From source file:libra.common.kmermatch.KmerJoiner.java

public float getProgress() {
    if (this.progressKey == null) {
        if (this.eof) {
            return 1.0f;
        } else {//from  w w  w  .  j  a  v a 2s . co  m
            return 0.0f;
        }
    } else {
        BigInteger seq = SequenceHelper.convertToBigInteger(this.progressKey.getSequence());
        BigInteger prog = seq.subtract(this.beginSequence);
        int comp = this.partitionSize.compareTo(prog);
        if (comp <= 0) {
            return 1.0f;
        } else {
            BigDecimal progDecimal = new BigDecimal(prog);
            BigDecimal rate = progDecimal.divide(new BigDecimal(this.partitionSize), 3,
                    BigDecimal.ROUND_HALF_UP);

            float f = rate.floatValue();
            return Math.min(1.0f, f);
        }
    }
}

From source file:com.chiorichan.util.ObjectUtil.java

public static Integer castToIntWithException(Object value) {
    if (value == null)
        return null;

    switch (value.getClass().getName()) {
    case "java.lang.Long":
        if ((long) value < Integer.MIN_VALUE || (long) value > Integer.MAX_VALUE)
            return (Integer) value;
        else// w  ww .j  av a2s.c  o  m
            return null;
    case "java.lang.String":
        return Integer.parseInt((String) value);
    case "java.lang.Integer":
        return (Integer) value;
    case "java.lang.Double":
        return (Integer) value;
    case "java.lang.Boolean":
        return ((boolean) value) ? 1 : 0;
    case "java.math.BigDecimal":
        return ((BigDecimal) value).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
    default:
        throw new ClassCastException("Uncaught Convertion to Integer of Type: " + value.getClass().getName());
    }
}

From source file:com.emuneee.nctrafficcams.ui.fragments.CameraDetailFragment.java

@Override
public void onResume() {
    super.onResume();
    EasyTracker.getInstance(getActivity()).set(Fields.SCREEN_NAME, TAG);
    EasyTracker.getInstance(getActivity()).send(MapBuilder.createAppView().build());
    View view = getView();// www.  ja  v  a  2  s.c o  m

    // set the variables
    TextView textViewTitle = (TextView) view.findViewById(R.id.text_view_detail_title);
    TextView textViewMetro = (TextView) view.findViewById(R.id.text_view_detail_metro);
    ImageView imageView = (ImageView) view.findViewById(R.id.image_view_detail);
    TextView textViewCoord = (TextView) view.findViewById(R.id.text_view_detail_coordinates);

    // populate the form
    imageView.setOnLongClickListener(new CameraItemLongClickListener());
    textViewTitle.setText(mCamera.getTitle());
    textViewMetro.setText(mCamera.getCity() + ", NC " + mCamera.getZipCode());
    BigDecimal latitude = new BigDecimal(mCamera.getLatitude()).setScale(3, BigDecimal.ROUND_HALF_UP);
    BigDecimal longitude = new BigDecimal(mCamera.getLongitude()).setScale(3, BigDecimal.ROUND_HALF_UP);
    textViewCoord.setText(
            latitude + getString(R.string.latitude) + ", " + longitude + getString(R.string.longitude));
    MainActivity.getImageWorker().loadImage(mCamera.getUrl(), imageView, mCamera);
}

From source file:com.autentia.tnt.businessobject.Project.java

public BigDecimal getCostPerProject() {
    BigDecimal total = new BigDecimal(0);
    Set<ProjectRole> roles = this.getRoles();

    if (roles != null) {
        for (ProjectRole role : roles) {
            Set<Activity> activities = role.getActivities();
            if (activities != null) {
                for (Activity activity : activities) {
                    BigDecimal converse = new BigDecimal(activity.getUser().getCostPerHour());
                    BigDecimal div = new BigDecimal(activity.getDuration());
                    BigDecimal ret = div.multiply(converse);
                    total = total.add(ret.divide(new BigDecimal(60), 2, BigDecimal.ROUND_HALF_UP));// += activity.getDuration()  * activity.getUser().getCostPerHour()/ 60 ;
                }/*from  www. j  a v a 2  s .c  o m*/
            }
        }
    }

    return total;
}

From source file:com.wakatime.intellij.plugin.WakaTime.java

public static BigDecimal getCurrentTimestamp() {
    return new BigDecimal(String.valueOf(System.currentTimeMillis() / 1000.0)).setScale(4,
            BigDecimal.ROUND_HALF_UP);
}