package xyz.wbsite.frame.excel.converter;

/**
 * FloatConverter - Float转化器，重写了对象到String，String到对象的转化方式
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2017-01-01
 */
public class FloatConverter implements Converter<Float> {

    @Override
    public Float convert(String var) {
        try {
            //增加对1.0一类的的优化显示
            if (var.matches("(\\d+)\\.0")) {
                var = var.replaceAll("\\.0$", "");
            }

            return Float.parseFloat(var);
        } catch (Exception e) {
            return 0f;
        }
    }

    @Override
    public String string(Float var) {
        if (var == null) {
            return "";
        }
        return String.valueOf(var);
    }
}
