List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:com.mycompany.sparkrentals.forms.BaseForm.java
public void validateNonNegativeFloat(String field, String value) { if (value == null || value.isEmpty()) { return;/*from w w w . ja va 2 s . co m*/ } try { float parsedFloat = Float.parseFloat(value); if (parsedFloat < 0) { errorMessages.add(field + " should be non-negative."); } else { cleanedData.put(field, parsedFloat); } } catch (NumberFormatException e) { errorMessages.add(field + " doesn't cotain a valid number."); } dataToDisplay.put(field, value); }
From source file:org.cellcore.code.engine.page.extractor.mcc.MCCPageDataExtractor.java
@Override protected float getPrice(Document doc) { Elements tr = doc.select("#blockContent").get(5).select("tr"); float iPrice = Float.MAX_VALUE; for (int i = 0; i < tr.size(); i++) { try {/* w w w . j a va 2 s . co m*/ String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text"); val = cleanPriceString(val); float price = Float.parseFloat(val); if (price < iPrice) { iPrice = price; } } catch (Throwable t) { } } if (iPrice == Float.MAX_VALUE) { iPrice = -1; } return iPrice; }
From source file:com.twosigma.beaker.fileloader.CsvPlotReader.java
private Object convertToNumber(Object value) { if (value instanceof String && NumberUtils.isNumber((String) value)) { return Float.parseFloat((String) value); } else {//from w ww . j a va2s.c om return value; } }
From source file:com.neu.controller.AdditionSuccessController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //throw new UnsupportedOperationException("Not yet implemented"); int result = 0; DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(); int count = (Integer) (session.getAttribute("count")); try {/*from w ww. j a v a2 s . c o m*/ QueryRunner run = new QueryRunner(ds); ResultSetHandler<Books> books = new BeanHandler<Books>(Books.class); for (int i = 1; i <= count; i++) { String isbnField = "isbn" + i; String titleField = "title" + i; String authorField = "author" + i; String priceField = "price" + i; String isbn = request.getParameter(isbnField).replaceAll("<|>|@|;|,|=|}|$|&", ""); String title = request.getParameter(titleField).replaceAll("<|>|@|;|,|=|}|$|&", ""); String author = request.getParameter(authorField).replaceAll("<|>|@|;|,|=|}|$|&", ""); float price = Float .parseFloat(request.getParameter(priceField).replaceAll("<|>|@|;|,|=|}|$|&", "")); Object[] params = new Object[4]; params[0] = isbn; params[1] = title; params[2] = author; params[3] = price; result = run.update("Insert into books(isbn,title,authors,price) values(?,?,?,?)", params); } } catch (Exception ex) { System.out.println("Details Not Added In DB!! " + ex.getMessage()); } if (result > 0) { mv.setViewName("success"); } else { mv.setViewName("error"); } return mv; }
From source file:com.nextep.designer.Application.java
public Object start(IApplicationContext context) { // Adding debug logs here since when we got a configuration problem we fail in these early // steps.//from w w w .j ava2 s . c o m log.debug("Creating display..."); //$NON-NLS-1$ Display display = PlatformUI.createDisplay(); log.debug("Display OK, checking java version..."); //$NON-NLS-1$ String javaVersion = System.getProperty("java.version"); //$NON-NLS-1$ Float d = Float.parseFloat(javaVersion.substring(0, 3)); if (d.floatValue() < 1.6f) { MessageDialog.openError(null, DesignerMessages.getString("application.javaTooOldError.title"), //$NON-NLS-1$ DesignerMessages.getString("application.javaTooOldError.message") + javaVersion + "."); //$NON-NLS-1$ //$NON-NLS-2$ return IApplication.EXIT_OK; } try { log.debug("Creating workbench..."); //$NON-NLS-1$ int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) { return IApplication.EXIT_RESTART; } return IApplication.EXIT_OK; } finally { display.dispose(); } }
From source file:edu.ehu.galan.wiki2wordnet.wikipedia2wordnet.Mapper.java
/** * Loads the mappings file from Wordnet 3.0 Fernando P.h.D thessis BZ2 format * http://staffwww.dcs.shef.ac.uk/people/S.Fernando/mappings.shtml * * @param pFileMappings - The bz2 file containing the mappings * @return HashMap<String,Wiki2WordnetMapping> - containing the mappings * (wikiTitle,Wiki2WordnetMapping)//from w ww . ja v a 2 s.com * */ public static HashMap<String, Wiki2WordnetMapping> loadFernandoMappings(String pFileMappings) { try { BufferedReader reader = null; String inputLine; reader = FileUtils.getBufferedReaderForBZ2File(pFileMappings); HashMap<String, Wiki2WordnetMapping> mappings = new HashMap<>(); String wikiTitle; String wordnetSynset; while ((inputLine = reader.readLine()) != null) { if (!inputLine.isEmpty()) { String[] line = inputLine.split("\t"); wordnetSynset = line[0]; String[] data = line[2].split("#"); String wikiId = data[0]; wikiTitle = data[1].replaceAll("_", " "); String wordnetName = line[1].replaceAll("_", " "); float confidence = Float.parseFloat(data[2]); mappings.put(wikiTitle, new Wiki2WordnetMapping(wikiTitle, wordnetName, Integer.parseInt(wordnetSynset), Integer.parseInt(wikiId), confidence, Wiki2WordnetMapping.WordnetType.noun)); } } return mappings; } catch (FileNotFoundException ex) { logger.error("File with babelnet mappings not found ", ex); } catch (CompressorException | IOException ex) { logger.error("Error with the bz2 format of IO exception: ", ex); } return null; }
From source file:hongik.android.project.best.ReviewDetailActivity.java
public void drawReview() { String query = "func=reviewdetail" + "&cid=" + cid + "&license=" + license; DBConnector conn = new DBConnector(query); conn.start();//from w ww. j av a 2 s . com try { conn.join(); JSONObject jsonResult = conn.getResult(); boolean result = jsonResult.getBoolean("result"); if (!result) { Toast.makeText(this, "Can not bring data", Toast.LENGTH_SHORT).show(); return; } JSONObject json = jsonResult.getJSONArray("values").getJSONObject(0); ((TextViewPlus) findViewById(R.id.reviewdetail_title)).setText(json.getString("SNAME")); ((TextViewPlus) findViewById(R.id.reviewdetail_address)).setText(json.getString("ADDR")); ((TextViewPlus) findViewById(R.id.reviewdetail_author)).setText(cid); ((RatingBar) findViewById(R.id.reviewdetail_grade)) .setRating(Float.parseFloat(json.getString("GRADE"))); ((EditTextPlus) findViewById(R.id.reviewdetail_text)).setText(json.getString("NOTE")); ((TextViewPlus) findViewById(R.id.reviewdetail_date)).setText(json.getString("DAY")); } catch (Exception ex) { } }
From source file:account.management.controller.inventory.StockReportController.java
@Override public void initialize(URL url, ResourceBundle rb) { product_list = FXCollections.observableArrayList(); try {// www.j a va 2 s . co m HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "all/products").asJson(); JSONArray array = res.getBody().getArray(); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); int id = obj.getInt("id"); String name = obj.getString("name"); float p_qty = Float.parseFloat(obj.get("p_qty").toString()); float s_qty = Float.parseFloat(obj.get("s_qty").toString()); double last_p_rate = obj.getDouble("last_p_rate"); double last_s_rate = obj.getDouble("last_s_rate"); double avg_p_rate = obj.getDouble("avg_p_rate"); double avg_s_rate = obj.getDouble("avg_s_rate"); product_list .add(new Product(id, name, p_qty, s_qty, last_p_rate, last_s_rate, avg_p_rate, avg_s_rate)); } } catch (Exception e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error in the server. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:com.storageroomapp.client.util.JsonSimpleUtil.java
/** * Convenience method for pulling a Float value off of a JSONObject * @param obj the JSONObject received from the server * @param key the String key of the value we want * @param defaultValue the Float to return if a value is not found (can be null) * @return the Float value, or null if not found or not a float *//* www .j a va 2s . com*/ static public Float parseJsonFloatValue(JSONObject obj, String key, Float defaultValue) { if ((obj == null) || (key == null)) { return defaultValue; } Float value = defaultValue; Object valueObj = obj.get(key); if (valueObj != null) { String valueStr = valueObj.toString(); try { value = Float.parseFloat(valueStr); } catch (NumberFormatException nfe) { // TODO log value = defaultValue; } } return value; }
From source file:org.cellcore.code.engine.page.extractor.mb.MBPageDataExtractor.java
protected float getPrice(Document doc) { if (!doc.getElementsContainingText("Cette carte n'est pas disponible en stock").isEmpty()) { return -1; }//from ww w. j av a 2 s.c o m Elements tr = doc.select(".stock").get(0).getElementsByTag("tr"); float iPrice = Float.MAX_VALUE; for (int i = 1; i < tr.size(); i++) { String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text"); val = cleanPriceString(val); float price = Float.parseFloat(val); if (price < iPrice) { iPrice = price; } } return iPrice; }