KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jodd.bean.converters;
2
3 /**
4  * Converts given object to Float.
5  */

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