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 add(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 convertsToFloat(double v) {
    BigDecimal b = new BigDecimal(v);
    return b.floatValue();
}

From source file:Main.java

public static String roundUptoTwoDecimalUnits(String value) {
    return String.valueOf(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP).doubleValue());
}

From source file:Main.java

public static Double sub(Double v1, Double v2) {
    BigDecimal b1 = new BigDecimal(v1.toString());
    BigDecimal b2 = new BigDecimal(v2.toString());
    return Double.valueOf(b1.subtract(b2).doubleValue());
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static String getBigDecimal(double time) {

    BigDecimal big = new BigDecimal(time);
    return big.toString();
}

From source file:Main.java

public static String getDecimalPrice(float price) {
    BigDecimal bigDecimal = new BigDecimal(price);
    return bigDecimal.setScale(1, BigDecimal.ROUND_DOWN).toString();
}

From source file:Main.java

public static int compareTo(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(v1);
    BigDecimal b2 = new BigDecimal(v2);
    return b1.compareTo(b2);
}