Example usage for java.math BigDecimal BigDecimal

List of usage examples for java.math BigDecimal BigDecimal

Introduction

In this page you can find the example usage for java.math BigDecimal BigDecimal.

Prototype

public BigDecimal(long val) 

Source Link

Document

Translates a long into a BigDecimal .

Usage

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 float mulFloat(Float v1, Float v2) {

    BigDecimal b1 = new BigDecimal(Float.toString(v1));

    BigDecimal b2 = new BigDecimal(Float.toString(v2));

    return b1.multiply(b2).floatValue();

}

From source file:Main.java

public static int compareTo(Number value1, Number value2) {
    BigDecimal b1 = new BigDecimal(Double.toString(value1.doubleValue()));
    BigDecimal b2 = new BigDecimal(Double.toString(value2.doubleValue()));
    return b1.compareTo(b2);
}

From source file:Main.java

public static BigDecimal round(float d, int decimalPlace) {
    BigDecimal bd = new BigDecimal(Float.toString(d));
    bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
    return bd;/*from w ww.  j  av a  2 s.co  m*/
}

From source file:Main.java

public static double sub2(double v1, double v2, double v3) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    BigDecimal b3 = new BigDecimal(Double.toString(v3));
    return b1.subtract(b2).subtract(b3).doubleValue();
}

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 BigDecimal mulBigDecimal(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.multiply(b2);
}

From source file:Main.java

public static final double sub(String v1, String v2) {
    BigDecimal b1 = new BigDecimal(v1);
    BigDecimal b2 = new BigDecimal(v2);
    return (b1.subtract(b2)).doubleValue();
}

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 int kgToML(float paramFloat) {
    BigDecimal localBigDecimal1 = new BigDecimal(String.valueOf(paramFloat));
    BigDecimal localBigDecimal2 = new BigDecimal("63701");
    BigDecimal localBigDecimal3 = new BigDecimal("65536");
    return new BigDecimal(String.valueOf(localBigDecimal1.multiply(localBigDecimal2).doubleValue()))
            .divide(localBigDecimal3, 0, 4).intValue();
}