Example usage for java.lang Float parseFloat

List of usage examples for java.lang Float parseFloat

Introduction

In this page you can find the example usage for java.lang Float parseFloat.

Prototype

public static float parseFloat(String s) throws NumberFormatException 

Source Link

Document

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

Usage

From source file:org.trustedanalytics.scoringengine.ATKScoringEngine.java

public Boolean score(float[] data) {
    String commaSeparatedNumbers = convertToCommaSeparated(data);
    String url = getUrl() + commaSeparatedNumbers;
    Float result;/*from  www.  j  av a  2  s . c o m*/
    try {
        RestTemplate template = new RestTemplate();
        ResponseEntity<String> response = template.postForEntity(url, null, String.class);
        String body = response.getBody();
        result = Float.parseFloat(body);
        LOG.debug("Score from scoring engine: {}", result);
    } catch (Exception ex) {
        LOG.warn("problem with getting scoring result! " + ex.getMessage(), ex);
        result = -100f;
    }

    return result.compareTo(1.0f) == 0;
}

From source file:eu.cassandra.sim.utilities.Utils.java

public static float getFloat(Object o) {
    if (o == null) {
        return 0.0f;
    } else {//from   w  ww  .j  av  a2  s  .  c  o m
        return Float.parseFloat(o.toString());
    }
}

From source file:com.google.blockly.model.FieldAngle.java

@Override
public boolean setFromString(String text) {
    try {/*from   ww w  .  ja  va2 s  .co m*/
        setAngle(Float.parseFloat(text));
    } catch (NumberFormatException e) {
        return false;
    }
    return true;
}

From source file:com.fluke.application.IEODReader.java

private static void process(String stockName, List<String> lines) {
    List<IntradayTicker> tickers = new ArrayList<>();
    for (String line : lines) {
        if (line.toLowerCase().contains("<ticker>")) {
            continue;
        }// www . ja  va2 s  . com
        String parts[] = line.split(",");
        IntradayTicker ticker = new IntradayTicker();
        ticker.setTime(getTimestamp(parts[1], parts[2]));
        ticker.setOpenPrice(Float.parseFloat(parts[3]));
        ticker.setHighPrice(Float.parseFloat(parts[4]));
        ticker.setLowPrice(Float.parseFloat(parts[5]));
        ticker.setClosePrice(Float.parseFloat(parts[6]));
        ticker.setVolume(Integer.parseInt(parts[7]));
        tickers.add(ticker);
        stockName = parts[0];
    }
    new IntraDayDao().insertBatch(stockName, tickers);
}

From source file:com.mycompany.couchdb.CsvManage.java

public boolean hello() throws FileNotFoundException, IOException {
    int count = 0;
    String filename = "src/main/resources/GeoLiteCity-Location.csv";
    City city;/*w  w  w  .  jav a 2  s  .  c  om*/
    DataDealer cityDao;

    cityDao = new DataDealer();

    Reader in = new FileReader(filename); //read file
    CSVParser parser = new CSVParser(in, CSVFormat.EXCEL.withHeader()); //create parser
    city = new City();
    for (CSVRecord record : parser) {
        //parse file and create objects

        //city.setLocId(Integer.parseInt(record.get("locId")));
        //city.setCountry(record.get("country"));
        city.setCity(record.get("city"));
        //city.setRegion(record.get("region"));
        city.setLatitude(Float.parseFloat(record.get("latitude")));
        city.setLongitude(Float.parseFloat(record.get("longitude")));

        //

        try {
            cityDao.save(city);

        } finally {
            cityDao.finalize();
        }

    }
    return true;
}

From source file:edu.msu.cme.rdp.classifier.comparison.ComparisonCmd.java

public static void main(String[] args) throws Exception {

    String queryFile1 = null;/*from   w  w w .  ja  va 2 s . c  o  m*/
    String queryFile2 = null;
    String class_outputFile = null;
    String compare_outputFile = null;
    String propFile = null;
    ClassificationResultFormatter.FORMAT format = CmdOptions.DEFAULT_FORMAT;
    float conf_cutoff = CmdOptions.DEFAULT_CONF;
    String gene = null;

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption(QUERYFILE1_SHORT_OPT)) {
            queryFile1 = line.getOptionValue(QUERYFILE1_SHORT_OPT);
        } else {
            throw new Exception("queryFile1 must be specified");
        }
        if (line.hasOption(QUERYFILE2_SHORT_OPT)) {
            queryFile2 = line.getOptionValue(QUERYFILE2_SHORT_OPT);
        } else {
            throw new Exception("queryFile2 must be specified");
        }

        if (line.hasOption(CmdOptions.OUTFILE_SHORT_OPT)) {
            class_outputFile = line.getOptionValue(CmdOptions.OUTFILE_SHORT_OPT);
        } else {
            throw new Exception("outputFile for classification results must be specified");
        }

        if (line.hasOption(COMPARE_OUTFILE_SHORT_OPT)) {
            compare_outputFile = line.getOptionValue(COMPARE_OUTFILE_SHORT_OPT);
        } else {
            throw new Exception("outputFile for comparsion results must be specified");
        }

        if (line.hasOption(CmdOptions.TRAINPROPFILE_SHORT_OPT)) {
            if (gene != null) {
                throw new IllegalArgumentException(
                        "Already specified the gene from the default location. Can not specify train_propfile");
            } else {
                propFile = line.getOptionValue(CmdOptions.TRAINPROPFILE_SHORT_OPT);
            }
        }
        if (line.hasOption(CmdOptions.BOOTSTRAP_SHORT_OPT)) {
            conf_cutoff = Float.parseFloat(line.getOptionValue(CmdOptions.BOOTSTRAP_SHORT_OPT));
        }
        if (line.hasOption(CmdOptions.FORMAT_SHORT_OPT)) {
            String f = line.getOptionValue(CmdOptions.FORMAT_SHORT_OPT);
            if (f.equalsIgnoreCase("allrank")) {
                format = ClassificationResultFormatter.FORMAT.allRank;
            } else if (f.equalsIgnoreCase("fixrank")) {
                format = ClassificationResultFormatter.FORMAT.fixRank;
            } else if (f.equalsIgnoreCase("filterbyconf")) {
                format = ClassificationResultFormatter.FORMAT.filterbyconf;
            } else if (f.equalsIgnoreCase("db")) {
                format = ClassificationResultFormatter.FORMAT.dbformat;
            } else {
                throw new IllegalArgumentException(
                        "Not valid output format, only allrank, fixrank, filterbyconf and db allowed");
            }

        }
        if (line.hasOption(CmdOptions.GENE_SHORT_OPT)) {
            if (propFile != null) {
                throw new IllegalArgumentException(
                        "Already specified train_propfile. Can not specify gene any more");
            }
            gene = line.getOptionValue(CmdOptions.GENE_SHORT_OPT).toLowerCase();

            if (!gene.equals(ClassifierFactory.RRNA_16S_GENE)
                    && !gene.equals(ClassifierFactory.FUNGALLSU_GENE)) {
                throw new IllegalArgumentException(gene + " is NOT valid, only allows "
                        + ClassifierFactory.RRNA_16S_GENE + " and " + ClassifierFactory.FUNGALLSU_GENE);
            }
        }
    } catch (Exception e) {
        System.out.println("Command Error: " + e.getMessage());
        new HelpFormatter().printHelp(120, "ComparisonCmd", "", options, "", true);
        return;
    }

    if (propFile == null && gene == null) {
        gene = ClassifierFactory.RRNA_16S_GENE;
    }

    ComparisonCmd cmd = new ComparisonCmd(propFile, gene);
    cmd.setConfidenceCutoff(conf_cutoff);
    printLicense();

    cmd.doClassify(queryFile1, queryFile2, class_outputFile, compare_outputFile, format);

}

From source file:org.cellcore.code.engine.page.extractor.mtgf.MTGFPageDataExtractor.java

@Override
protected float getPrice(Document doc) {
    String val = cleanPriceString(doc.select(".card-buy").get(0).select(".price").get(0).text());
    return Float.parseFloat(val);
}

From source file:de.uniwue.info2.numerics.prec.SinglePrecisionFloat.java

@Override
protected String floatValueToBinaryString(String value) {
    float f = Float.parseFloat(value);
    String binary;/*w  ww  . jav  a2s.c o m*/
    if (f == 0) {
        binary = StringUtils.repeat("0", 32);
    } else {
        binary = Integer.toBinaryString(Float.floatToIntBits(f));
    }
    return binary;
}

From source file:it.unibas.spicy.persistence.Types.java

public static Object getTypedValue(String type, Object value) throws DAOException {
    if (value == null || value.toString().equalsIgnoreCase("NULL")) {
        return NullValueFactory.getNullValue();
    }//from  w  ww .  j  a v  a 2s  .  c o  m
    if (type.equals(BOOLEAN)) {
        return Boolean.parseBoolean(value.toString());
    }
    if (type.equals(STRING)) {
        return value.toString();
    }
    if (type.equals(INTEGER)) {
        try {
            return Integer.parseInt(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(DOUBLE)) {
        try {
            return Double.parseDouble(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(FLOAT)) {
        try {
            return Float.parseFloat(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(DATE) || type.equals(DATETIME)) {
        return value.toString();
        //            try {
        //                return DateFormat.getDateInstance().parse(value.toString());
        //            } catch (ParseException ex) {
        //                logger.error(ex);
        //                throw new DAOException(ex.getMessage());
        //            }
    }
    return value.toString();
}

From source file:com.github.terma.jenkins.githubprcoveragestatus.CoberturaParser.java

@Override
public float get(String coberturaFilePath) {
    try {/*from  w w w.  j  a  v  a  2  s.c o m*/
        String content = FileUtils.readFileToString(new File(coberturaFilePath));
        float lineRate = Float.parseFloat(findFirst(content, "line-rate=\"([0-9.]+)\""));
        float branchRate = Float.parseFloat(findFirst(content, "branch-rate=\"([0-9.]+)\""));
        return lineRate / 2 + branchRate / 2;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}