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.github.jessemull.microflex.stat.statbigdecimal.MaxBigDecimalTest.java

/**
 * Tests set calculation using indices./*from w  ww  .ja  va2 s .c o m*/
 */
@Test
public void testSetIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = max.set(plate.dataSet(), begin, end - begin);

        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(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMax();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

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

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests the plate statistics method using the values between the indices.
 *///from   w  ww . j a  va 2  s .c  o m
@Test
public void testPlateIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = min.plate(plate, begin, end - begin);

        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(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

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

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests set calculation using indices.//from  w ww. j a va 2 s .  c  o m
 */
@Test
public void testSetIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = min.set(plate.dataSet(), begin, end - begin);

        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(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getMin();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

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

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:uk.co.onehp.trickle.services.betfair.BetfairServiceImpl.java

private PlaceBets createLimitedSPBet(Bet bet, BigDecimal liability) {
    BigDecimal price = (bet.getStrategy().getAspect() == BettingAspect.BACK ? bet.getStrategy().getMinOdds()
            : bet.getStrategy().getMaxOdds());
    bet.addLog(new BetLog(new LocalDateTime(), liability, price, BetType.LIMITED_SP));
    this.domainService.updateBet(bet);
    PlaceBets placeBets = new PlaceBets();
    placeBets.setBetType(bet.getStrategy().getAspect() == BettingAspect.BACK ? BetTypeEnum.B : BetTypeEnum.L);
    placeBets.setBetCategoryType(BetCategoryTypeEnum.L);
    placeBets.setBetPersistenceType(BetPersistenceTypeEnum.NONE);
    placeBets.setMarketId(bet.getHorse().getRaceId());
    placeBets.setSelectionId(bet.getHorse().getRunnerId());
    placeBets.setBspLiability(liability.doubleValue());
    placeBets.setSize(bet.getStrategy().getAspect() == BettingAspect.BACK ? liability.doubleValue()
            : BettingUtil.libilityToStake(liability, price).doubleValue());
    placeBets.setPrice(price.doubleValue());
    return placeBets;
}

From source file:com.blackbear.flatworm.converters.CoreConverters.java

public String convertBigDecimal(Object obj, Map<String, ConversionOption> options) {
    if (obj == null) {
        return null;
    }//from  www.  j  a v a 2  s . c o  m
    BigDecimal bd = (BigDecimal) obj;

    int decimalPlaces = 0;
    String decimalPlacesOption = (String) Util.getValue(options, "decimal-places");
    boolean decimalImplied = "true".equals(Util.getValue(options, "decimal-implied"));

    if (decimalPlacesOption != null)
        decimalPlaces = Integer.parseInt(decimalPlacesOption);

    DecimalFormat format = new DecimalFormat();
    format.setDecimalSeparatorAlwaysShown(!decimalImplied);
    format.setMinimumFractionDigits(decimalPlaces);
    format.setMaximumFractionDigits(decimalPlaces);

    return format.format(bd.doubleValue());
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.util.KeyphrasePerformanceCounter.java

public Double getMeanAveragePrecision() {
    BigDecimal meanAveragePrecision = new BigDecimal("0.0");
    for (FilePerformance filePerformance : fileName2performanceMap.values()) {
        meanAveragePrecision = meanAveragePrecision.add(filePerformance.calculateAveragePrecision());
    }//  w w w .j  a v  a  2  s .c o m
    if (fileName2performanceMap.size() == 0) {
        return 0d;
    }
    meanAveragePrecision = meanAveragePrecision.divide(
            new BigDecimal(String.valueOf(fileName2performanceMap.size())), NBR_FLOATING_POINTS,
            RoundingMode.UP);
    return meanAveragePrecision.doubleValue();
}

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

/**
 * Tests well calculation./*  ww  w  .  j  a  v a 2s .com*/
 */
@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 resultDouble = stat.getGeometricMean();

            BigDecimal returned = mean.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests well calculation.//from   ww w . java 2  s .  c  o 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 resultDouble = stat.getMean();

            BigDecimal returned = mean.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests well calculation./*from   w  w w .jav a 2s.  com*/
 */
@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 resultDouble = stat.getSumsq();

            BigDecimal returned = sum.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests well calculation./*  www.  ja  v a  2  s.  com*/
 */
@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 resultDouble = stat.getSum();

            BigDecimal returned = sum.well(well, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}