金额转大写:
public class MoneyForm {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(digitUppercase(14000090.23));
}
private static final String UNIT[] = { “万”, “千”, “佰”, “拾”, “亿”, “千”, “佰”,
“拾”, “万”, “千”, “佰”, “拾”, “元”, “角”, “分” };
private static final String NUM[] = { “零”, “壹”, “贰”, “叁”, “肆”, “伍”, “陆”,
“柒”, “捌”, “玖” };
private static final double MAX_VALUE = 9999999999999.99D;
public static String digitUppercase(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] &