Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

In this page you can find the example usage for java.lang Double parseDouble.

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

Returns a new double initialized to the value represented by the specified String , as performed by the valueOf method of class Double .

Usage

From source file:edu.cmu.cs.lti.ark.fn.identification.FrameIdentificationRelease.java

public static TObjectDoubleHashMap<String> readModel(Collection<String> featureLines) {
    final TObjectDoubleHashMap<String> model = new TObjectDoubleHashMap<String>(featureLines.size());
    int count = 0;
    for (String line : featureLines) {
        String[] fields = line.split("\t");
        final String featureName = fields[0].trim();
        final Double featureValue = Double.parseDouble(fields[1].trim());
        model.put(featureName, featureValue);
        count++;/*w  w  w. ja va2 s  .  c  om*/
        if (count % 100000 == 0)
            System.err.print(count + " ");
    }
    return model;
}

From source file:com.forexnepal.allbanks.HimalayanBank.java

@Override
public void scrap(String args) throws IOException {
    Currency currency;//from w  w w  . ja v a 2s . co m

    Bank bank = bankService.getByName("Himalayan Bank Limited");
    System.out.println(bank.getBankName());

    String URL = "http://www.himalayanbank.com/forex";
    String contentPage1, contentPage2, fullLink, regex1, regex2, regex3;
    Pattern pattern1, pattern2, pattern3;
    Matcher matcher1, matcher2, matcher3;

    contentPage1 = readURL(URL);

    regex1 = "<td>(.*?)</td>(.*?)<td>(.*?)</td>(.*?)<td align=\"right\">(.*?)</td>(.*?)<td align=\"right\">(.*?)</td>(.*?)<td align=\"right\">(.*?)</td>";

    // regex1="&nbsp;&nbsp;(.*?)</b>";//currency name
    //<b>(\d)</b></font unit
    pattern1 = Pattern.compile(regex1);
    matcher1 = pattern1.matcher(contentPage1);

    while (matcher1.find()) {

        int unit = Integer.parseInt(matcher1.group(3).replaceAll("-", "1").trim());
        Double sellingRate = (Double.parseDouble(matcher1.group(9).replaceAll("-", "0").trim()))
                / (Integer.parseInt(matcher1.group(3).replaceAll("-", "0").trim()));
        Double buyingRate = (Double.parseDouble(matcher1.group(5).replaceAll("-", "0").trim()))
                / (Integer.parseInt(matcher1.group(3).replaceAll("-", "0").trim()));
        //System.out.println("in");

        System.out.println(matcher1.group(1).trim() + "\t1\t" + buyingRate + "\t" + sellingRate);

        //System.out.println(currencyService.getByName("USD"));
        try {
            ExchangeRates exchangeRates = new ExchangeRates();
            currency = currencyService.getByName(matcher1.group(1).trim());

            exchangeRates.setBank(bank);
            exchangeRates.setCurrency(currency);
            exchangeRates.setUnit(1);
            exchangeRates.setSellingRate(sellingRate);
            exchangeRates.setBuyingRate(buyingRate);
            exchangeRates.setForexDate(date);

            exchangeRates.setForexTime(time);

            //System.out.println(exchangeRates.getCurrency()+":"+exchangeRates.getBuyingRate());
            exchangeRatesService.insertOrUpdate(exchangeRates);

        } catch (NullPointerException | NumberFormatException ex) {
            System.out.println(ex.getMessage());
        }

    }
}

From source file:com.jennifer.ui.util.StringUtil.java

public static double parseDouble(String key, JSONObject series) {

    // setting//from w w w  .j a  v a  2 s . co  m
    String[] names = JSONObject.getNames(series);
    for (String name : names) {
        if (series.getJSONObject(name).has("max")) {
            key = key.replace("{" + name + "}", series.getJSONObject(name).getDouble("max") + "");
        }
    }

    // caculate
    String[] list = key.split(" ");

    double value = Double.parseDouble(list[0]);

    for (int i = 1; i < list.length; i += 2) {
        String operator = list[i];

        if (operator.startsWith("+")) {
            value += Double.parseDouble(list[i + 1]);
        } else if (operator.startsWith("/")) {
            value /= Double.parseDouble(list[i + 1]);
        } else if (operator.startsWith("-")) {
            value -= Double.parseDouble(list[i + 1]);
        } else if (operator.startsWith("*")) {
            value *= Double.parseDouble(list[i + 1]);
        }
    }

    return value;
}

From source file:com.aw.core.format.NumeroEnTextoFormatter.java

/**
*Devuelve en letras un monto determinado.
*@param valor: Objeto Double que ser mostrada en letras.
*@return String: Monto en Letras./* w  ww .  ja  v  a2s .  c  o m*/
*/
private static String valorEnLetras(Double valor) {

    String centavos = "00";
    double doubleValor = valor;
    int numero = valor.intValue();
    int posPunto = String.valueOf(valor).indexOf(".");
    int posComa = String.valueOf(valor).indexOf(",");
    double doubleNumero = Double.parseDouble(String.valueOf(numero));
    if (posPunto > 0 || posComa > 0) {
        if (posPunto > 0)
            centavos = String.valueOf(valor).substring(posPunto + 1);
        if (posComa > 0)
            centavos = String.valueOf(valor).substring(posComa + 1);
    } else
        centavos = "00";

    String cadena = "";
    int millon;
    int cienMil;

    if (numero < 1000000000) {

        if (numero > 999999) {
            millon = (new Double(numero / 1000000)).intValue();
            numero = numero - millon * 1000000;
            cadena += base(millon, true) + (millon > 1 ? " MILLONES " : " MILLON ");
        }
        if (numero > 999) {
            cienMil = (new Double(numero / 1000)).intValue();
            numero = numero - cienMil * 1000;
            cadena += base(cienMil, false) + " MIL ";
        }

        cadena += base(numero, true);

        if (cadena != null && cadena.trim().length() > 0) {
            cadena += " CON ";
        }

        if (centavos.trim().length() == 1)
            centavos += "0";
        cadena += String.valueOf(centavos) + "/100";

    }

    return cadena.trim();
    //return  cadena.trim()+" Nuevos Soles";
}

From source file:com.krawler.common.util.SchedulingUtilities.java

public static double parseDuration(String duration) {
    double d = -1;
    if (duration.contains("h")) {
        duration = duration.substring(0, duration.indexOf('h'));
    } else if (duration.contains("d")) {
        duration = duration.substring(0, duration.indexOf('d'));
    }/*  w  ww. j  a v a  2s .  c  o  m*/
    d = Double.parseDouble(duration);
    return d;
}

From source file:no.magott.training.ex2.ExchangeRateFieldSetMapper.java

@Override
public ExchangeRate mapFieldSet(FieldSet fieldSet) throws BindException {
    ExchangeRate exchangeRate = new ExchangeRate();
    exchangeRate.setDate(fieldSet.readDate("Date", "yyyy-MM-dd"));
    String exchangeRateAsString = fieldSet.readString("ExchangeRate");
    if (!exchangeRateAsString.trim().equals("-")) {
        exchangeRate.setExchangeRate(Double.parseDouble(exchangeRateAsString));
    }//from   w w w  .  j a v a2 s .co  m

    exchangeRate.setFrom(fromCurrency);
    exchangeRate.setTo(toCurrency);
    return exchangeRate;
}

From source file:gamlss.algorithm.TEST.java

private void twoParTest() {

    String fileName = "Data/distTest.csv";
    CSVFileReader readData = new CSVFileReader(fileName);
    readData.readFile();//from  w  w  w  . j av  a2 s. c o  m
    ArrayList<String> data = readData.storeValues;

    ArrayRealVector y = new ArrayRealVector(data.size());
    ArrayRealVector mu = new ArrayRealVector(data.size());
    ArrayRealVector sigma = new ArrayRealVector(data.size());
    ArrayRealVector nu = new ArrayRealVector(data.size());
    ArrayRealVector tau = new ArrayRealVector(data.size());

    for (int i = 0; i < data.size(); i++) {
        String[] line = data.get(i).split(",");
        y.setEntry(i, Double.parseDouble(line[0]));
        mu.setEntry(i, Double.parseDouble(line[1]));
        sigma.setEntry(i, Double.parseDouble(line[2]));
        nu.setEntry(i, Double.parseDouble(line[3]));
        tau.setEntry(i, Double.parseDouble(line[4]));
    }

    double[] outA = new double[y.getDimension()];
    String folder = "C:\\Users\\Daniil\\Desktop\\Gamlss_exp/outDistG.csv";
    ArrayRealVector out = null;
    GA dist = new GA();

    dist.setDistributionParameter(DistributionSettings.MU, mu);
    dist.setDistributionParameter(DistributionSettings.SIGMA, sigma);
    dist.setDistributionParameter(DistributionSettings.NU, nu);
    dist.setDistributionParameter(DistributionSettings.TAU, tau);
    //1      
    out = dist.firstDerivative(DistributionSettings.MU, y);
    MatrixFunctions.vectorWriteCSV(folder, out, false);
    //2
    out = dist.secondDerivative(DistributionSettings.MU, y);
    MatrixFunctions.vectorWriteCSV(folder, out, true);
    //3
    out = dist.firstDerivative(DistributionSettings.SIGMA, y);
    MatrixFunctions.vectorWriteCSV(folder, out, true);
    //4
    out = dist.secondDerivative(DistributionSettings.SIGMA, y);
    MatrixFunctions.vectorWriteCSV(folder, out, true);
    //5
    //         out = dist.secondCrossDerivative(DistributionSettings.MU, DistributionSettings.SIGMA,  y);
    //         MatrixFunctions.vectorWriteCSV(folder, out, true);
    //6
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.dGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), false);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //7
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.dGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), true);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //8
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.pGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), true, true);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //9
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.pGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), false, true);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //10
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.pGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), true, false);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //11

    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.pGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), false, false);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //12
    for (int i = 0; i < y.getDimension(); i++) {
        //            outA[i] = dist.qGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), true, true);
    }
    //         MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //13
    for (int i = 0; i < y.getDimension(); i++) {
        //            outA[i] = dist.qGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), false, true);
    }
    //         MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //14
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.qGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), true, false);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //15
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.qGA(y.getEntry(i), mu.getEntry(i), sigma.getEntry(i), false, false);
    }
    MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //16
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.dGA(y.getEntry(i));
    }
    //         MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //17
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.pGA(y.getEntry(i));
    }
    //         MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);
    //18
    for (int i = 0; i < y.getDimension(); i++) {
        outA[i] = dist.qGA(y.getEntry(i));
    }
    //         MatrixFunctions.vectorWriteCSV(folder, new ArrayRealVector(outA, false), true);

    System.out.println("Done !!!");

}

From source file:com.kbotpro.cache.xml.XMLParser.java

public Object getValue(Element element) {
    final String type = element.getAttributeValue("type");
    if (type == null) {
        return null;
    }/*from   w  w w  . j ava 2s .  co m*/
    if (element.getText() == null) {
        return null;
    }
    if (type.equals("int")) {
        return Integer.parseInt(element.getText());
    }
    if (type.equals("long")) {
        return Long.parseLong(element.getText());
    }
    if (type.equals("double")) {
        return Double.parseDouble(element.getText());
    }
    if (type.equals("float")) {
        return Float.parseFloat(element.getText());
    }
    if (type.equals("boolean")) {
        return Boolean.parseBoolean(element.getText());
    }
    if (type.equals("base64")) {
        return Base64.decodeBase64(element.getText());
    }
    if (type.equals("string")) {
        return element.getText();
    }
    if (type.equals("null")) {
        return null;
    }

    return null;
}

From source file:com.moscona.dataSpace.Text.java

@Override
public double getDoubleValue() throws DataSpaceException {
    try {/*  www  . j a  va2s . com*/
        return Double.parseDouble(value.replaceAll(",", ""));
    } catch (NumberFormatException e) {
        throw new DataSpaceException("Failed to parse \"" + value + "\" as Double");
    }
}

From source file:net.estinet.gFeatures.Feature.gHub.crystal.Crystal.java

public void createFile() {
    File f = new File("plugins/gFeatures/gHub/Crystals");
    if (!f.isDirectory()) {
        f.mkdir();/* w  w w  . j a  v a2s . c  o  m*/
    }
    File[] listOfFiles = f.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {
        if (listOfFiles[i].isFile()) {
            try {
                List<String> lines = getLines(listOfFiles[i]);
                MGServer mgs = new MGServer(lines.get(0),
                        new Location(Bukkit.getWorld("EstiNet"), Double.parseDouble(lines.get(1)),
                                Double.parseDouble(lines.get(2)), Double.parseDouble(lines.get(3))));
                Basis.crystals.put(mgs.getLocation(), mgs);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}