字符串类型转换

来源:互联网 发布:短域名生成算法 编辑:程序博客网 时间:2024/04/30 06:44
public class NumberParseUtil {
    private static final Logger logger = LoggerFactory
            .getLogger(NumberParseUtil.class);

    public static int parseInt(String str) throws Exception {
        if (str == null) {
            return 0;
        } else {
            try {
                return Integer.parseInt(str);
            } catch (Exception e) {
                logger.error("int类型转换错误", e);
                throw new Exception();
            }
        }

    }

    public static float parseFloat(String str) throws Exception {
        if (str == null) {
            return 0;
        } else {
            try {
                return Float.parseFloat(str);
            } catch (Exception e) {
                logger.error("float类型转换错误", e);
                throw new Exception();
            }
        }

    }
}

原创粉丝点击