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.mycompany.thymeleafspringapp.dao.DealsDaoImpl.java

@Override
public Deals createDeal(Instruments instr, Users user, DealDirection direction, BigDecimal openPrice,
        Date openDate, String descr, Set<Tags> tags, Set<Screenshots> screenshots) {
    Deals d = new Deals(0, instr, user, direction == DealDirection.LONG ? true : false, openPrice.doubleValue(),
            null, openDate, null, descr, screenshots, tags);
    persistDeal(d);/* ww w  . j  a  v a  2s . c o  m*/
    return d;
}

From source file:com.idylwood.utils.MathUtils.java

private final static double varianceSlow(final double[] data) {
    BigDecimal mean = new BigDecimal(0);
    for (double x : data)
        mean = mean.add(new BigDecimal(x), MathContext.UNLIMITED);
    mean = mean.divide(new BigDecimal(data.length), MathContext.UNLIMITED);
    //mean = new BigDecimal(mean(data));
    BigDecimal ret = new BigDecimal(0);
    for (double x : data) {
        //BigDecimal summand = ret.add(new BigDecimal(x),MathContext.UNLIMITED);
        BigDecimal summand = new BigDecimal(x).subtract(mean, MathContext.UNLIMITED);
        ret = ret.add(summand.pow(2));/* ww  w  .j  a  v a2  s . c  o m*/
    }
    ret = ret.divide(new BigDecimal(data.length - 1), MathContext.DECIMAL128);
    return ret.doubleValue();
}

From source file:edu.ku.brc.specify.config.LatLonConverter.java

/**
 * @param bd//from   w  w w  .j a v a  2 s . co  m
 * @param latLonStr
 * @param type
 * @return
 */
public static String ensureFormattedString(final BigDecimal bd, final String latLonStr, final FORMAT type,
        final LATLON latOrLon, final int decimalSize) {
    if (StringUtils.isEmpty(latLonStr)) {
        if (bd == null) {
            return null;
        }

        String outStr = format(bd, latOrLon, type, DEGREES_FORMAT.Symbol, decimalSize);
        if (latOrLon == LATLON.Latitude) {
            outStr += " " + northSouth[bd.doubleValue() < 0.0 ? 1 : 0];
        } else {
            outStr += " " + eastWest[bd.doubleValue() < 0.0 ? 1 : 0];
        }
        return outStr;
    }
    return latLonStr;
}

From source file:ch.algotrader.service.TransactionPersistenceServiceImpl.java

/**
 * {@inheritDoc}/*from  www. j  av  a  2s .  c  om*/
 */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public String resetCashBalances() {

    // get all existing cashBalances
    Collection<CashBalance> existingCashBalances = this.cashBalanceDao.loadAll();

    // sum all transactions
    Collection<Transaction> transactions = this.transactionDao.loadAll();
    BigDecimalMap<Pair<Strategy, Currency>> map = new BigDecimalMap<>();
    for (Transaction transaction : transactions) {

        transaction.initializeSecurity(HibernateInitializer.INSTANCE);

        // process all currenyAmounts
        for (CurrencyAmountVO currencyAmount : transaction.getAttributions()) {
            map.increment(new Pair<>(transaction.getStrategy(), currencyAmount.getCurrency()),
                    currencyAmount.getAmount());
        }
    }

    // create cash balances
    StringBuilder buffer = new StringBuilder();
    for (Map.Entry<Pair<Strategy, Currency>, BigDecimal> entry : map.entrySet()) {

        Strategy strategy = entry.getKey().getFirst();
        Currency currency = entry.getKey().getSecond();
        BigDecimal amount = entry.getValue().setScale(this.commonConfig.getPortfolioDigits(),
                BigDecimal.ROUND_HALF_UP);

        CashBalance cashBalance = this.cashBalanceDao.findByStrategyAndCurrency(strategy, currency);
        if (cashBalance != null) {

            existingCashBalances.remove(cashBalance);

            BigDecimal oldAmount = cashBalance.getAmount();
            if (oldAmount.doubleValue() != amount.doubleValue()) {

                cashBalance.setAmount(amount);

                String info = "adjusted cashBalance " + cashBalance + " from " + oldAmount;
                LOGGER.info(info);
                buffer.append(info + "\n");

            }

        } else {

            cashBalance = CashBalance.Factory.newInstance();
            cashBalance.setCurrency(currency);
            cashBalance.setAmount(amount);
            cashBalance.setStrategy(strategy);

            this.cashBalanceDao.save(cashBalance);

            String info = "created cashBalance " + cashBalance;
            LOGGER.info(info);
            buffer.append(info + "\n");

        }
    }

    // remove all obsolete cashBalances
    for (CashBalance cashBalance : existingCashBalances) {

        Strategy strategy = cashBalance.getStrategy();

        String info = "removed cashBalance " + cashBalance;
        LOGGER.info(info);
        buffer.append(info + "\n");
    }

    this.cashBalanceDao.deleteAll(existingCashBalances);

    return buffer.toString();

}

From source file:fuzzy.util.MaxMF.java

public Map<Double, Double> evaluate(Collection<T> x, MembershipFunction<T> mf) {
    Map<Double, Double> max = new HashMap<Double, Double>();
    BigDecimal maxValue = BigDecimal.valueOf(0.0);
    boolean first = true;
    for (T value : x) {
        BigDecimal temp = new BigDecimal(mf.evaluate(value), new MathContext(precision, roundingMode));
        if (first || temp.compareTo(maxValue) > 0) {
            first = false;//from w w w .  j  a  va  2 s. c  om
            maxValue = temp;
            max.clear();
            max.put(value.doubleValue(), temp.doubleValue());
        } else if (temp.compareTo(maxValue) == 0) {
            max.put(value.doubleValue(), temp.doubleValue());
        } // else ignore since it's less than the maximum value
    }
    return max;
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

public double formatSizeMB(double total) {
    double amount = (total / mbDivider);
    BigDecimal bd = new BigDecimal(amount).setScale(2, RoundingMode.HALF_EVEN);
    amount = bd.doubleValue();
    return amount;
}

From source file:ch.algotrader.entity.security.SecurityFamilyImpl.java

@Override
public BigDecimal getTickSize(String broker, BigDecimal price, boolean upwards) {

    Validate.notNull(price, "Price cannot be null");

    return RoundUtil.getBigDecimal(getTickSize(broker, price.doubleValue(), upwards), getScale(broker));
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the string formatted value for the size
*//*from w ww.  j  a v  a  2s .com*/
public double formatSizeGB(double total) {
    double amount = (total / gbDivider);
    BigDecimal bd = new BigDecimal(amount).setScale(2, RoundingMode.HALF_EVEN);
    amount = bd.doubleValue();
    return amount;
}

From source file:fsm.series.Series_CF.java

public double getF1Value(double y, int m, int n) {

    double um = getMu_m(m);
    double un = getMu_m(n);
    double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um));

    double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un));
    double km = um / a;
    double kn = un / a;

    BigDecimal Ym;/*from  w  ww.  j  av a 2 s.co  m*/
    BigDecimal Yn;

    BigDecimal cosh = new BigDecimal(-alphaM * -cosh(km * y));
    BigDecimal sinh = new BigDecimal(-sinh(km * y));
    BigDecimal sin = new BigDecimal(sin(km * y));
    BigDecimal cos = new BigDecimal(-alphaM * cos(km * y));

    Ym = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y));
    BigDecimal sinhN = new BigDecimal(-sinh(kn * y));
    BigDecimal sinN = new BigDecimal(sin(kn * y));
    BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y));

    Yn = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ym.multiply(Yn);

    return ans.doubleValue();
}

From source file:fsm.series.Series_CF.java

public double getF2Value(double y, int m, int n) {
    double Pi = Math.PI;

    double um = getMu_m(m);
    double un = getMu_m(n);
    double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um));

    double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un));
    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd2;/* ww w  . ja  va 2s  . c om*/
    BigDecimal Yn;

    BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y));

    Ymd2 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y));
    BigDecimal sinhN = new BigDecimal(-sinh(kn * y));
    BigDecimal sinN = new BigDecimal(sin(kn * y));
    BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y));

    Yn = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd2.multiply(Yn);

    return ans.doubleValue();
}