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 getLineSpacing(SharedPreferences preferences, String key, String defaultValue) { return Float.parseFloat(preferences.getString(key, defaultValue)); }
From source file:Main.java
/** * Convert float value wraped in string to float safely. *//*from ww w. jav a 2s .c o m*/ public static float toFloatSafely(String text) { float result = -1.0f; text = text.trim(); try { result = Float.parseFloat(text); } catch (NumberFormatException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static final float getFloatAttribute(final Attributes pAttributes, final String pAttributeName, final float pDefaultValue) { final String value = pAttributes.getValue("", pAttributeName); return (value != null) ? Float.parseFloat(value) : pDefaultValue; }
From source file:Main.java
public static String getSeperateAmount(double amount) { String double_format = "%1$.2f"; String total = String.format(double_format, amount); // return String.format(format, // "" +/* w w w . jav a 2 s . c o m*/ return addSeparateSign((int) Float.parseFloat(total)); }
From source file:Main.java
public static Float convertToFloat(String fStr) { try {//from w w w. ja v a 2s . c o m return Float.parseFloat(fStr); } catch (NumberFormatException e) { } return null; }
From source file:Main.java
public static float getTagValueAsFloat(Document document, String tagName) { float tagValue = -1.0f; String tempVal = getTagValueAsString(document, tagName); tagValue = Float.parseFloat(tempVal); return tagValue; }
From source file:Main.java
public static float floatAttr(final XmlPullParser pp, final String attrName) { return Float.parseFloat(pp.getAttributeValue(null, attrName).trim()); }
From source file:Main.java
/** * Check number.//from w w w . java 2s . c om * * @param value * the value * @return true, if successful */ public static boolean checkNumber(String value) { try { if (value == null || value.length() == 0) { return false; } Float.parseFloat(value); } catch (NumberFormatException nfe) { return false; } return true; }
From source file:Main.java
public static float getFloatProperty(Properties properties, String key, float defaultValue) { if (properties != null) { String value = properties.getProperty(key, "").trim(); if (!value.equals("")) { try { return Float.parseFloat(value); } catch (NumberFormatException var5) { ;/* w ww .j av a 2s . c om*/ } } } return defaultValue; }
From source file:Main.java
static final Float convertUnits(String name, XmlPullParser atts, float dpi, float width, float height) { String value = getStringAttr(name, atts); if (value == null) { return null; } else if (value.endsWith("px")) { return Float.parseFloat(value.substring(0, value.length() - 2)); } else if (value.endsWith("pt")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 72; } else if (value.endsWith("pc")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 6; } else if (value.endsWith("cm")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 2.54f; } else if (value.endsWith("mm")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi / 254; } else if (value.endsWith("in")) { return Float.valueOf(value.substring(0, value.length() - 2)) * dpi; } else if (value.endsWith("%")) { Float result = Float.valueOf(value.substring(0, value.length() - 1)); float mult; if (name.contains("x") || name.equals("width")) { mult = width / 100f;// www. jav a 2 s. c o m } else if (name.contains("y") || name.equals("height")) { mult = height / 100f; } else { mult = (height + width) / 2f; } return result * mult; } else { return Float.valueOf(value); } }