public static Double toNullableDouble ( Object value ) { if ( value == null ) return null ; if ( value instanceof Date ) return ( double ) ( ( Date ) value ) . getTime ( ) ; if ( value instanceof Calendar ) return ( double ) ( ( Calendar ) value ) . getTimeInMillis ( ) ; if ( value instanceof Duration ) return ( double ) ( ( Duration ) value ) . toMillis ( ) ; if ( value instanceof Boolean ) return ( boolean ) value ? 1.0 : 0.0 ; if ( value instanceof Integer ) return ( double ) ( ( int ) value ) ; if ( value instanceof Short ) return ( double ) ( ( short ) value ) ; if ( value instanceof Long ) return ( double ) ( ( long ) value ) ; if ( value instanceof Float ) return ( double ) ( ( float ) value ) ; if ( value instanceof Double ) return ( double ) value ; if ( value instanceof String ) try { return Double . parseDouble ( ( String ) value ) ; } catch ( NumberFormatException ex ) { return null ; } return null ; }
Converts value into doubles or returns null when conversion is not possible .