读书人

判断是不是为数字/转换成金额格式

发布时间: 2012-11-05 09:35:12 作者: rapoo

判断是否为数字/转换成金额格式

 /** * @see 是否为整数  * @author yisai * @param value * @return  *  */public static boolean isInteger(Object value){try{Integer.parseInt(value.toString());return true;}catch(Exception e){return false;}}/** * @see 是否为小数  * @author yisai * @param value * @return  *  */public static boolean isDouble(Object value){try{Double.parseDouble(value.toString());return true;}catch(Exception e){return false;}}/** * @see 是否为数字  * @author yisai * @param value * @return  *  */public static boolean isNumeric(Object value){if (isInteger(value) || isDouble(value)){return true;}return false;}/** * @see 转换成金额格式 * @author yisai * @param money * @param pattern"0.00"2为小数"0.0"一位小数"0"无小数 * @return */public static String convertMoney(Object money,String pattern){DecimalFormat decimalFormat = new DecimalFormat(pattern);String value = null;if(isNumeric(money)){value = decimalFormat.format(money);}else{value = decimalFormat.format(0);}return value;    }
?

读书人网 >编程

热点推荐