public static BigDecimal toBigDecimal ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof BigDecimal ) { return ( BigDecimal ) value ; } else { try { return new BigDecimal ( value . toString ( ) . trim ( ) ) ; } catch ( NumberFormatException e ) { throw new ConversionException ( "failed to convert: '" + value + "' to BigDecimal" , e ) ; } } }
Converts value to BigDecimal if it can . If value is a BigDecimal it is returned if it is a BigDecimal it is promoted to BigDecimal and then returned in all other cases it converts the value to String then tries to parse BigDecimal from it .