首页 > 代码库 > 将银行大写数字转换为纯数字

将银行大写数字转换为纯数字

/**
	 * 
	 * @Description: 将“壹仟”格式转换成1000
	 * @param
	 * @return int
	 * @throws
	 */
	public static int getMoneyFromString(String string) {

		int result = 0;

		if (string.contains("亿")) {
			int index = string.indexOf("亿");
			char billionString = string.charAt(index - 1);
			result = result + getNumFromOldString(billionString) * 10000;
		}

		if (string.contains("仟")) {
			int index = string.indexOf("仟");
			char millionString = string.charAt(index - 1);
			result = result + getNumFromOldString(millionString) * 1000;
		}

		if (string.contains("佰")) {
			int index = string.indexOf("佰");
			char hundredString = string.charAt(index - 1);
			result = result + getNumFromOldString(hundredString) * 100;
		}

		if (string.contains("拾")) {
			int index = string.indexOf("拾");
			char tenString = string.charAt(index - 1);
			result = result + getNumFromOldString(tenString) * 10;
		}

		String[] lastNum = string.split("拾");
		if (lastNum.length > 1) {
			result = result + getNumFromOldString(lastNum[1].toCharArray()[0]);
		}

		return result;

	}

	/**
	 * 
	 * @Description: 转换老体字到数字
	 * @param
	 * @return int
	 * @throws
	 */
	public static int getNumFromOldString(char ch) {

		switch (ch) {
		case '零':
			return 0;
		case '壹':
			return 1;
		case '贰':
			return 2;
		case '叁':
			return 3;
		case '肆':
			return 4;
		case '伍':
			return 5;
		case '陆':
			return 6;
		case '柒':
			return 7;
		case '捌':
			return 8;
		case '玖':
			return 9;
		}

		return 0;

	}

将银行大写数字转换为纯数字