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 String cmsToInches(String cmsAsString) {
    try {//  ww w . j a va 2  s  .c  o m
        float cms = Float.parseFloat(cmsAsString);
        float inches = cms / CMS_PER_INCH;
        return String.format(Locale.US, "%.1f \"", inches);
    } catch (NumberFormatException e) {
        /*- not a number, text is shown without parsing it */
        return cmsAsString;
    }
}

From source file:Main.java

public static float parseFloat(String v, float _default) {

    if (v == null || v.equals(""))
        return _default;

    return Float.parseFloat(v);

}

From source file:Main.java

public static int timeInMS(String time) {
    int t = 0;//  www  . j  a v  a  2  s .com
    int i = time.indexOf(".");
    int mult = 1000;

    if (i != -1) {
        t += mult * Float.parseFloat(time.substring(i));
        time = time.substring(0, i);
    }
    String[] parts = time.split(":");
    for (i = parts.length - 1; i >= 0; i--) {
        t += Integer.parseInt(parts[i]) * mult;
        mult *= 60;
    }

    return t;
}

From source file:Main.java

public static float changToTwoDecimal(float in) {
    DecimalFormat df = new DecimalFormat("0.00");
    String out = df.format(in);//from  w ww . ja va 2  s  .c  om
    return Float.parseFloat(out);
}

From source file:Main.java

public static float parseFloat(String str) {
    if (!"".equals(str) && !"null".equals(str) && str != null && isNumeric(str)) {
        return Float.parseFloat(str);
    } else {//from   w  w  w.  java  2s. c o m
        return (float) 0.0;
    }
}

From source file:Main.java

public static float readFloat(Node node, String attributeName, float def) {
    try {//from  ww  w.ja va2 s .  c o m
        return Float.parseFloat(node.getAttributes().getNamedItem(attributeName).getNodeValue());
    } catch (Exception ex) {
        return def;
    }
}

From source file:Main.java

public static float[] getFloatArray(String str) {
    String[] list = str.split(",");
    float[] ar = new float[list.length];
    int i = 0;/*from w  w  w  . j av a2s .co m*/
    for (String s : list) {
        ar[i++] = Float.parseFloat(s);
    }
    return ar;
}

From source file:Main.java

/**
 *
 * @param number//  ww  w .j  a  va2  s .co m
 * @param defaultValue
 * @return
 */
public static float convertStringToFloat(String number, float defaultValue) {
    try {
        return Float.parseFloat(number);
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:Main.java

public static float[] toFloatArray(String flattened) {
    String[] list = flattened.split(" ");
    float[] points = new float[list.length];
    for (int i = 0; i < list.length; i++)
        points[i] = Float.parseFloat(list[i]);
    return points;
}

From source file:Main.java

public static float yiweixiaoshu2(String value) {
    if ("0".equals(value) || "0.0".equals(value) || "0.00".equals(value)) {
        return 0f;
    }/*  w w  w. j  ava 2 s.c om*/
    float a = Float.parseFloat(value);
    float b = (float) (Math.round(a * 10)) / 10;
    return b;
}