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

static float getLatitudeFromNmeaString(String latitude, String NS) {
    float med = Float.parseFloat(latitude.substring(2)) / 60.0f;
    med += Float.parseFloat(latitude.substring(0, 2));
    if (NS.startsWith("S")) {
        med = -med;/*from   www.j  a va  2  s  .c o m*/
    }
    return med;
}

From source file:Main.java

static float getLongitudeFromNmeaString(String longitude, String WE) {
    float med = Float.parseFloat(longitude.substring(3)) / 60.0f;
    med += Float.parseFloat(longitude.substring(0, 3));
    if (WE.startsWith("W")) {
        med = -med;//from  www . j  a  va  2  s  .  c  o  m
    }
    return med;
}

From source file:Main.java

public static float getFloatValue(Element ele, String tagName) {
    return Float.parseFloat(getTextValue(ele, tagName));
}

From source file:Main.java

public static float compute(String op1, String op2, char operator) {

    float o1 = Float.parseFloat(op1);
    float o2 = Float.parseFloat(op2);

    Log.e("Operand 1", op1);
    Log.e("Operand 2", op2);
    Log.e("Operator", operator + "");

    switch (operator) {
    case '-':
        return (o1 - o2);
    case '+':
        return (o1 + o2);
    case '/':
        return (o1 / o2);
    case '*':
        return (o1 * o2);
    default:/*from  w  w w . java 2 s  .c  om*/
        break;
    }
    return -1;
}

From source file:Main.java

public static float str2Float(String str) {
    if (TextUtils.isEmpty(str))
        return 0F;
    return Float.parseFloat(str);
}

From source file:Main.java

public static String floatToDuration(String duration_in_float) {
    duration_in_float = String.format("%2.2f", Float.parseFloat(duration_in_float));
    String[] parts = duration_in_float.split("\\.");
    long minute = Long.parseLong(parts[0]);
    long seconds = (60 * Long.parseLong(parts[1])) / 100;
    return String.format("%02d:%02d", minute, seconds);
}

From source file:Main.java

public static String c2f(String celsius) {
    if (!TextUtils.isEmpty(celsius)) {
        int fahrenheit = (int) (Float.parseFloat(celsius) * 9 / 5 + 32);
        return fahrenheit + "";
    } else {/* w  ww. j av  a 2s  . c  o m*/
        return "";
    }
}

From source file:Main.java

public static String f2c(String fahrenheit) {
    if (!TextUtils.isEmpty(fahrenheit)) {
        int celsius = (int) ((Float.parseFloat(fahrenheit) - 32) * 5 / 9);
        return celsius + "";
    } else {/*from   www.  j a v a 2s  . c  o  m*/
        return "";
    }
}

From source file:Main.java

public static String deletaDec(String de) {
    try {//  w  w  w .  j  a v a2s.c o  m
        float tem = Float.parseFloat(de);
        return String.valueOf((int) tem);
    } catch (Exception e) {
        Log.i(LOG_TAG, "deletaDec exception : wind = " + de);
        return "0";
    }
}

From source file:Main.java

public static Float getSafeFloatFromString(String value) {
    Float ret = 0.0f;/*from w  ww. ja va  2 s .c o m*/
    if (value.length() > 0)
        ret = Float.parseFloat(value);
    return ret;
}