parse value to double - Android java.lang

Android examples for java.lang:String Parse

Description

parse value to double

Demo Code


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

public class Main {
    /**//from ww  w .  j  av  a2s .c  om
     * parse value to double
     */
    public static double toDouble(Object value) {
        if (value instanceof Number) {
            return ((Number) value).doubleValue();
        }
        return value == null ? 0 : toDouble(String.valueOf(value));
    }

    /**
     * parse value to double
     */
    public static double toDouble(String value) {
        return TextUtils.isEmpty(value) ? 0 : Double.parseDouble(value);
    }
}

Related Tutorials