parse value to float - Android java.lang

Android examples for java.lang:String Parse

Description

parse value to float

Demo Code


//package com.java2s;
import android.text.TextUtils;

public class Main {
    /**// w ww  .j  ava  2  s .  com
     * parse value to float
     */
    public static float toFloat(Object value) {
        if (value instanceof Number) {
            return ((Number) value).floatValue();
        }
        return value == null ? 0 : toFloat(String.valueOf(value));
    }

    /**
     * parse value to float
     */
    public static float toFloat(String value) {
        return TextUtils.isEmpty(value) ? 0 : Float.parseFloat(value);
    }
}

Related Tutorials