Here you can find the source of tryParseDouble(Object o)
Object
that may be null or may be a float or double, this method attempts to convert the value to a Double
.
Parameter | Description |
---|---|
o | the object to try to convert |
Float or Double
; null otherwise
public static Double tryParseDouble(Object o)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w .j av a 2 s .co m * Given an <code>Object</code> that may be null or may be a float or double, this * method attempts to convert the value to a <code>Double</code>. If successful, * the <code>Double</code> value is returned; otherwise, <code>null</code> is returned. * NOTE: the [non-null] object is first converted to a string and is trimmed of whitespace. * @param o the object to try to convert * @return the converted value, if <em>o</em> is a <code>Float or Double</code>; null otherwise */ public static Double tryParseDouble(Object o) { if (o == null) return null; Double retVal = null; try { retVal = Double.parseDouble(o.toString().trim()); } catch (NumberFormatException nfe) { } return retVal; } }