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:Main.java

public static float floatTo(float d) {
    BigDecimal bigDecimal = new BigDecimal(d);
    bigDecimal = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP);
    return bigDecimal.floatValue();
}

From source file:Main.java

public static double keepThreePlacesOfDecimal(double number) {
    BigDecimal b = new BigDecimal(number);
    return b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:Main.java

public static String str2Bi(String d) {
    BigDecimal bigDecimal = new BigDecimal(d);
    bigDecimal = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP);
    return bigDecimal.toString();
}

From source file:Main.java

public static double changeDouble(double dbl, int count) {
    BigDecimal b = new BigDecimal(dbl);
    return b.setScale(count, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:Main.java

public static int convertFloatToInt(float sourceNum) {
    BigDecimal bigDecimal = new BigDecimal(sourceNum);
    return bigDecimal.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}

From source file:Main.java

public static float roundFloat(float number, int count) {
    BigDecimal bd = new BigDecimal(number + "");
    float value = bd.setScale(count, BigDecimal.ROUND_HALF_UP).floatValue();
    return value;
}

From source file:Main.java

public static float round(float d, int decimalPlace) {
    BigDecimal bd = new BigDecimal(Float.toString(d));
    bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
    return bd.floatValue();
}

From source file:Main.java

public static int convertDoubleToInt(double sourceNum) {
    BigDecimal bigDecimal = new BigDecimal(sourceNum);
    return bigDecimal.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}

From source file:Main.java

public static Double round(Double d) {
    if (d == null) {
        return null;
    }/*from  www. j av  a  2  s .  c om*/
    return BigDecimal.valueOf(d).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:Main.java

public static float handleFloat(float num, int limit) {
    BigDecimal bigDecimal = new BigDecimal(num);
    float res = bigDecimal.setScale(limit, BigDecimal.ROUND_HALF_UP).floatValue();
    return res;/*  w ww .j  av a 2s. com*/
}