KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > bean > converters > BigDecimalConverter


1 package jodd.bean.converters;
2
3 import java.math.BigDecimal;
4
5 /**
6  * Converts given object to BigDecimal.
7  */

8
9 public final class BigDecimalConverter implements jodd.bean.Converter {
10
11     public Object convert(Object value) {
12
13         if (value == null) {
14             return (BigDecimal) null;
15         }
16     
17         if (value instanceof BigDecimal) {
18             return value;
19         }
20     
21         try {
22             return (new BigDecimal(value.toString()));
23         } catch (Exception e) {
24             throw new IllegalArgumentException("BigDecimal conversion for " + value + " failed.");
25         }
26     }
27 }
28
Popular Tags