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.wicht.benchmark.utils.Benchs.java

private double getExactMean(double mean, Prefix prefix) {
    BigDecimal exactMean = BigDecimal.valueOf(mean);

    exactMean = exactMean.scaleByPowerOfTen(-prefix.getExponent());

    return exactMean.doubleValue();
}

From source file:com.qiangbang.controller.wap.BusinessController.java

public void index() {
    Users users = (Users) getRequest().getSession().getAttribute("users");
    if (users == null) {
        System.out.println("business index session usess is null");
        redirect(//from ww w .  ja  va 2 s. co m
                "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx042031f85a80d192&redirect_uri=http://qb.qq12306.cn/wapIndex/wxcallBack&response_type=code&scope=snsapi_base&state=2#wechat_redirect");
        return;
    }
    UserService userService = Duang.duang(UserService.class);
    int uid = users.getInt("id");
    int count = userService.getBusCount(uid);//
    double busamount = userService.getBusSumPrice(uid);//
    Business business = Business.me.findByUid(uid);

    Record record = Evaluate.me.findAvgService(uid);
    double avgService = 0;
    double avgSpeed = 0;
    double avgQuality = 0;
    int sum = 0;
    int goodper = 0;

    //      Constants.MSGMAP.put(uid+"","??!");

    HashMap<String, Object> res = new HashMap<String, Object>();
    if (record != null) {
        BigDecimal serv = record.getBigDecimal("serv");
        avgService = serv == null ? 0 : serv.doubleValue();
        BigDecimal speed = record.getBigDecimal("speed");
        avgSpeed = speed == null ? 0 : speed.doubleValue();
        BigDecimal qua = record.getBigDecimal("qua");
        avgQuality = qua == null ? 0 : qua.doubleValue();

        res.put("avgService", avgService);
        res.put("avgSpeed", avgSpeed);
        res.put("avgQuality", avgQuality);

        double allavg = avgService + avgSpeed + avgQuality;
        if (allavg > 0) {
            res.put("allavg", allavg / 3);
        } else {
            res.put("allavg", 0);
        }

        Long esum = record.getLong("esum");
        sum = esum == null ? 0 : esum.intValue();
        Long good = record.getLong("good");
        goodper = good == null ? 0 : good.intValue();
        if (sum == 0 || goodper == 0) {
            res.put("goodpercent", 0);
        } else {
            res.put("goodpercent", ((goodper / sum) * 100));
        }
    }
    setAttr("res", res);

    setAttr("count", count);
    setAttr("busamount", busamount);
    setAttr("business", business);
    setAttr("evalrec", record);
    setAttr("isself", 1);
    render("shop/index.jsp");
}

From source file:com.automaster.autoview.server.servlet.ExcelServlet.java

private double caculaDistanciaEntreDoisPontos(double lat1, double lon1, double lat2, double lon2) {

    //Transforma cordenadas em radianos
    /*String lat1Reduzida = String.valueOf(lat1);
    int index = lat1Reduzida.indexOf(".");
    String latFinal1 = lat1Reduzida.substring(0, index+5);
            //  ww w . j a va2s  .com
    String lon1Reduzida = String.valueOf(lon1);
    String lonFinal1 = lon1Reduzida.substring(0, index+5);
            
    String lat2Reduzida = String.valueOf(lat2);
    String latFinal2 = lat2Reduzida.substring(0, index+5);
            
    String lon2Reduzida = String.valueOf(lon2);
    String lonFinal2 = lon2Reduzida.substring(0, index+5);*/

    double lat01 = Math.toRadians(lat1);
    double lon01 = Math.toRadians(lon1);
    double lat02 = Math.toRadians(lat2);
    double lon02 = Math.toRadians(lon2);
    //calcula a distncia em KM atravs da frmula
    double dist = (6371 * Math.acos(
            Math.cos(lat01) * Math.cos(lat02) * Math.cos(lon02 - lon01) + Math.sin(lat01) * Math.sin(lat02)));
    //formata o resultado
    if (dist > 0) {
        BigDecimal decimalFormatado = new BigDecimal(dist).setScale(2, RoundingMode.HALF_EVEN);
        return decimalFormatado.doubleValue();
    }
    return 0;
    //return dist;

}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests well calculation.//ww  w . j  a va  2s .c  om
 */
@Test
public void testWell() {

    for (PlateBigDecimal plate : array) {

        for (WellBigDecimal well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getN();
            double returned = n.well(well);

            assertTrue(result == returned);
        }
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests well calculation.//  w  w  w  . j  a  va2 s . co m
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getN();
            double returned = n.well(well);

            assertTrue(result == returned);
        }
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method.
 *//*from w  w  w . j  av a2  s.c  om*/
@Test
public void testAggregatedPlate() {

    for (PlateBigDecimal plate : array) {

        List<Double> resultList = new ArrayList<Double>();
        int aggregatedReturned = n.platesAggregated(plate);

        for (WellBigDecimal well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        assertEquals((int) resultAggregated, aggregatedReturned);
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method.
 */// w ww .  j a  v  a 2 s  .c o  m
@Test
public void testAggregatedSet() {

    for (PlateBigDecimal plate : array) {

        List<Double> resultList = new ArrayList<Double>();
        int aggregatedReturned = n.setsAggregated(plate.dataSet());

        for (WellBigDecimal well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        assertEquals((int) resultAggregated, aggregatedReturned);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests the aggregated plate statistics method.
 *//* www. j  av  a  2s . co  m*/
@Test
public void testAggregatedPlate() {

    for (Plate plate : array) {

        List<Double> resultList = new ArrayList<Double>();
        int aggregatedReturned = n.platesAggregated(plate);

        for (Well well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        assertEquals((int) resultAggregated, aggregatedReturned);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.NTest.java

/**
 * Tests the aggregated plate statistics method.
 *///  w  w w .  j av  a 2 s .c  o m
@Test
public void testAggregatedSet() {

    for (Plate plate : array) {

        List<Double> resultList = new ArrayList<Double>();
        int aggregatedReturned = n.setsAggregated(plate.dataSet());

        for (Well well : plate) {

            for (BigDecimal bd : well) {
                resultList.add(bd.doubleValue());
            }

        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i);
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregated = statAggregated.getN();

        assertEquals((int) resultAggregated, aggregatedReturned);
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.NBigDecimalTest.java

/**
 * Tests the plate statistics method.//from  w  w w.j a v a2 s . com
 */
@Test
public void testPlate() {

    for (PlateBigDecimal plate : array) {

        Map<WellBigDecimal, Integer> resultMap = new TreeMap<WellBigDecimal, Integer>();
        Map<WellBigDecimal, Integer> returnedMap = n.plate(plate);

        for (WellBigDecimal well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double result = stat.getN();

            resultMap.put(well, (int) result);
        }

        for (WellBigDecimal well : plate) {

            int result = resultMap.get(well);
            int returned = returnedMap.get(well);

            assertEquals(result, returned);
        }
    }
}