参照nndhyp的博客。 

原文地址 http://blog.csdn.net/nndhyp/article/details/7265971

财务系统应用较多
将金额小数转换成中文大写金额
如40330701101.2 ==> 肆佰零叁亿叁千零柒拾万壹千壹佰零壹元贰角
代码如下

Java代码 复制代码 收藏代码
  1. /**
  2. * 金额小数转换成中文大写金额
  3. * @author Neil Han
  4. *
  5. */
  6. public class ConvertMoneyToUppercase {
  7.  
  8. private static final String UNIT[] = { "万", "千", "佰", "拾", "亿", "千", "佰",
  9. "拾", "万", "千", "佰", "拾", "元", "角", "分" };
  10.  
  11. private static final String NUM[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆",
  12. "柒", "捌", "玖" };
  13.  
  14. private static final double MAX_VALUE = 9999999999999.99D;
  15.  
  16. /**
  17. * 将金额小数转换成中文大写金额
  18. * @param money
  19. * @return result
  20. */
  21. public static String convertMoney(double money) {
  22. if (money < 0 || money > MAX_VALUE)
  23. return "参数非法!";
  24. long money1 = Math.round(money * 100); // 四舍五入到分
  25. if (money1 == 0)
  26. return "零元整";
  27. String strMoney = String.valueOf(money1);
  28. int numIndex = 0; // numIndex用于选择金额数值
  29. int unitIndex = UNIT.length - strMoney.length(); // unitIndex用于选择金额单位
  30. boolean isZero = false; // 用于判断当前为是否为零
  31. String result = "";
  32. for (; numIndex < strMoney.length(); numIndex++, unitIndex++) {
  33. char num = strMoney.charAt(numIndex);
  34. if (num == '0') {
  35. isZero = true;
  36. if (UNIT[unitIndex] == "亿" || UNIT[unitIndex] == "万"
  37. || UNIT[unitIndex] == "元") { // 如果当前位是亿、万、元,且数值为零
  38. result = result + UNIT[unitIndex]; //补单位亿、万、元
  39. isZero = false;
  40. }
  41. }else {
  42. if (isZero) {
  43. result = result + "零";
  44. isZero = false;
  45. }
  46. result = result + NUM[Integer.parseInt(String.valueOf(num))] + UNIT[unitIndex];
  47. }
  48. }
  49. //不是角分结尾就加"整"字
  50. if (!result.endsWith("角")&&!result.endsWith("分")) {
  51. result = result + "整";
  52. }
  53. //例如没有这行代码,数值"400000001101.2",输出就是"肆千亿万壹千壹佰零壹元贰角"
  54. result = result.replaceAll("亿万", "亿");
  55. return result;
  56. }
  57.  
  58. public static void main(String[] args) {
  59. double value = Double.parseDouble("40330701101.2");
  60. System.out.println("您输入的金额(小写)为:" + value);
  61. System.out.println("您输入的金额(大写)为:" + convertMoney(value));
  62. }
  63.  
  64. }

/**
 * 金额小数转换成中文大写金额
 * @author Neil Han
 *	
 */
public class ConvertMoneyToUppercase {

	private static final String UNIT[] = { "万", "千", "佰", "拾", "亿", "千", "佰",
			"拾", "万", "千", "佰", "拾", "元", "角", "分" };

	private static final String NUM[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆",
			"柒", "捌", "玖" };

	private static final double MAX_VALUE = 9999999999999.99D;

	/**
	 * 将金额小数转换成中文大写金额
	 * @param money
	 * @return result
	 */
	public static String convertMoney(double money) {
		if (money < 0 || money > MAX_VALUE)
			return "参数非法!";
		long money1 = Math.round(money * 100); // 四舍五入到分
		if (money1 == 0)
			return "零元整";
		String strMoney = String.valueOf(money1);
		int numIndex = 0; // numIndex用于选择金额数值
		int unitIndex = UNIT.length - strMoney.length(); // unitIndex用于选择金额单位
		boolean isZero = false; // 用于判断当前为是否为零
		String result = "";
		for (; numIndex < strMoney.length(); numIndex++, unitIndex++) {
			char num = strMoney.charAt(numIndex);
			if (num == '0') {
				isZero = true;
				if (UNIT[unitIndex] == "亿" || UNIT[unitIndex] == "万"
						|| UNIT[unitIndex] == "元") { // 如果当前位是亿、万、元,且数值为零
					result = result + UNIT[unitIndex]; //补单位亿、万、元
					isZero = false;
				} 
			}else {
				if (isZero) {
					result = result + "零";
					isZero = false;
				}
				result = result + NUM[Integer.parseInt(String.valueOf(num))] + UNIT[unitIndex];
			}
		}
		//不是角分结尾就加"整"字
		if (!result.endsWith("角")&&!result.endsWith("分")) {
			result = result + "整";
		}
		//例如没有这行代码,数值"400000001101.2",输出就是"肆千亿万壹千壹佰零壹元贰角"
		result = result.replaceAll("亿万", "亿");
		return result;
	}

	public static void main(String[] args) {
		double value = Double.parseDouble("40330701101.2");
		System.out.println("您输入的金额(小写)为:" + value);
		System.out.println("您输入的金额(大写)为:" + convertMoney(value));
	}

}



输出为:
您输入的金额(小写)为:4.03307011012E10
您输入的金额(大写)为:肆佰零叁亿叁千零柒拾万壹千壹佰零壹元贰角