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.gm.machine.util.CommonUtils.java

/**
 * ?????//from   ww  w .  java  2 s  . c  om
 * 
 * @param a
 * @return
 */
public static double getDecimal(double a) {
    BigDecimal bd = new BigDecimal(a);
    bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);
    return bd.doubleValue();
}

From source file:com.nortal.petit.converter.util.ResultSetHelper.java

public static Double getDouble(ResultSet rs, ColumnPosition column) throws SQLException {
    BigDecimal bd = getBigDecimal(rs, column);
    return bd == null ? null : Double.valueOf(bd.doubleValue());
}

From source file:com.tencent.wetest.common.util.DeviceUtil.java

public static String getCpuMinFreq() {
    String result = "--";
    double cpuMinFreq = 0;
    try {//  w  w  w  .  j  ava 2 s.c  o  m
        BufferedReader br = new BufferedReader(
                new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"));
        String text = "";
        while ((text = br.readLine()) != null) {
            text = text.trim();
            if (!"".equals(text.trim())) {
                cpuMinFreq = Double.parseDouble(text.trim()) / (1000 * 1000);

                BigDecimal bg = new BigDecimal(cpuMinFreq).setScale(2, RoundingMode.UP);

                result = "" + bg.doubleValue();

                // DeviceUtil.cpuMinFreq = cpuMinFreq;
            }
            break;
        }
        br.close();
        br = null;
    } catch (Exception e) {
        Logger.error("getCpuMinFreqException" + e.toString());
    }
    return result;
}

From source file:com.tencent.wetest.common.util.DeviceUtil.java

public static String getCpuMaxFreq() {
    String result = "--";
    double cpuMaxFreq = 0;
    try {/*from w w w  .ja va 2 s .co m*/
        BufferedReader br = new BufferedReader(
                new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"));
        String text = "";
        while ((text = br.readLine()) != null) {
            text = text.trim();
            if (!"".equals(text.trim())) {
                cpuMaxFreq = Double.parseDouble(text.trim()) / (1000 * 1000);
                BigDecimal bg = new BigDecimal(cpuMaxFreq).setScale(1, RoundingMode.UP);

                result = "" + bg.doubleValue();

            }
            break;
        }
        br.close();
        br = null;

    } catch (Exception e) {

        Logger.error("getCpuMaxFreq Exception:" + e.toString());

    }

    return result;
}

From source file:com.surfs.storage.web.utils.Stringutils.java

public static String convertToKB(String total) {
    if (StringUtils.isBlank(total)) {
        return total;
    }//w  w w  .ja va  2s  .c  om

    String space = total.substring(0, total.length() - 1);
    String unit = total.substring(total.length() - 1, total.length());

    BigDecimal t = new BigDecimal(space);
    BigDecimal multiply = null;

    if (unit.equalsIgnoreCase("M")) {
        multiply = t.multiply(new BigDecimal("1048576"));
    } else if (unit.equalsIgnoreCase("T")) {
        multiply = t.multiply(new BigDecimal("1099511627776"));
    } else if (unit.equalsIgnoreCase("G")) {
        multiply = t.multiply(new BigDecimal("1073741824"));
    }

    return String.valueOf(multiply.doubleValue());
}

From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java

/**
 * Apply a BigDecimal value to the cell.
 * /*from w w  w .  j a v  a  2 s.  co  m*/
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param object
 *            the object
 * @param cell
 *            the {@link Cell} to use
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws ElementException
 */
protected static void bigDecimalHandler(final XConfigCriteria configCriteria, final Object object,
        final Cell cell)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ElementException {
    if (configCriteria.getElement().isFormula()) {
        // apply the formula
        if (!toFormula(configCriteria, cell)) {
            CellValueHandler.consumeValue(cell, toExplicitFormula(object, configCriteria.getField()));
        }
    } else {
        // normal manage cell
        BigDecimal bd = (BigDecimal) configCriteria.getField().get(object);

        if (bd != null) {
            Double dBigDecimal = bd.doubleValue();
            if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) {
                DecimalFormat df = new DecimalFormat(configCriteria.getElement().transformMask());
                CellValueHandler.consumeValue(cell,
                        df.format(dBigDecimal).replace(Constants.COMMA, Constants.DOT));
            } else {
                CellValueHandler.consumeValue(cell, dBigDecimal);
            }
        }
    }
}

From source file:it.polimi.diceH2020.launcher.controller.LaunchAnalysis.java

/**
 * Round doubles without losing precision.
 *
 * @param unrounded//from w w w  . ja va  2  s .  co m
 * @param precision
 * @param roundingMode
 * @return
 */
public static double round(double unrounded, int precision, int roundingMode) {
    BigDecimal bd = new BigDecimal(unrounded);
    BigDecimal rounded = bd.setScale(precision, roundingMode);
    return rounded.doubleValue();
}

From source file:hudson.plugins.robot.model.RobotResult.java

private static double roundToDecimals(double value, int decimals) {
    BigDecimal bd = new BigDecimal(Double.toString(value));
    bd = bd.setScale(decimals, BigDecimal.ROUND_DOWN);
    return bd.doubleValue();
}

From source file:com.intuit.tank.project.JobDetailFormatter.java

protected static String calculateCost(TankConfig config, JobInstance proposedJobInstance,
        List<JobRegion> regions, long simulationTime) {
    List<VmInstanceType> instanceTypes = config.getVmManagerConfig().getInstanceTypes();
    BigDecimal costPerHour = new BigDecimal(.5D);
    for (VmInstanceType type : instanceTypes) {

        if (type.getName().equals(proposedJobInstance.getVmInstanceType())) {
            costPerHour = new BigDecimal(type.getCost());
            break;
        }//from ww  w .  j  a v  a2s . c o m
    }
    long time = simulationTime + proposedJobInstance.getRampTime();
    int numMachines = 0;
    for (JobRegion region : regions) {
        int users = Integer.parseInt(region.getUsers());
        if (users > 0) {
            numMachines += (int) Math.ceil((double) users / (double) proposedJobInstance.getNumUsersPerAgent());
        }
    }
    // dynamoDB costs about 1.5 times the instance cost
    BigDecimal cost = estimateCost(numMachines, costPerHour, time);
    NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
    return nf.format(cost.doubleValue());
}

From source file:com.wicht.benchmark.utils.Benchs.java

/**
 * Compute the values of the benchmarks to get the optimal prefix for the results.
 *
 * @param benchmarks The benchmarks to compute.
 *
 * @return The Prefix for the results./*from   w w w.  ja v a 2 s . c  o  m*/
 */
private static Prefix computeOptimalPrefix(Iterable<NamedBenchmark> benchmarks) {
    Prefix maxPrefix = null;

    for (NamedBenchmark benchmark : benchmarks) {
        BigDecimal mean = BigDecimal.valueOf(benchmark.getMean());

        Prefix prefix = Prefix.getScalePrefix(mean.doubleValue());

        maxPrefix = max(maxPrefix, prefix);
    }

    return maxPrefix;
}