---
title: "金额转换"
author: "backbase"
date: "2009-03-14T20:28:45Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2009-03-14T20:30:16Z"
id: 349194
url: "https://backbase.iteye.com/blog/349194"
---

public class ConvertRMB{

	private static final char DATA = new char { '零', '壹', '贰', '叁', '肆','伍', '陆', '柒', '捌', '玖' };
	
	private static final char UNITS = new char { '元', '拾', '佰', '仟', '万','拾', '佰', '仟', '亿' };

	public static void main(String args) {
```java

```

		System.out.println(convert(1234));
	}

	public static String convert(int money) {
		StringBuffer sbf = new StringBuffer();
		int unit = 0;
		while (money != 0) {
			sbf.insert(0, UNITS);
			int number = money % 10;
			sbf.insert(0, DATA);
			money /= 10;
		}
		return sbf.toString();
	}

}

输出：壹仟贰佰叁拾肆元

备注：该题目的解决方法从张孝祥老师整理面试题的文档中摘录，张老师写得非常易懂，巧妙，再次感谢张老师。