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 float round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.floatValue(); }
From source file:Main.java
public static BigDecimal amtToBigDecimal(String bcdAmt) { BigDecimal bigDecimal = new BigDecimal(bcdAmt); bigDecimal.setScale(2, RoundingMode.HALF_UP); bigDecimal = bigDecimal.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP); return bigDecimal; }
From source file:Main.java
public static String getDecimalPrice(float price) { BigDecimal bigDecimal = new BigDecimal(price); return bigDecimal.setScale(1, BigDecimal.ROUND_DOWN).toString(); }
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 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 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 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 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 String f2Bi(float 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 getDoubleFromDoubletRoundHalfUp1(double sourceNum, int scale) { BigDecimal bigDecimal = new BigDecimal(sourceNum); return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue(); }