List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:Main.java
/** * parse value to float// w ww. ja v a 2s . c o m */ public static float toFloat(String value) { return TextUtils.isEmpty(value) ? 0 : Float.parseFloat(value); }
From source file:Main.java
private static Object convertValType(Object value, Class<?> fieldTypeClass) { Object retVal;//from w ww. j av a2s . co m if (Long.class == fieldTypeClass || long.class == fieldTypeClass) { retVal = Long.parseLong(value.toString()); } else if (Integer.class == fieldTypeClass || int.class == fieldTypeClass) { retVal = Integer.parseInt(value.toString()); } else if (Float.class == fieldTypeClass || float.class == fieldTypeClass) { retVal = Float.parseFloat(value.toString()); } else if (Double.class == fieldTypeClass || double.class == fieldTypeClass) { retVal = Double.parseDouble(value.toString()); } else { retVal = value; } return retVal; }
From source file:Main.java
/** * Parses the value of the given attribute as a float. * @param attributeName the name of the attribute. * @param map the map that contains all the attributes. * @return the float value.// w w w . j ava2 s. c o m */ public static float parseFloat(String attributeName, NamedNodeMap map) { org.w3c.dom.Node attr = map.getNamedItem(attributeName); try { return attr != null ? Float.parseFloat(attr.getTextContent()) : 0f; } catch (NumberFormatException ex) { return 0.0f; } }
From source file:Main.java
public static float parseFloat(String f) { if (f == null) { return 0; } else {//from ww w. j ava 2 s . c o m try { return Float.parseFloat(f); } catch (NumberFormatException ex) { return 0; } } }
From source file:Main.java
/** * Turns a string into a float array./*from www . ja v a 2s . c o m*/ * 'spaces' must only contain string equivalent of valid floats separated with commas * with no spaces. * @param string * @return a float array */ public static float[] stringToFloatArray(String string) { String strArray[] = string.split(","); int length = strArray.length; float floatArray[] = new float[length]; int i = 0; for (String str : strArray) { floatArray[i] = Float.parseFloat(str); i++; } return floatArray; }
From source file:Main.java
/** * Parses the given attribute of this tag and returns it as a float *//* ww w .ja v a 2s.c o m*/ public static float getAttribFloat(Element ele, String name) { String sval = ele.getAttribute(name); float val = 0.0f; try { val = Float.parseFloat(sval); } catch (Exception e) { } return val; }
From source file:Main.java
/** * Convert a string format float value to Float. * //from ww w . jav a2s . c o m * @param context * @param resID * @param defValue * @return */ public final static float getFloatSafely(Context context, int resID, float defValue) { try { String strValue = context.getResources().getString(resID); if (null == strValue) { return defValue; } return Float.parseFloat(strValue); } catch (Exception e) { e.printStackTrace(); return defValue; } }
From source file:Main.java
public static void startScaleAnime(final View view, float newScale, Animator.AnimatorListener listener) { ValueAnimator anime = ValueAnimator.ofFloat(view.getScaleX(), newScale); anime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . j a v a 2s .c o m public void onAnimationUpdate(ValueAnimator animation) { float s = Float.parseFloat(animation.getAnimatedValue().toString()); view.setScaleX(s); view.setScaleY(s); } }); if (listener != null) { anime.addListener(listener); } anime.setDuration(mAnimeDuration); anime.start(); }
From source file:Main.java
/** * Parses the supplied xsd:float string and returns its value. * /*from w w w. j a va2s. co m*/ * @param s * A string representation of an xsd:float value. * @return The <tt>float</tt> value represented by the supplied string * argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:float value. */ public static float parseFloat(String s) { s = trimPlusSign(s); return Float.parseFloat(s); }
From source file:Main.java
public static float getSize(String size) { float value = 15.0f; if (size != null) { Matcher m = SIZED_VALUE.matcher(size.trim()); if (m.matches()) { value = Float.parseFloat(m.group(1)); }/*w w w . j a v a 2 s .c o m*/ } return value; }