Example usage for java.lang Float parseFloat

List of usage examples for java.lang Float parseFloat

Introduction

In this page you can find the example usage for java.lang Float parseFloat.

Prototype

public static float parseFloat(String s) throws NumberFormatException 

Source Link

Document

Returns a new float initialized to the value represented by the specified String , as performed by the valueOf method of class Float .

Usage

From source file:Main.java

public static float parseFloat(String f, float def) {
    if (f == null) {
        return def;
    } else {//from   ww w .  java 2s  .co m
        try {
            return Float.parseFloat(f);
        } catch (NumberFormatException ex) {
            return 0;
        }
    }
}

From source file:Main.java

public static RectF toRectF(String flattened) {
    float[] bounds = new float[4];
    String[] strings = flattened.split(" ");
    for (int i = 0; i < 4; i++)
        bounds[i] = Float.parseFloat(strings[i]);
    return new RectF(bounds[0], bounds[1], bounds[2], bounds[3]);
}

From source file:Main.java

public static float[] stringToFloat(String s) {

    float[] arr = new float[24];
    String[] splits = s.split("\t");

    for (int i = 0; i < s.length(); i++) {
        try {//from  w w w .  j a  v  a2s .com
            arr[i] = Float.parseFloat(splits[i]);
        } catch (Exception e) {

        }
    }
    return arr;
}

From source file:Main.java

public static Float getAttribAsFloat(Element e, String name, Float dft) {
    String num = getAttribute(e, name);
    return num.equals("") ? dft : Float.parseFloat(num);
}

From source file:Main.java

public static Float getElementAsFloat(Element e, String name, Float dft) {
    String num = getElement(e, name);
    return num.equals("") ? dft : Float.parseFloat(num);
}

From source file:Main.java

public static float doFloat(Object obj, float defValue) {
    return obj != null ? Float.parseFloat(obj.toString()) : defValue;
}

From source file:Main.java

public static float getChildAsFloat(Element parent, String childName) {
    if (doesElementContainChildren(parent, childName)) {
        return Float.parseFloat(getFirstChildElement(parent, childName).getTextContent());
    }/*from   w  w w  . j  av a2s  .c o  m*/
    return -1f;
}

From source file:Main.java

public static String convertToCurrency(float value) {
    DecimalFormat format = new DecimalFormat("#.##");
    try {/*w  w  w.j a  v a 2 s .  c  o  m*/
        value = Float.parseFloat(format.format(value));
    } catch (Exception e) {
        e.printStackTrace();
    }
    NumberFormat defaultFormat = NumberFormat.getCurrencyInstance(Locale.CANADA);
    return defaultFormat.format(value);
}

From source file:Main.java

public static Float stringToFloat(String str) {
    if (str == null) {
        return null;
    } else {/*  ww  w  .  j  a  v  a 2  s. c  o m*/
        try {
            return Float.parseFloat(str);
        } catch (NumberFormatException e) {
            Log.w(TAG,
                    "Unable to interpret value " + str + " in field being "
                            + "converted to float, caught NumberFormatException <" + e.getMessage()
                            + "> field discarded");
            return null;
        }
    }
}

From source file:Main.java

public static float[] fromFloatString(String string) {
    String[] strings = string.replace("[", "").replace("]", "").split(", ");
    float result[] = new float[strings.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = Float.parseFloat(strings[i]);
    }//from   w  w  w. j a v a  2  s .  c o  m
    return result;
}