java中将金额变为可读金额

例如:将 1000.00 转化为1,000.00

	/**
	 * 将一个金额转化为可读的金额
	 * 如:1000.00 转化为 1,000.00
	 * @author 半知半行
	 */
	public static String getReadable(String param) {
		if(param == null || param.trim().length() == 0) {
			return param;
		}
		String result = "";//返回结果

		String befPoint = param;//获取小数点前的数字
		String afPoint = null;//获取小数点及以后的数字
		if(param.contains(".")) {
			int index = param.indexOf(".");
			befPoint = param.substring(0,index);
			afPoint = param.substring(index,param.length());
		}
		
		
		int length = befPoint.length();
		char[] paramChar = befPoint.toCharArray();
		for(int i = 0; i < length; i++) {
			if(i > 0 && (length-i) % 3 == 0) {
				result += ",";
			}
			result += paramChar[i];
		}
		if(afPoint != null) {
			result += afPoint;
		}
		
		return result;
	}

 

你可能感兴趣的:(原创公共方法)