const numberToCNchar = money => {
const ArabicNumeralCapital = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" ];
const AfterInt = ["角", "分"];
const IntUnitSplit = ["元", "万", "亿", "兆"];
const BeforeInt = ["", "拾", "佰", "仟"];
const symbol = money < 0 ? "负" : "";
money = Math.abs(money);
let res = "";
for(let i = 0; i < AfterInt.length; i++) {
let num = Math.pow(10, i+1);
num = Math.floor(num * money) % 10;
res += (ArabicNumeralCapital[num] + AfterInt[i]).replace(/(零.)+/, '');
}
if (res.length < 1) {
res = "整";
}
let IntPart = Math.floor(money);
for(let i = 0; i < IntUnitSplit.length && IntPart > 0; i++) {
let part = "";
for(let j = 0; j < BeforeInt.length; j++) {
let a = IntPart % 10;
IntPart = Math.floor(IntPart / 10);
part = ArabicNumeralCapital[a] + BeforeInt[j] + part;
}
res = part + IntUnitSplit[i] + res;
}
res=res.replace(/(零[拾佰仟])*零元/,"元");
res=res.replace(/^(零.)+/,"");
res=res.replace(/(零[拾佰仟])+/g,"零");
res=res.replace(/零([万亿兆])+/g,"$1");
res=res.replace(/零([万亿兆])+/g,"");
res=res.replace(/^整$/, "零元整");
return symbol + res;
}
const money = numberToCNchar('43043242.93');
console.log('money',money)