List of usage examples for java.math BigDecimal ROUND_HALF_UP
int ROUND_HALF_UP
To view the source code for java.math BigDecimal ROUND_HALF_UP.
Click Source Link
From source file:Main.java
public static BigDecimal round(float d, int decimalPlace) { BigDecimal bd = new BigDecimal(Float.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd;//from w w w .jav a 2s .c o m }
From source file:Main.java
public static double retainDecimal(int decimalNumber, double value) { BigDecimal bg = new BigDecimal(value); return bg.setScale(decimalNumber, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
public static double byteCastMB(long number) { double n = number / 1024.0 / 1024.0; BigDecimal bd = new BigDecimal(n); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); }
From source file:Main.java
public static double remainder(double v1, double v2) { BigDecimal val1 = new BigDecimal(Double.toString(v1 % v2)); double val = val1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); return val; }
From source file:Main.java
public static int convertToInteger(String data) { BigDecimal num = new BigDecimal(data).setScale(NUM_AFTER_COM, BigDecimal.ROUND_HALF_UP); String res = num.toString().replace(".", ""); return Integer.valueOf(res); }
From source file:Main.java
public static Float getFloatFromFloatRoundHalfUp(float sourceNum, int scale) { BigDecimal bigDecimal = new BigDecimal(sourceNum); return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP).floatValue(); }
From source file:Main.java
public static Float getDoubleFromDoubletRoundHalfUp(double sourceNum, int scale) { BigDecimal bigDecimal = new BigDecimal(sourceNum); return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP).floatValue(); }
From source file:Main.java
public static Double getDoubleFromDoubletRoundHalfUp1(double sourceNum, int scale) { BigDecimal bigDecimal = new BigDecimal(sourceNum); return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
public static float numMathMul(float d1, float d2) { BigDecimal b1 = new BigDecimal(d1); BigDecimal b2 = new BigDecimal(d2); float res = b1.multiply(b2).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue(); return res;/*from ww w .j a v a2s.co m*/ }
From source file:Main.java
public static String conversionDistanse(int aDistanceMeter) { return (aDistanceMeter >= 1000) ? Math.round((new BigDecimal(String.valueOf(aDistanceMeter / 1000)) .setScale(1, BigDecimal.ROUND_HALF_UP).longValue())) + "km" : aDistanceMeter + "m"; }