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 double roundDouble(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); }// ww w . j a v a 2 s . co 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 int getDurationToInt(long duration) { int d = 0;//from ww w . ja v a 2 s. co m try { BigDecimal b = new BigDecimal(Long.toString(duration)); BigDecimal one = new BigDecimal("1000"); d = b.divide(one, 0, BigDecimal.ROUND_CEILING).intValue(); } catch (Exception e) { e.printStackTrace(); d = 0; } return d; }
From source file:Main.java
/** * bytes to mb//from www . jav a 2 s .com * @param bytes * @return */ public static String bytes2mb(long bytes) { BigDecimal filesize = new BigDecimal(bytes); BigDecimal megabyte = new BigDecimal(1024 * 1024); float returnValue = filesize.divide(megabyte, 2, BigDecimal.ROUND_UP).floatValue(); return (returnValue + " MB "); }
From source file:Main.java
public static float getDurationToFloat(long duration) { float f = 0;//from ww w . j a va 2s . c o m try { BigDecimal b = new BigDecimal(Long.toString(duration)); BigDecimal one = new BigDecimal("1000"); f = b.divide(one, 1, BigDecimal.ROUND_HALF_UP).floatValue(); } catch (Exception e) { e.printStackTrace(); f = 0; } return f; }
From source file:Main.java
public static String bytes2kb(long bytes) { BigDecimal filesize = new BigDecimal(bytes); BigDecimal megabyte = new BigDecimal(1024 * 1024); float returnValue = filesize.divide(megabyte, 2, BigDecimal.ROUND_UP).floatValue(); if (returnValue > 1) return (returnValue + "MB"); BigDecimal kilobyte = new BigDecimal(1024); 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) { BigDecimal b1 = new BigDecimal(v1.toString()); BigDecimal b2 = new BigDecimal(v2.toString()); return Double.valueOf(b1.divide(b2, DEF_DIV_SCALE, BigDecimal.ROUND_HALF_UP).doubleValue()); }
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 w w .j a v a 2s.c om BigDecimal b1 = new BigDecimal(v1.toString()); BigDecimal b2 = new BigDecimal(v2.toString()); return Double.valueOf(b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue()); }
From source file:Main.java
public static BigDecimal tangent(BigDecimal x) { BigDecimal sin = sine(x); BigDecimal cos = cosine(x);/*from w w w . j a v a2 s. c o m*/ return sin.divide(cos, SCALE, BigDecimal.ROUND_HALF_UP); }
From source file:Main.java
public static double round(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }// ww w .ja v a2 s. 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 BigDecimal calculateDivide(BigDecimal numerator, BigDecimal denominator) { BigDecimal result = BigDecimal.ZERO; if (denominator.compareTo(BigDecimal.ZERO) != 0) { result = numerator.divide(denominator, 3, BigDecimal.ROUND_HALF_UP); }/* w w w . j a va 2s . c om*/ return result; }