KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > typeconverter > FloatConverter


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

3 package jodd.typeconverter;
4
5 /**
6  * Converts given object to Float.
7  */

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