01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.typeconverter;
04:
05: import java.math.BigDecimal;
06:
07: /**
08: * Converts given object to BigDecimal.
09: */
10: public class BigDecimalConverter implements TypeConverter {
11:
12: public static BigDecimal valueOf(Object value) {
13: if (value == null) {
14: return null;
15: }
16: if (value instanceof BigDecimal) {
17: return (BigDecimal) value;
18: }
19: try {
20: return (new BigDecimal(value.toString()));
21: } catch (NumberFormatException nfex) {
22: throw new TypeConversionException(nfex);
23: }
24: }
25:
26: public Object convert(Object value) {
27: return valueOf(value);
28: }
29: }
|