List of utility methods to do String to Float Convert
double | String2AmountFloat(String str) String Amount Float try { String tempStr = NumberFormat.getNumberInstance() .format(Long.parseLong(str, 10)).replace(",", ""); return Long.parseLong(tempStr) / 100.00; } catch (Exception e) { e.printStackTrace(); return 0.00; |
boolean | isFloat(String str) is Float if (isLong(str)) { return true; Pattern pattern = Pattern.compile("\\d*\\.{1}\\d+"); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; return true; |
boolean | isFloat(String str, int precision) is Float String regStr = "\\d*\\.{1}\\d{" + precision + "}"; Pattern pattern = Pattern.compile(regStr); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; return true; |
double | getFloatValue(double val, int len) get Float Value if (len <= 0) { return val; int lastVal = (int) (val * (Math.pow(10, len + 1))) - ((int) (val * (Math.pow(10, len)))) * 10; if (lastVal < 5) { return ((int) (val * (Math.pow(10, len)))) / (Math.pow(10, len)); ... |
float | parseFloat(String string, float defValue) Parses string to float try { return Float.parseFloat(string); } catch (NumberFormatException nfe) { return defValue; |
float | TryParse(String str, float defaultFloat) Try Parse try { float f = Float.parseFloat(str); return f; } catch (NumberFormatException ex) { return defaultFloat; |
float | parseFloat(String value) parse Float float result = (float) 0.00; if (value.length() > 0) { try { result = round(Float.parseFloat(value), 1); } catch (Exception e) { return (float) 0.00; return result; |