List of usage examples for java.math BigDecimal divide
public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("16"); BigDecimal bg2 = new BigDecimal("3"); // divide bg1 with bg2 with 3 scale BigDecimal bg3 = bg1.divide(bg2, 3, RoundingMode.CEILING); System.out.println(bg3);/* w w w . ja v a2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("16"); BigDecimal bg2 = new BigDecimal("3"); // divide bg1 with bg2 with 4 scale // 1 specifies BigDecimal.ROUND_DOWN BigDecimal bg3 = bg1.divide(bg2, 4, BigDecimal.ROUND_DOWN); System.out.println(bg3);/*w w w.j a v a 2s.com*/ }
From source file:Main.java
public static double divAddGoods(String value1, String value2) { if ("0.".equals(value2)) { value2 = "1"; }/*from w w w. j a v a2 s . com*/ double v1 = Double.parseDouble(value1); double v2 = Double.parseDouble(value2); BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal((v2)); return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
public static final double round(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }//www . j ava2s . c o m BigDecimal b = new BigDecimal(Double.toString(v)); BigDecimal one = new BigDecimal("1"); return (b.divide(one, scale, BigDecimal.ROUND_HALF_UP)).doubleValue(); }
From source file:Main.java
public static double divide(double v1, double v2, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }//from w w w . j a va 2s . c o m BigDecimal b = new BigDecimal(Double.toString(v1)); BigDecimal one = new BigDecimal(v2); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); }
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 double division(double v1, double v2) { BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
/** * bytes to kb/* www.j a v a2s . c o m*/ * @param bytes * @return */ public static String bytes2kb(long bytes) { BigDecimal filesize = new BigDecimal(bytes); BigDecimal kilobyte = new BigDecimal(1024); float returnValue = filesize.divide(kilobyte, 2, BigDecimal.ROUND_UP).floatValue(); return (returnValue + " KB "); }
From source file:Main.java
public static double div(double v1, double v2, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }/*from w ww . j av a 2 s. c om*/ BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); }
From source file:Main.java
public static float roundFloat(Float v, int scale) { if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); }/*from w w w . j a va 2 s . c o m*/ BigDecimal b = new BigDecimal(Float.toString(v)); BigDecimal one = new BigDecimal("1"); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).floatValue(); }