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 BigDecimal amtToBigDecimal(String bcdAmt) {
    BigDecimal bigDecimal = new BigDecimal(bcdAmt);
    bigDecimal.setScale(2, RoundingMode.HALF_UP);
    bigDecimal = bigDecimal.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
    return bigDecimal;
}

From source file:Main.java

public static int convertToInteger(String data) {
    BigDecimal num = new BigDecimal(data).setScale(NUM_AFTER_COM, BigDecimal.ROUND_HALF_UP);
    String res = num.toString().replace(".", "");
    return Integer.valueOf(res);
}

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

private static double getdPoint(double num) {
    double d = num;
    int fInt = (int) d;
    BigDecimal b1 = new BigDecimal(Double.toString(d));
    BigDecimal b2 = new BigDecimal(Integer.toString(fInt));
    double dPoint = b1.subtract(b2).floatValue();
    return dPoint;
}

From source file:Main.java

public static double getdPoint(double num) {
    double d = num;
    int fInt = (int) d;
    BigDecimal b1 = new BigDecimal(Double.toString(d));
    BigDecimal b2 = new BigDecimal(Integer.toString(fInt));
    double dPoint = b1.subtract(b2).floatValue();
    return dPoint;

}

From source file:Main.java

public static double returnMax(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(v1);
    BigDecimal b2 = new BigDecimal(v2);
    return b1.max(b2).doubleValue();
}

From source file:Main.java

public static double returnMin(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(v1);
    BigDecimal b2 = new BigDecimal(v2);
    return b1.min(b2).doubleValue();
}

From source file:Main.java

public static double round(double unrounded, int precision) {
    BigDecimal bd = new BigDecimal(unrounded);
    BigDecimal rounded = bd.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
    return rounded.doubleValue();
}

From source file:Main.java

public static int getDurationToInt(long duration) {
    int d = 0;/*from  www.ja va2s . c om*/
    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

public static double getBigDecimal_0(String strings) {
    double price = Double.parseDouble(strings);
    BigDecimal bg = new BigDecimal(price).setScale(0, BigDecimal.ROUND_UP);
    return bg.doubleValue();
}