Example usage for java.math BigDecimal ROUND_UP

List of usage examples for java.math BigDecimal ROUND_UP

Introduction

In this page you can find the example usage for java.math BigDecimal ROUND_UP.

Prototype

int ROUND_UP

To view the source code for java.math BigDecimal ROUND_UP.

Click Source Link

Document

Rounding mode to round away from zero.

Usage

From source file:Main.java

public static void main(String args[]) {
    double r = 3.1234567;
    int decimalPlace = 2;
    BigDecimal bd = new BigDecimal(r);
    bd = bd.setScale(decimalPlace, BigDecimal.ROUND_UP);
    r = bd.doubleValue();/*from   w  w  w .ja  va  2s  .  c  om*/
    System.out.println(r);
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_UP);

    System.out.println(bg3);/*from   ww  w .j  av a 2  s  .c  o  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BigDecimal bd1 = new BigDecimal("123456789.0123456890");

    // Create via a long
    BigDecimal bd2 = BigDecimal.valueOf(123L);

    bd1 = bd1.divide(bd2, BigDecimal.ROUND_UP);

}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("16");
    BigDecimal bg2 = new BigDecimal("3");

    // divide bg1 with bg2
    // 0 specifies BigDecimal.ROUND_UP
    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_UP);

    System.out.println(bg3);//  ww w  . j  a va 2 s  .co  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Create via a string
    BigDecimal bd1 = new BigDecimal("123456789.0123456890");

    // Create via a long
    BigDecimal bd2 = BigDecimal.valueOf(123L);

    bd1 = bd1.add(bd2);//from   w  ww.j  av a 2  s  . c  o  m
    bd1 = bd1.multiply(bd2);
    bd1 = bd1.subtract(bd2);
    bd1 = bd1.divide(bd2, BigDecimal.ROUND_UP);
    bd1 = bd1.negate();
}

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();
}

From source file:Main.java

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

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

/**
 * bytes to kb//from   w w  w .j a  va  2  s.  com
 * @param bytes
 * @return
 */
public static String bytes2kb(long bytes) {
    BigDecimal filesize = new BigDecimal(bytes);
    BigDecimal kilobyte = new BigDecimal(1024);
    float returnValue = filesize.divide(kilobyte, 2, BigDecimal.ROUND_UP).floatValue();
    return (returnValue + "  KB ");
}

From source file:Main.java

/**
 * bytes to mb/*from   w  ww.  j  a v  a2 s. c o m*/
 * @param bytes
 * @return
 */
public static String bytes2mb(long bytes) {
    BigDecimal filesize = new BigDecimal(bytes);
    BigDecimal megabyte = new BigDecimal(1024 * 1024);
    float returnValue = filesize.divide(megabyte, 2, BigDecimal.ROUND_UP).floatValue();
    return (returnValue + "  MB ");
}