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 String keep0Point(float paramFloat) {
    return String.valueOf(new BigDecimal(paramFloat).setScale(0, 4).intValue());
}

From source file:Main.java

public static double mul(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.multiply(b2).doubleValue();
}

From source file:Main.java

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

From source file:Main.java

public static double addDouble(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.add(b2).doubleValue();
}

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_FLOOR);
    return bd.floatValue();
}

From source file:Main.java

public static boolean compare(String double1, String double2) {
    if (new BigDecimal(double2).compareTo(new BigDecimal(double1)) > 0) {
        return true;
    }/*from w  ww.java 2  s. co m*/
    return false;
}

From source file:Main.java

public static int compareTo(String arg0, String arg1) {
    BigDecimal b1 = new BigDecimal(arg0);
    BigDecimal b2 = new BigDecimal(arg1);
    return b1.compareTo(b2);
}

From source file:Main.java

public static Integer change2int(String price) {
    BigDecimal decimal = new BigDecimal(price);
    BigDecimal decimal1 = new BigDecimal(100);
    return decimal.multiply(decimal1).intValue();
}

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

public static float roundFloat(float number, int count) {
    BigDecimal bd = new BigDecimal(number + "");
    float value = bd.setScale(count, BigDecimal.ROUND_HALF_UP).floatValue();
    return value;
}