List of usage examples for java.math BigDecimal setScale
@Deprecated(since = "9") public BigDecimal setScale(int newScale, int roundingMode)
From source file:Main.java
public static double round(double value, int scale, int roundingMode) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(scale, roundingMode); double d = bd.doubleValue(); bd = null;/*w ww .j av a2s . c o m*/ return d; }
From source file:Main.java
public static float formatFloat(float floatValue, int newScale) { BigDecimal b = new BigDecimal(floatValue); return b.setScale(newScale, BigDecimal.ROUND_HALF_UP).floatValue(); }
From source file:Main.java
public static String keepNSecimal(String numberStr, int n) { double number = Double.parseDouble(numberStr); BigDecimal b = new BigDecimal(number); String ss = b.setScale(n, BigDecimal.ROUND_HALF_UP).doubleValue() + ""; int pointIndex = ss.lastIndexOf("."); int fractionCount = ss.length() - pointIndex - 1; for (int i = 0; i < n - fractionCount; i++) { ss += 0;/*from w w w . j a va 2s. c o m*/ } return ss; }
From source file:Main.java
public static double round(double value, int nDecimals) { BigDecimal r = new BigDecimal(value); return r.setScale(nDecimals, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
public static double round(double unrounded, int precision) { BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, BigDecimal.ROUND_HALF_DOWN); return rounded.doubleValue(); }
From source file:Main.java
public static double transformTwoDecimalDoubleNumber(double number) { BigDecimal bigD = new BigDecimal(number); bigD = bigD.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return bigD.doubleValue(); }
From source file:Main.java
public static double[] round2(double[] doubleRes) { double[] result = new double[doubleRes.length]; for (int i = 0; i < doubleRes.length; i++) { BigDecimal bg = new BigDecimal(doubleRes[i]); result[i] = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); }// w w w . j av a 2s . c om return result; }
From source file:Main.java
@SuppressWarnings("SameParameterValue") private static double round(double value, int places) { if (places < 0) { throw new IllegalArgumentException(); }// w w w . j av a 2 s . co m BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.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 double changep2(double i) { // TODO Auto-generated method stub BigDecimal b = new BigDecimal(i); int saveBitNum = 2; double c = b.setScale(saveBitNum, BigDecimal.ROUND_HALF_UP).doubleValue(); return c;//from w ww .ja va 2s .co m }