java⼩写⾦额转⼤写⼩算法public class MoneyFormat {
private StringBuffer sb = new StringBuffer();
private String bigLetter[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌","玖" };
private String unit[] = { "圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾","佰", "仟", "万" };
/**
* 转换⾦额为⼤写
java valueof
*
* @param String ⼩写⾦额
* @return String ⼤写⾦额
* @author dryzeng
*/
public String format(String inputMoney) {
if (inputMoney.length() > 13) {
sb.append("数字太⼤,⽆法显⽰!");
String();
}
if (Double.valueOf(inputMoney) < 0) {
sb.append("错误,⾦额为负数!");
String();
}
if (Double.valueOf(inputMoney) == 0) {
sb.append("零圆整");
String();
}
// 取得⼩数点前的数字
String moneyf[] = String.valueOf(inputMoney).split("\\.")[0].split("");
//⾦额转换
for (int i = 1; i < moneyf.length; i++) {
sb.append(bigLetter[Integer.valueOf(moneyf[i])]);
sb.append(unit[moneyf.length - 1 - i]);
}
try {
// 取得⼩数点后的数字
String moneyb[] = String.valueOf(inputMoney).split("\\.")[1].split("");
sb.append(bigLetter[Integer.valueOf(moneyb[1])]);
sb.append("⾓");
} catch (Exception e) {}
//格式⼈性化
String finalsb = sb.toString();
finalsb = placeAll("零仟", "零");        finalsb = placeAll("零佰", "零");        finalsb = placeAll("零拾", "零");        finalsb = placeAll("零亿", "亿");        finalsb = placeAll("零万", "万");        finalsb = placeAll("零零零", "零");        finalsb = placeAll("零零", "零");        finalsb = placeAll("零圆", "圆");        finalsb = placeAll("亿万", "亿");        finalsb = placeAll("零⾓", "");
if ("圆".equals(finalsb.substring(0, 1))) {            finalsb = "零" + finalsb;
}
return finalsb;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。