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

private static String getFormatSize(double size) {
    double kiloByte = size / 1024;
    if (kiloByte < 1) {
        return size + "Byte";
    }/*  w  w w.  j  av  a2s.co  m*/
    double megaByte = kiloByte / 1024;
    if (megaByte < 1) {
        BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
        return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
    }
    double gigaByte = megaByte / 1024;
    if (gigaByte < 1) {
        BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
        return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
    }
    double teraBytes = gigaByte / 1024;
    if (teraBytes < 1) {
        BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
        return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
    }
    BigDecimal result4 = new BigDecimal(teraBytes);
    return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
}

From source file:Main.java

public static String change2String(int cent) {
    BigDecimal decimal = new BigDecimal(cent);
    BigDecimal decimal1 = new BigDecimal(100);
    return decimal.divide(decimal1).toString();
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static String formatFileSize(double size) {
    double kiloByte = size / 1024;
    if (kiloByte < 1) {
        return size + "B";
    }/*w w w .ja  va 2  s. co m*/

    double megaByte = kiloByte / 1024;
    if (megaByte < 1) {
        BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
        return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
    }

    double gigaByte = megaByte / 1024;
    if (gigaByte < 1) {
        BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
        return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
    }

    double teraBytes = gigaByte / 1024;
    if (teraBytes < 1) {
        BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
        return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
    }
    BigDecimal result4 = new BigDecimal(teraBytes);
    return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
}

From source file:Main.java

public static String getFormatSize(double size) {
    double kiloByte = size / 1024;
    if (kiloByte < 1) {
        return size + "Byte(s)";
    }/*from  w  w  w  .  j  av a 2  s .c o  m*/

    double megaByte = kiloByte / 1024;
    if (megaByte < 1) {
        BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
        return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
    }

    double gigaByte = megaByte / 1024;
    if (gigaByte < 1) {
        BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
        return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
    }

    double teraBytes = gigaByte / 1024;
    if (teraBytes < 1) {
        BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
        return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
    }
    BigDecimal result4 = new BigDecimal(teraBytes);
    return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
}

From source file:Main.java

public static BigDecimal withObject(Object value) {
    if (value == null)
        return null;
    else if (value instanceof BigDecimal)
        return (BigDecimal) value;
    else if (value instanceof Double)
        return new BigDecimal((Double) value);
    else if (value instanceof Float)
        return new BigDecimal((Float) value);
    else if (value instanceof Integer)
        return new BigDecimal((Integer) value);
    else if (value instanceof Short)
        return new BigDecimal((Short) value);
    else/*w  ww.  j  av a  2 s.  c o  m*/
        return null;
}

From source file:Main.java

public static String getFormatSize(double size) {
    double kiloByte = size / 1024.0D;
    if (kiloByte < 1.0D) {
        return size + " B"; // Byte(s)
    }/*from w  w  w .  j ava  2 s  .c  o  m*/

    double megaByte = kiloByte / 1024.0D;
    if (megaByte < 1.0D) {
        BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
        return result1.setScale(2, 4).toPlainString() + " KB";
    }

    double gigaByte = megaByte / 1024.0D;
    if (gigaByte < 1.0D) {
        BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
        return result2.setScale(2, 4).toPlainString() + " MB";
    }

    double teraBytes = gigaByte / 1024.0D;
    if (teraBytes < 1.0D) {
        BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
        return result3.setScale(2, 4).toPlainString() + " GB";
    }
    BigDecimal result4 = new BigDecimal(teraBytes);
    return result4.setScale(2, 4).toPlainString() + " TB";
}