Here you can find the source of toDouble(String value, double defaultValue)
Parameter | Description |
---|---|
value | string value |
defaultValue | default value |
static public double toDouble(String value, double defaultValue)
//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; } }