public Number getValue ( ) { if ( ( getText ( ) == null ) || "" . equals ( getText ( ) . trim ( ) ) ) return null ; try { Number n = format . parse ( getText ( ) ) ; if ( n . getClass ( ) == this . numberClass ) return n ; else if ( this . numberClass == BigDecimal . class ) { BigDecimal bd = new BigDecimal ( n . doubleValue ( ) ) ; if ( scale != null ) { bd = bd . setScale ( scale . intValue ( ) , BigDecimal . ROUND_HALF_UP ) ; } return bd ; } else if ( this . numberClass == Double . class ) return new Double ( n . doubleValue ( ) ) ; else if ( this . numberClass == Float . class ) return new Float ( n . floatValue ( ) ) ; else if ( this . numberClass == BigInteger . class ) // we have called setBigDecimalFormat to make sure a BigDecimal // is returned so use toBigInteger on that class return ( ( BigDecimal ) n ) . toBigInteger ( ) ; else if ( this . numberClass == Long . class ) return new Long ( n . longValue ( ) ) ; else if ( this . numberClass == Integer . class ) return new Integer ( n . intValue ( ) ) ; else if ( this . numberClass == Short . class ) return new Short ( n . shortValue ( ) ) ; else if ( this . numberClass == Byte . class ) return new Byte ( n . byteValue ( ) ) ; return null ; } catch ( Exception pe ) { log . error ( "Error: " + getText ( ) + " is not a number." , pe ) ; return null ; } }
Parses a number from the inputField and will adjust it s class if needed .