本文整理汇总了Java中java.lang.Double.parseDouble方法的典型用法代码示例。如果您正苦于以下问题:Java Double.parseDouble方法的具体用法?Java Double.parseDouble怎么用?Java Double.parseDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.Double
的用法示例。
在下文中一共展示了Double.parseDouble方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseDouble
import java.lang.Double; //导入方法依赖的package包/类
private double parseDouble(String doubleString) {
Matcher m = specialDoubleRegex.matcher(doubleString);
if (m.matches()) {
//got an infinity
if (m.start(1) != -1) {
if (m.start(2) != -1) {
return Double.NEGATIVE_INFINITY;
} else {
return Double.POSITIVE_INFINITY;
}
} else {
return Double.NaN;
}
}
return Double.parseDouble(doubleString);
}
示例2: getDouble
import java.lang.Double; //导入方法依赖的package包/类
/**
* Implements the <tt>getDouble</tt> method as per the specification in
* {@link Preferences#getDouble(String,double)}.
*
* <p>This implementation invokes {@link #get(String,String) <tt>get(key,
* null)</tt>}. If the return value is non-null, the implementation
* attempts to translate it to an <tt>double</tt> with
* {@link Double#parseDouble(String)}. If the attempt succeeds, the return
* value is returned by this method. Otherwise, <tt>def</tt> is returned.
*
* @param key key whose associated value is to be returned as a double.
* @param def the value to be returned in the event that this
* preference node has no value associated with <tt>key</tt>
* or the associated value cannot be interpreted as a double.
* @return the double value represented by the string associated with
* <tt>key</tt> in this preference node, or <tt>def</tt> if the
* associated value does not exist or cannot be interpreted as
* a double.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
*/
public double getDouble(String key, double def) {
double result = def;
try {
String value = get(key, null);
if (value != null)
result = Double.parseDouble(value);
} catch (NumberFormatException e) {
// Ignoring exception causes specified default to be returned
}
return result;
}
示例3: getDouble
import java.lang.Double; //导入方法依赖的package包/类
/**
* Implements the {@code getDouble} method as per the specification in
* {@link Preferences#getDouble(String,double)}.
*
* <p>This implementation invokes {@link #get(String,String) get(key,
* null)}. If the return value is non-null, the implementation
* attempts to translate it to an {@code double} with
* {@link Double#parseDouble(String)}. If the attempt succeeds, the return
* value is returned by this method. Otherwise, {@code def} is returned.
*
* @param key key whose associated value is to be returned as a double.
* @param def the value to be returned in the event that this
* preference node has no value associated with {@code key}
* or the associated value cannot be interpreted as a double.
* @return the double value represented by the string associated with
* {@code key} in this preference node, or {@code def} if the
* associated value does not exist or cannot be interpreted as
* a double.
* @throws IllegalStateException if this node (or an ancestor) has been
* removed with the {@link #removeNode()} method.
* @throws NullPointerException if {@code key} is {@code null}.
* @throws IllegalArgumentException if key contains the null control
* character, code point U+0000.
*/
public double getDouble(String key, double def) {
double result = def;
try {
String value = get(key, null);
if (value != null)
result = Double.parseDouble(value);
} catch (NumberFormatException e) {
// Ignoring exception causes specified default to be returned
}
return result;
}