感觉应该不复杂,找AI写一个,有不少bug,尝试自己写,还挺麻烦的
费了半天劲,记录一下
private static final String[] CHINESE_NUMS = {
"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
private static final String[] CHINESE_LEVEL ={
"元","万", "亿", "万"};
private static final String[] CHINESE_UNITS = {
"", "拾", "佰","仟"};
private static final String[] DECIMAL_UNIT = {
"角","分","厘"};
public static String convert(double amount) {
if (amount < 0 || amount >= 1e16) {
throw new IllegalArgumentException("Amount out of range");
}
//这里有点问题,double转字符串,如果结果串超过16位会省略,可以优化
//正常够用
String amountStr = String.format("%.2f",amount);
// 将金额分为整数部分和小数部分
String zheng = "";
String ling = "";
//转化整数部分
zheng = readZS(amountStr.