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:com.algoTrader.util.RoundUtil.java

public static BigDecimal roundToNextN(BigDecimal value, double n, int roundingMethod) {

    return RoundUtil.getBigDecimal(roundToNextN(value.doubleValue(), n, roundingMethod), getDigits(n));
}

From source file:Main.java

public static double round(double d, int decimalPlace) {
    try {/*from w  w w  .j  av  a 2s. co m*/
        BigDecimal bd = new BigDecimal(Double.toString(d));
        bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
        return bd.doubleValue();
    } catch (NumberFormatException e) {
        //on NaN or +/- infinity return the value
        return d;
    }
}

From source file:com.floreantpos.util.NumberUtil.java

public static double roundToTwoDigit(double value) {
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(2, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:com.floreantpos.util.NumberUtil.java

public static double roundToThreeDigit(double value) {
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(3, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:ch.algotrader.util.RoundUtil.java

public static BigDecimal roundToNextN(BigDecimal value, BigDecimal n, int roundingMethod) {

    return RoundUtil.getBigDecimal(roundToNextN(value.doubleValue(), n.doubleValue(), roundingMethod),
            getDigits(n));/*from w  w  w .j  a  va 2  s .  c o m*/
}

From source file:Main.java

public static String IndianFormat(BigDecimal n) {
    DecimalFormat formatter = new DecimalFormat("#,###.00");
    //we never reach double digit grouping so return
    if (n.doubleValue() < 100000) {
        return formatter.format(n.setScale(2, 1).doubleValue());
    }/*w  w  w.j  a va 2  s  . com*/
    StringBuffer returnValue = new StringBuffer();
    //Spliting integer part and decimal part
    String value = n.setScale(2, 1).toString();
    String intpart = value.substring(0, value.indexOf("."));
    String decimalpart = value.substring(value.indexOf("."), value.length());
    //switch to double digit grouping
    formatter.applyPattern("#,##");
    returnValue.append(formatter.format(new BigDecimal(intpart).doubleValue() / 1000)).append(",");
    //appending last 3 digits and decimal part
    returnValue.append(intpart.substring(intpart.length() - 3, intpart.length())).append(decimalpart);
    //returning complete string
    if (returnValue.toString().equals(".00")) {
        return "0.00";
    }

    return returnValue.toString();

}

From source file:cloudnet.sla.VmSlaOverallDowntime.java

public static double round(double value, int places) {
    if (places < 0) {
        throw new IllegalArgumentException();
    }//from w ww. j a va2s  . c  o m

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

From source file:com.boha.minisass.gate.PhotoServlet.java

public static double getElapsed(long start, long end) {
    BigDecimal m = new BigDecimal(end - start).divide(new BigDecimal(1000));
    return m.doubleValue();
}

From source file:com.openappengine.utility.ObjectConverter.java

/**
 * Converts BigDecimal to Double./*from   w w w  . j a  v a2  s  .  c om*/
 * @param value The BigDecimal to be converted.
 * @return The converted Double value.
 */
public static Double bigDecimalToDouble(BigDecimal value) {
    return new Double(value.doubleValue());
}

From source file:geogebra.util.MyMath.java

/**
 * Round a double to the given number of digits
 * @param x // www  .j  av  a  2  s  .c om
 * @param digits 
 * @return number rounded to given number of digits
 */
final public static double truncate(double x, int digits) {
    BigDecimal bd = new BigDecimal(x);
    bd = bd.setScale(digits, BigDecimal.ROUND_HALF_UP);
    return bd.doubleValue();
}