public static Double toDouble ( Number self ) { // Conversions in which all decimal digits are known to be good. if ( ( self instanceof Double ) || ( self instanceof Long ) || ( self instanceof Integer ) || ( self instanceof Short ) || ( self instanceof Byte ) ) { return self . doubleValue ( ) ; } // Chances are this is a Float or a Big. // With Float we're extending binary precision and that gets ugly in decimal. // If we used Float.doubleValue() on 0.1f we get 0.10000000149011612. // Note that this is different than casting '(double) 0.1f' which will do the // binary extension just like in Java. // With Bigs and other unknowns, this is likely to be the same. return Double . valueOf ( self . toString ( ) ) ; }
Transform a Number into a Double