字符串轉換工具類

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 請求參數轉換工具類
 * @time 2016-11-18
 * @author binshangwen
 */
public class ParamConvertUtil
{
    private static Logger log = LoggerFactory.getLogger(ParamConvertUtil.class);

    /**
     * 轉換成Integer
     * @param value
     * @return
     */
    public static Integer convertInteger(String value){
        Integer id = 0;
        try{
            id = Integer.parseInt(value);
        }catch (NumberFormatException e){
            //log.error("",e);
        }
        return id;
    }

    /**
     * 轉換成Double
     * @param value
     */
    public static Double convertDouble(String value){
          Double d=0d;
          try{
              d=Double.parseDouble(value);
          }catch (NumberFormatException e){
             // log.error("",e);
          }
        return d;
    }

    /**
     * 轉換成Float
     * @param value
     */
    public static Float convertFloat(String value){
        Float f=0f;
        try{
            f=Float.parseFloat(value);
        }catch (NumberFormatException e){
           // log.error("",e);
        }
        return f;
    }


    /**
     * 轉換成Long
     * @param value
     */
    public static Long convertLong(String value){
        Long l = 0l;
        try{
            l=Long.parseLong(value);
        }catch (NumberFormatException e){
           // log.error("",e);
        }
        return l;
    }

}
相關文章
相關標籤/搜索