Java Double Number Create toDouble(String value, double defaultValue)

Here you can find the source of toDouble(String value, double defaultValue)

Description

convert the string to an double, and return the default value if the string is null or does not contain a valid int value

License

Open Source License

Parameter

Parameter Description
value string value
defaultValue default value

Return

double

Declaration

static public double toDouble(String value, double defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww w  .  j  a  v  a2s .  c om
     * convert the string to an double, and return the default value if
     * the string is null or does not contain a valid int value
     *
     * @param value string value
     * @param defaultValue default value
     *
     * @return double
     */
    static public double toDouble(String value, double defaultValue) {
        if (value != null) {
            try {
                return Double.parseDouble(value);
            } catch (NumberFormatException n) {
            }
        }
        return defaultValue;
    }

    /**
     * convert the string to an double, and return 0 if
     * the string is null or does not contain a valid int value
     *
     * @param value string value
     *
     * @return double
     */
    static public double toDouble(String value) {
        if (value != null) {
            try {
                return Double.parseDouble(value);
            } catch (NumberFormatException n) {
            }
        }
        return 0;
    }
}

Related

  1. toDouble(String val)
  2. toDouble(String value)
  3. toDouble(String value)
  4. toDouble(String value)
  5. toDouble(String value)
  6. toDouble(String value, double defaultValue)
  7. toDouble(String value, Double defaultValue)
  8. toDouble(String value, double defaultValue)
  9. toDouble(String value, Double fallback)