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 sub(double value1, double value2) {
    BigDecimal b1 = new BigDecimal(Double.valueOf(value1));
    BigDecimal b2 = new BigDecimal(Double.valueOf(value2));
    return b1.subtract(b2).doubleValue();
}

From source file:Main.java

public static float numMathMul(float d1, float d2) {
    BigDecimal b1 = new BigDecimal(d1);
    BigDecimal b2 = new BigDecimal(d2);
    float res = b1.multiply(b2).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
    return res;//  w w  w  .j  av  a2 s  .  co  m
}

From source file:Main.java

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

From source file:Main.java

public static double subtract(double d1, double d2) {
    BigDecimal bd1 = new BigDecimal(Double.toString(d1));
    BigDecimal bd2 = new BigDecimal(Double.toString(d2));
    return bd1.subtract(bd2).doubleValue();
}

From source file:Main.java

public static double mul(double value1, double value2) {
    BigDecimal b1 = new BigDecimal(Double.valueOf(value1));
    BigDecimal b2 = new BigDecimal(Double.valueOf(value2));
    return b1.multiply(b2).doubleValue();
}

From source file:Main.java

public static double doubleJian(double d1, double d2) {
    BigDecimal bd1 = new BigDecimal(Double.toString(d1));
    BigDecimal bd2 = new BigDecimal(Double.toString(d2));
    return bd1.subtract(bd2).doubleValue();
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static double keepThreePlacesOfDecimal(double number) {
    BigDecimal b = new BigDecimal(number);
    return b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:Main.java

public static double changeDouble(double dbl, int count) {
    BigDecimal b = new BigDecimal(dbl);
    return b.setScale(count, BigDecimal.ROUND_HALF_UP).doubleValue();
}