List of usage examples for java.math BigDecimal BigDecimal
public BigDecimal(long val)
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;/*from w ww. j a v a 2 s. c o m*/ }
From source file:Main.java
public static double mulDouble(double v1, double v2) { BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.multiply(b2).doubleValue(); }
From source file:Main.java
public static String change2String(String price) { BigDecimal decimal = new BigDecimal(price); BigDecimal decimal1 = new BigDecimal(100); return decimal.multiply(decimal1).toString(); }
From source file:Main.java
public static boolean compare(String v1, String v2) { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); int bj = b1.compareTo(b2); boolean res;//w w w . ja va2 s. co m if (bj > 0) res = true; else res = false; return res; }
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 round(double num) { BigDecimal b = new BigDecimal(num); BigDecimal rounded = b.setScale(2, RoundingMode.HALF_EVEN); return rounded.doubleValue(); //return num; }
From source file:Main.java
public static double Rounding(double d) { BigDecimal bd = new BigDecimal(d); bd.setScale(1, RoundingMode.HALF_UP); return bd.floatValue(); }
From source file:Main.java
public static double mulddd(double value1, double value2, double value3) { BigDecimal b1 = new BigDecimal(Double.toString(value1)); BigDecimal b2 = new BigDecimal(Double.toString(value2)); BigDecimal b3 = new BigDecimal(Double.toString(value3)); return b1.multiply(b2).multiply(b3).doubleValue(); }
From source file:Main.java
public static double roundDouble(double value, int scale, int roundingMode) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(scale, roundingMode); double d = bd.doubleValue(); bd = null;/* w w w . j a v a2 s . com*/ return d; }
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(); }