num转大写中文(零壹贰叁肆伍陆柒捌玖)

package net.wendal.nutz.util;

import org.junit.Test;

public class MoneyLowerToUp {

	public String numtochinese(String input) {
		String s1 = "零壹贰叁肆伍陆柒捌玖";
		String s4 = "分角整元拾佰仟万拾佰仟亿拾佰仟";
		String temp = "";
		String result = "";
		float f;
		int len = 0;
		if (input == null)
			return "输入字串不是数字串只能包括以下字符(′0′~′9′,′.′),输入字串最大只能精确到仟亿,小数点只能两位!";
		temp = input.trim();
		try {
			f = Float.parseFloat(temp);
		} catch (Exception e) {
			return "输入字串不是数字串只能包括以下字符(′0′~′9′,′.′),输入字串最大只能精确到仟亿,小数点只能两位!";
		}

		if (temp.indexOf(".") == -1)
			len = temp.length();
		else
			len = temp.indexOf(".");
		if (len > s4.length() - 3)
			return "输入字串最大只能精确到仟亿,小数点只能两位!";
		int n2 = 0;
		String num = "";
		String unit = "";

		for (int i = 0; i < temp.length(); i++) {
			if (i > len + 2)
				break;
			if (i != len) {
				int n1 = Integer.parseInt(String.valueOf(temp.charAt(i)));
				num = s1.substring(n1, n1 + 1);
				n1 = len - i + 2;
				unit = s4.substring(n1, n1 + 1);
				result = result.concat(num).concat(unit);
				System.out.println(result);
			}
		}
		if ((len == temp.length()) || (len == temp.length() - 1))
			result = result.concat("整");
		if (len == temp.length() - 2)
			result = result.concat("零分");
		
		return result;
	}
	@Test
	public void test(){
		System.out.println(numtochinese("155456.46"));
	}

}

猜你喜欢

转载自blog.csdn.net/jackieriver/article/details/72143309