https://www.d5.nz/read/sfdlq/text-part0000_split_029.html
private char[] chnNum = {'零', '一', '二', '三', '四', '五', '六', '七', '八', '九'};
private String[] chnSectionUnit = {"", "万", "亿", "万亿"};
private String[] chnNumUnit = {"", "十", "百", "千"};
public String numberToChinese(long num) {
int secUnitPos = 0;
boolean needZero = false;
StringBuilder sb = new StringBuilder();
while (num > 0) {
int section = (int) (num % 10000);
// 上一个section是否 > 0 and < 1000
if (needZero) {
sb.insert(0, chnNum[0]);
}
sb.insert(0, chnSectionUnit[secUnitPos]);
sectionToChinese(section, sb);
needZero = section > 0 && section < 1000;
secUnitPos++;
num = num / 10000;
}
return sb.toString();
}
private void sectionToChinese(int section, StringBuilder sb) {
int numUnitPos = 0;
boolean lastCharIsZero = true;
while (section > 0) {
int v = section % 10;
if (v == 0) {
// 注意连续的0, 0101与1001
// section == 0 或者 (section != 0 and zero = false)
if (section == 0 || !lastCharIsZero) {
lastCharIsZero = true;
sb.insert(0, chnNum[0]);
}
}
else {
lastCharIsZero = false;
sb.insert(0, chnNumUnit[numUnitPos]);
sb.insert(0, chnNum[v]);
}
numUnitPos++;
section = section / 10;
}
}