KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > BigDecimalConverter


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.typeconverter;
4
5 import java.math.BigDecimal JavaDoc;
6
7 /**
8  * Converts given object to BigDecimal.
9  */

10 public class BigDecimalConverter implements TypeConverter {
11
12     public static BigDecimal JavaDoc valueOf(Object JavaDoc value) {
13         if (value == null) {
14             return null;
15         }
16         if (value instanceof BigDecimal JavaDoc) {
17             return (BigDecimal JavaDoc) value;
18         }
19         try {
20             return (new BigDecimal JavaDoc(value.toString()));
21         } catch (NumberFormatException JavaDoc nfex) {
22             throw new TypeConversionException(nfex);
23         }
24     }
25
26
27     public Object JavaDoc convert(Object JavaDoc value) {
28         return valueOf(value);
29     }
30 }
31
Popular Tags