工具类包括:
- 数字转中文大写形式,比如一百二十一
- 数字转金额用的大写形式,比如:壹佰贰拾壹
- 转金额形式,比如:壹佰贰拾壹整
package cn.hutool.core.convert;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
public class NumberChineseFormatterUtils {
private static final char[] DIGITS = {
'零', '一', '壹', '二', '贰', '三', '叁', '四', '肆', '五', '伍',
'六', '陆', '七', '柒', '八', '捌', '九', '玖'};
private static final ChineseUnit[] CHINESE_NAME_VALUE = {
new ChineseUnit(' ', 1, false),
new ChineseUnit('十', 10, false),
new ChineseUnit('拾', 10, false),
new ChineseUnit('百', 100, false),
new ChineseUnit('佰', 100, false),
new ChineseUnit('千', 1000, false),
new ChineseUnit('仟', 1000, false),
new ChineseUnit('万', 1_0000, true),
new ChineseUnit('亿', 1_0000_0000, true),
};
public static String format(double amount, boolean isUseTraditional) {
return format(amount, isUseTraditional, false);
}
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode) {
if (amount > 99_9999_9999_9999.99 || amount < -99999999999999.99) {
throw new IllegalArgumentException("Number support only: (-99999999999999.99 ~ 99999999999999.99)!");
}
boolean negative = false;
if (amount < 0) {
negative = true;
amount = -amount;
}
long temp = Math.round(amount * 100);
final int numFen = (int) (temp % 10);
temp = temp / 10;
final int numJiao = (int) (temp % 10);
temp = temp / 10;
final