List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:Main.java
public static float getFloatAttribute(Node node, String name, float defVal) { String att = getAttribute(node, name); if (att == null) return defVal; return Float.parseFloat(att); }
From source file:Main.java
public static float toFloat(String value) { if (TextUtils.isEmpty(value)) return 0.0f; try {//from w ww .ja v a 2 s. co m float val = Float.parseFloat(value); return val; } catch (NumberFormatException ex) { return 0.0f; } }
From source file:Main.java
public static Float testNumber(String aArg) { while (true) { if (aArg.length() == 0) { return null; }/*from ww w. ja v a 2 s . c om*/ if (aArg.matches("-?\\d+(\\.\\d+)?") == true) { break; } else { throw new IllegalArgumentException("not a number"); } } return Float.parseFloat(aArg); }
From source file:Main.java
/** * Parses a float./*from ww w . j a v a 2 s .c o m*/ * If null or not a float, the default is returned. * * @param s a string * @param defaultValue the default * @return the parsed result */ public static float parseFloat(String s, float defaultValue) { if (s == null) return defaultValue; try { return Float.parseFloat(s); } catch (NumberFormatException e) { return defaultValue; } }
From source file:Main.java
public static float convertStringToFloat(String s) { try {/* w ww.j a v a 2s. com*/ return Float.parseFloat(s); } catch (Exception e) { return 0; } }
From source file:Main.java
/** * Gets the String value as float.// www .j av a 2 s . com */ public final static float getStringAsFloat(String value) { return value == null ? -1 : Float.parseFloat(value); }
From source file:Main.java
public static float bracketFloat(String str, float floor, float ceiling) throws NumberFormatException { float val = 0f; try {//from w w w. j a v a 2 s. c o m val = Float.parseFloat(str); } catch (NumberFormatException e) { e.printStackTrace(); } val = bracketFloat(val, floor, ceiling); return val; }
From source file:Main.java
/** * /*w ww . ja v a 2s . c om*/ * @param object * @return */ protected static Float toFloat(Object object) { String str = toString(object); if ("".equals(str)) return 0.0f; else return Float.parseFloat(str); }
From source file:Main.java
public static float getDescendentTextAsFloat(Node node, String name, float defaultValue) throws IOException { Node d = getDescendent(node, name); if (d != null) { String sval = d.getTextContent().trim(); return Float.parseFloat(sval); }// w w w. j a va2s. c om return defaultValue; }
From source file:Main.java
public static Boolean isEnoughtBattery(Context context) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); Float acceptableBatteryLevel = Float.parseFloat(pref.getString("pref_battery_level", "40.0f")); Float batteryLevel = getBatteryLevel(context); return (batteryLevel >= acceptableBatteryLevel || isCharging(context)); }