public static Float toFloat ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof Float ) { return ( Float ) value ; } else if ( value instanceof Number ) { return ( ( Number ) value ) . floatValue ( ) ; } else { return Float . valueOf ( value . toString ( ) . trim ( ) ) ; } }
Converts value to Float if it can . If value is a Float it is returned if it is a Number it is promoted to Float and then returned in all other cases it converts the value to String then tries to parse Float from it .