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

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

Description

Returns the given String parsed to a Double.

License

Open Source License

Parameter

Parameter Description
value a String
defaultValue default double value to return if conversion fails

Return

double

Declaration

public static double toDouble(String value, double defaultValue) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w ww .  ja v a  2 s .  c  o  m*/
     * Returns the given String parsed to a Double. If the String cannot be
     * converted, the default value will be returned instead.
     *
     * @param value a String
     * @param defaultValue default double value to return if conversion fails
     * @return double
     */
    public static double toDouble(String value, double defaultValue) {
        try {
            return Double.parseDouble(value);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }
}

Related

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