码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-09-18 18:58:24      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:des   io   java   ar   sp   on   c   r   res   

/**
	 * 
	 * @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;

	}

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

标签:des   io   java   ar   sp   on   c   r   res   

原文地址:http://blog.csdn.net/zhaokaiqiang1992/article/details/39375711

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!