Example usage for java.math BigDecimal doubleValue

List of usage examples for java.math BigDecimal doubleValue

Introduction

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

Prototype

@Override
public double doubleValue() 

Source Link

Document

Converts this BigDecimal to a double .

Usage

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

@SuppressLint("DefaultLocale")
public static String getPriceString(double price) {
    BigDecimal a1 = new BigDecimal(Double.toString(price));
    return String.valueOf(a1.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 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 void divideBigDecimalsInMap(Map<String, Object> baseMap, BigDecimal divisor) {
    if (baseMap == null || divisor == null || divisor.doubleValue() == 0.0)
        return;/*from ww  w.  j a  v a2s .  c o  m*/
    for (Map.Entry<String, Object> entry : baseMap.entrySet()) {
        if (!(entry.getValue() instanceof BigDecimal))
            continue;
        BigDecimal baseVal = (BigDecimal) entry.getValue();
        entry.setValue(baseVal.divide(divisor, BigDecimal.ROUND_HALF_UP));
    }
}

From source file:Main.java

public static double byteCastMB(long number) {
    double n = number / 1024.0 / 1024.0;
    BigDecimal bd = new BigDecimal(n);
    bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
    return bd.doubleValue();
}

From source file:Main.java

public static double roundDouble(double value, int scale, int roundingMode) {
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(scale, roundingMode);
    double d = bd.doubleValue();
    bd = null;/*w  w  w.  j  a  v a 2 s. c  o m*/
    return d;
}

From source file:Main.java

public static double round(double value, int places) {

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:Main.java

private static double round(double value, int places) {
    if (places < 0)
        throw new IllegalArgumentException();

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:Main.java

/**
 * Rounds a double down via passed in amount and places
 * @param value/*from  w w w  .ja  va 2s .  c o  m*/
 * @param places
 * @return
 */
public static double roundDown(double value, int places) {
    if (places < 0)
        throw new IllegalArgumentException();

    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.FLOOR);
    return bd.doubleValue();
}