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 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 int getNumericByDouble(double value) {
    BigDecimal valueBigDecimal = new BigDecimal(value);
    return valueBigDecimal.setScale(0, BigDecimal.ROUND_DOWN).intValue();
}

From source file:Main.java

private static BigDecimal getShareAmount(Double amount, Double rate, Integer installments) {
    return new BigDecimal(amount * ((1 + rate / 100) / installments)).setScale(2, RoundingMode.HALF_UP);
}

From source file:Main.java

public static float getDurationToFloat(long duration) {
    float f = 0;/*  w w w  . j  ava  2  s. com*/
    try {
        BigDecimal b = new BigDecimal(Long.toString(duration));
        BigDecimal one = new BigDecimal("1000");
        f = b.divide(one, 1, BigDecimal.ROUND_HALF_UP).floatValue();

    } catch (Exception e) {
        e.printStackTrace();
        f = 0;
    }
    return f;
}

From source file:Main.java

public static BigDecimal calculateInterest(BigDecimal amount, BigDecimal rate, long days) {
    return amount.multiply(rate).multiply(new BigDecimal(days / 360.0 / 100.0));
}

From source file:Main.java

public static String keepZeroSecimal(String numberStr) {
    double number = Double.parseDouble(numberStr);
    BigDecimal b = new BigDecimal(number);

    String ss = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

    return ss;//ww w .  j a  v a 2  s .  c o  m
}

From source file:Main.java

public static BigDecimal round(double value, int decimals) {
    BigDecimal valueBigDecimal = new BigDecimal(value);
    return valueBigDecimal.setScale(decimals, BigDecimal.ROUND_HALF_UP);
}

From source file:Main.java

private static BigDecimal round(double value, int decimals) {
    BigDecimal valueBigDecimal = new BigDecimal(value);
    return valueBigDecimal.setScale(decimals, BigDecimal.ROUND_HALF_UP);
}

From source file:Main.java

public static BigDecimal redondear(double f, int scale) {
    String val = f + "";
    BigDecimal big = new BigDecimal(val);
    big = big.setScale(scale, RoundingMode.HALF_UP);

    return big;/*from www.jav  a  2 s  .  co  m*/
}

From source file:Main.java

/**
 * bytes to kb/*from   w ww  .  jav a  2 s.  c om*/
 * @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 ");
}