001package org.javasimon.utils.bean;
002
003/**
004 * Converter from String to Double.
005 *
006 * @author <a href="mailto:ivan.mushketyk@gmail.com">Ivan Mushketyk</a>
007 */
008public class ToDoubleConverter implements Converter {
009
010        @Override
011        public Double convert(Class<?> targetClass, String strVal) throws ConvertException {
012                if (strVal == null) {
013                        return null;
014                }
015
016                try {
017                        return Double.parseDouble(strVal);
018                } catch (NumberFormatException ex) {
019                        throw new ConvertException(String.format("Failed to parse '%s' to Double", strVal));
020                }
021        }
022}