public static Number castToNumber ( Object val ) // was NumericValue { if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . entry ( cclass , "castToNumber" , val ) ; if ( ! ( val instanceof String ) ) { if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , null ) ; return null ; } String stringVal = ( String ) val ; if ( stringVal . length ( ) == 0 ) { if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , null ) ; return null ; } // If the value ends in [ l | L | f | F | d | D ] it must be intended to be a // Long/Float/Double and we convert it accordingly. Otherwise, we first try to // convert to Integer/Long, then to Double. If all fail, we return null. try { switch ( stringVal . charAt ( stringVal . length ( ) - 1 ) ) { case ' ' : case ' ' : stringVal = stringVal . substring ( 0 , stringVal . length ( ) - 1 ) ; Long theLong = new Long ( stringVal ) ; if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , theLong ) ; return theLong ; case ' ' : case ' ' : Float theFloat = new Float ( stringVal ) ; if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , theFloat ) ; return theFloat ; case ' ' : case ' ' : Double theDouble = new Double ( stringVal ) ; if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , theDouble ) ; return theDouble ; default : try { theLong = new Long ( stringVal ) ; if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , theLong ) ; return theLong ; } catch ( NumberFormatException e ) { // No FFDC code needed theDouble = new Double ( stringVal ) ; if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , theDouble ) ; return theDouble ; } } } catch ( NumberFormatException e ) { // No FFDC code needed if ( tc . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) tc . exit ( cclass , "castToNumber" , null ) ; return null ; } }
be so cast .