List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:account.management.controller.ReportTrialBalanceController.java
public TrialBalance getBalanace(String id, JSONArray arrayIn) { for (int i = 0; i < arrayIn.length(); i++) { JSONObject obj = arrayIn.getJSONObject(i); if (obj.get("id").toString().equals(id)) { String name = obj.getString("name"); String balance = String.format("%1$.2f", obj.getDouble("balance")); ;//from w w w. ja v a 2 s . c om String dr, cr; if (Float.parseFloat(balance) < 0) { cr = String.valueOf(Float.parseFloat(balance) * (-1)); dr = ""; } else { dr = balance; cr = ""; } return new TrialBalance(name, dr, cr); } } return null; }
From source file:com.z.controllers.HomeController.java
@RequestMapping(value = "establecimientos/Count/{localidad}/{departamento}/{lat}/{lng}/{distanciaKM}/{regimen}", method = RequestMethod.GET) public @ResponseBody HashMap<String, Integer> getEstbylocdepCount(@PathVariable("localidad") String localidad, @PathVariable("departamento") String departamento, @PathVariable("lat") String lat, @PathVariable("lng") String lng, @PathVariable("distanciaKM") double distanciaKM, @PathVariable("regimen") String regimen) { Criteria criteria = new CriteriaDistance(Float.parseFloat(lat), Float.parseFloat(lng), distanciaKM); List<Establecimientos> establecimientos; if (regimen.equals("Todos")) { establecimientos = criteria//from w w w.java 2 s .c om .meetCriteria(establecimientosDAO.listByLocalidadAndDepartamento(localidad, departamento)); } else { establecimientos = criteria.meetCriteria( establecimientosDAO.listByLocalidadAndDepartamento(localidad, departamento, regimen)); } HashMap<String, Integer> regimens = new HashMap(); regimens.put("Publico", 0); regimens.put("Privado Subvencionado", 0); regimens.put("Privado No Subvencionado", 0); for (Establecimientos establecimiento : establecimientos) { if (regimens.containsKey(establecimiento.getRegimen())) { regimens.put(establecimiento.getRegimen(), regimens.get(establecimiento.getRegimen()) + 1); } } regimens.put("Total", establecimientos.size()); return regimens; }
From source file:com.hichinaschool.flashcards.preferences.StepsPreference.java
/** * Convert steps format. For better usability, rounded floats are converted to integers (e.g., * 1.0 is converted to 1)./*from ww w . j a va 2 s . com*/ * * @param steps String representation of steps. * @return The steps as a JSONArray or null if the steps are not valid. */ public static JSONArray convertToJSON(String steps) { JSONArray ja = new JSONArray(); steps = steps.trim(); if (TextUtils.isEmpty(steps)) { return ja; } try { for (String s : steps.split("\\s+")) { float f = Float.parseFloat(s); // 0 or less is not a valid step. if (f <= 0) { return null; } // Use whole numbers if we can (but still allow decimals) int i = (int) f; if (i == f) { ja.put(i); } else { ja.put(f); } } } catch (NumberFormatException e) { return null; } catch (JSONException e) { // Can't serialize float. Value likely too big/small. return null; } return ja; }
From source file:edu.internet2.middleware.shibboleth.common.config.metadata.AbstractReloadingMetadataProviderBeanDefinitionParser.java
/** * Gets the refresh delay factor for the metadata provider. * /* w w w . j av a 2 s . c o m*/ * @param config provider configuration element * * @return refresh delay factor */ protected float getRefreshDelayFactor(Element config) { float delayFactor = 0.75f; if (config.hasAttributeNS(null, "refreshDelayFactor")) { String factorString = config.getAttributeNS(null, "refreshDelayFactor"); try { delayFactor = Float.parseFloat(factorString); } catch (NumberFormatException e) { log.error("Metadata provider had invalid refreshDelayFactor value '{}', using default value", factorString); } } if (delayFactor <= 0.0 || delayFactor >= 1.0) { log.error("Metadata provider had invalid refreshDelayFactor value '{}', using default value", delayFactor); delayFactor = 0.75f; } return delayFactor; }
From source file:MSUmpire.SpectrumParser.mzXMLReadUnit.java
public ScanData Parse() throws ParserConfigurationException, SAXException, IOException, DataFormatException { if (XMLtext.replaceFirst("</scan>", "").contains("</scan>")) { XMLtext = XMLtext.replaceFirst("</scan>", ""); }/* ww w . j av a2 s .co m*/ if (!XMLtext.contains("</scan>")) { XMLtext += "</scan>"; } ScanData scan = new ScanData(); final DocumentBuilder docBuilder = tls.get(); docBuilder.reset(); InputSource input = new InputSource(new StringReader(XMLtext)); Document doc = null; try { doc = docBuilder.parse(input); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); Logger.getRootLogger().error(XMLtext); } Node root = doc.getFirstChild(); for (int i = 0; i < root.getAttributes().getLength(); i++) { switch (root.getAttributes().item(i).getNodeName()) { case ("num"): scan.ScanNum = Integer.parseInt(root.getAttributes().item(i).getNodeValue()); break; case ("centroided"): { if ("1".equals(root.getAttributes().item(i).getNodeValue())) { scan.centroided = true; } else { scan.centroided = false; } break; } case ("msLevel"): scan.MsLevel = Integer.parseInt(root.getAttributes().item(i).getNodeValue()); break; case ("scanType"): scan.scanType = root.getAttributes().item(i).getNodeValue(); break; case ("peaksCount"): scan.PeaksCountString = Integer.parseInt(root.getAttributes().item(i).getNodeValue()); break; case ("retentionTime"): scan.RetentionTime = Float.parseFloat(root.getAttributes().item(i).getNodeValue().substring(2, root.getAttributes().item(i).getNodeValue().indexOf("S"))) / 60f; break; case ("lowMz"): { String value = root.getAttributes().item(i).getNodeValue(); if ("inf".equals(value)) { value = String.valueOf(Float.MIN_VALUE); } scan.StartMz = Float.parseFloat(value); break; } case ("highMz"): { String value = root.getAttributes().item(i).getNodeValue(); if ("inf".equals(value)) { value = String.valueOf(Float.MAX_VALUE); } scan.EndMz = Float.parseFloat(value); break; } case ("startMz"): scan.StartMz = Float.parseFloat(root.getAttributes().item(i).getNodeValue()); break; case ("endMz"): { String value = root.getAttributes().item(i).getNodeValue(); if ("inf".equals(value)) { value = String.valueOf(Float.MAX_VALUE); } scan.EndMz = Float.parseFloat(value); break; } case ("basePeakMz"): { String value = root.getAttributes().item(i).getNodeValue(); if ("inf".equals(value)) { value = String.valueOf(Float.MAX_VALUE); } scan.BasePeakMz = Float.parseFloat(value); break; } case ("basePeakIntensity"): scan.BasePeakIntensity = Float.parseFloat(root.getAttributes().item(i).getNodeValue()); break; case ("totIonCurrent"): scan.SetTotIonCurrent(Float.parseFloat(root.getAttributes().item(i).getNodeValue())); break; } } for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node childNode = root.getChildNodes().item(i); switch (childNode.getNodeName()) { case ("precursorMz"): { scan.PrecursorMz = Float.parseFloat(childNode.getTextContent()); for (int j = 0; j < childNode.getAttributes().getLength(); j++) { switch (childNode.getAttributes().item(j).getNodeName()) { case ("precursorScanNum"): scan.precursorScanNum = Integer.parseInt(childNode.getAttributes().item(j).getNodeValue()); break; case ("precursorIntensity"): scan.PrecursorIntensity = Float .parseFloat(childNode.getAttributes().item(j).getNodeValue()); break; case ("precursorCharge"): scan.PrecursorCharge = Integer.parseInt(childNode.getAttributes().item(j).getNodeValue()); break; case ("activationMethod"): scan.ActivationMethod = childNode.getAttributes().item(j).getNodeValue(); break; case ("windowWideness"): scan.windowWideness = Float.parseFloat(childNode.getAttributes().item(j).getNodeValue()); break; } } break; } case ("peaks"): { for (int j = 0; j < childNode.getAttributes().getLength(); j++) { switch (childNode.getAttributes().item(j).getNodeName()) { case ("compressionType"): scan.compressionType = childNode.getAttributes().item(j).getNodeValue(); break; case ("precision"): scan.precision = Integer.parseInt(childNode.getAttributes().item(j).getNodeValue()); break; } } ParsePeakString(scan, childNode.getTextContent()); break; } } childNode = null; } if ("calibration".equals(scan.scanType)) { scan.MsLevel = -1; } XMLtext = null; scan.Data.Finalize(); return scan; }
From source file:com.polyvi.xface.extension.audio.XAudioExt.java
@Override public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException { String appId = mWebContext.getApplication().getAppId(); XExtensionResult.Status status = XExtensionResult.Status.NO_RESULT; if (action.equals(COMMAND_PLAY)) { XAudioStatusChangeListener listener = new XAudioStatusChangeListener(callbackCtx); play(args.getString(0), args.getString(1), mWebContext.getWorkSpace(), listener); } else if (action.equals(COMMAND_STOP)) { stop(args.getString(0));/* w w w . j a v a2 s. co m*/ } else if (action.equals(COMMAND_PAUSE)) { pause(args.getString(0)); } else if (action.equals(COMMAND_SEEKTO)) { seekTo(args.getString(0), args.getInt(1)); } else if (action.equals(COMMAND_RELEASE)) { boolean ret = release(args.getString(0)); return new XExtensionResult(status, ret); } else if (action.equals(COMMAND_GETCURRENTPOSITION)) { int pos = getCurrentPosition(args.getString(0), appId); return new XExtensionResult(XExtensionResult.Status.OK, pos); } else if (action.equals(COMMAND_STARTRECORDING)) { XAudioStatusChangeListener listener = new XAudioStatusChangeListener(callbackCtx); startRecording(args.getString(0), args.getString(1), mWebContext.getWorkSpace(), listener); } else if (action.equals(COMMAND_STOPRECORDING)) { stopRecording(args.getString(0)); } else if (action.equals(COMMAND_SETVOLUME)) { setVolume(args.getString(0), Float.parseFloat(args.getString(1))); } return new XExtensionResult(status); }
From source file:com.moto.miletus.application.ble.neardevice.NearDeviceNotification.java
/** * notification// www .jav a2s. c o m * * @param room String * @param light ParameterValue * @param temp ParameterValue */ private void notification(final String room, final ParameterValue light, final ParameterValue temp) { String msg; if (room == null) { systemService.cancelAll(); return; } else if (light != null && temp != null) { msg = "Welcome to: " + room + Strings.NEW_LINE + "Light: " + light.getValue() + Strings.LUX + Strings.NEW_LINE; try { String tempRound = Precision.round(Float.parseFloat(temp.getValue()), 1) + ""; msg = msg + "Temp: " + tempRound + Strings.CELSIUS + Strings.NEW_LINE; } catch (NumberFormatException ex) { Log.e(TAG, ex.toString()); } } else { msg = "Welcome to: " + room + Strings.NEW_LINE; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.miletus).setContentTitle("Room Status") .setPriority(NotificationCompat.PRIORITY_MAX).setContentText(msg); Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); systemService.notify(9812, mBuilder.build()); Log.i(TAG, msg); }
From source file:com.ahm.fileupload.FileController.java
public void readLastInputColumn(File csvFile) { String line = ""; String cvsSplitBy = ","; BufferedReader br = null;//w w w . j a v a 2 s . c o m try { br = new BufferedReader(new FileReader(csvFile)); while ((line = br.readLine()) != null) { String[] data = line.split(cvsSplitBy); //System.out.println(data[2]); float val = Float.parseFloat(data[data.length - 1]); if (val < this.targetsMin) { this.targetsMin = val; } if (val > this.targetsMax) { this.targetsMax = val; } targets.add(val); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.clican.pluto.common.resource.MapResource.java
public float getFloat(String key, float defval) { String s = get(key);/* w w w . j av a 2 s . co m*/ if (s == null) { return defval; } try { return Float.parseFloat(s); } catch (NumberFormatException e) { throw new IllegalArgumentException("Property must be an float value :" + key); } }
From source file:model.Modele.java
/** * Methode qui sauvegarde les donnes dans des objets (RAM) * * @param file le fichier sauvegarder//from w ww . j a v a 2 s . c o m * @return le nom de fichier pour l'afficher sur la rubrique des donnes */ public String Save_data(File file) { String last_last_1 = null; String last_last_2 = null; try (BufferedReader br = new BufferedReader(new FileReader(file))) { final String fileName = file.toURI().toString(); String fileNamelast = null; String[] fileNames = fileName.toString().split("/"); String last_part = fileNames[7]; String[] parts = last_part.split("\\."); String last_last_part = parts[1]; last_last_1 = last_last_part.substring(0, 4); last_last_2 = last_last_part.substring(4, 6); List<String> row = new ArrayList<>(); String line; donnes = new ArrayList<>(); boolean line_one = false; double val_proggress = 0.0; while ((line = br.readLine()) != null) { if (line_one) { row.clear(); donnes.add(line); int i = 0; for (String retval : line.split(";")) { if (i == 0 || i == 1 || i == 7 || i == 9 || i == 14) { row.add(retval); } i++; } if (row.size() == 5) { String c; if (!row.get(2).equals("mq")) { Float kelvin = Float.parseFloat(row.get(2)); Float celsius = kelvin - 273.15F; c = Float.toString(celsius); } else { c = "0"; } //conversion des erreurs : if (row.get(0).equals("mq")) { row.set(0, "0"); } if (row.get(1).equals("mq")) { row.set(1, "0"); } if (row.get(2).equals("mq")) { row.set(2, "0"); } if (row.get(3).equals("mq")) { row.set(3, "0"); } if (row.get(4).equals("mq")) { row.set(4, "0"); } add_or_create(row, c); } } line_one = true; } } catch (IOException ex) { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex); } list_donnee.add("DATA existe, Date : " + last_last_1 + " - " + last_last_2); return "DATA existe, Date : " + last_last_1 + " - " + last_last_2; }