阿拉伯数字转换成中文对发票票面金额转换的扩展

This commit is contained in:
MCP 2022-03-10 15:45:43 +08:00
parent b8bfce490b
commit 206de3bad0

View File

@ -40,7 +40,6 @@ public class NumberChineseFormatter {
new ChineseUnit('亿', 1_0000_0000, true),
};
/**
* 阿拉伯数字转换成中文,小数点后四舍五入保留两位. 使用于整数小数的转换.
*
@ -53,14 +52,24 @@ public class NumberChineseFormatter {
}
/**
* 阿拉伯数字转换成中文,小数点后四舍五入保留两位. 使用于整数小数的转换.
* 阿拉伯数字转换成中文.
*
* <p>主要是对发票票面金额转换的扩展
* <p>-12.32
* <p>发票票面转换为(负数)壹拾贰圆叁角贰分
* <p>而非负壹拾贰元叁角贰分
* <p>共两点不同1(负数) 而非 2 而非
* 2022/3/9
*
* @param amount 数字
* @param isUseTraditional 是否使用繁体
* @param isMoneyMode 是否为金额模式
* @return 中文
* @param isMoneyMode 是否金额模式
* @param negativeName 负号转换名称 (负数)
* @param unitName 单位名称
* @return java.lang.String
* @author machuanpeng
*/
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode) {
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode, String negativeName, String unitName) {
if (0 == amount) {
return "";
}
@ -71,7 +80,7 @@ public class NumberChineseFormatter {
// 负数
if (amount < 0) {
chineseStr.append("");
chineseStr.append(StrUtil.isNullOrUndefined(negativeName) ? "" : negativeName);
amount = -amount;
}
@ -86,7 +95,7 @@ public class NumberChineseFormatter {
// 金额模式下无需零元
chineseStr.append(longToChinese(yuan, isUseTraditional));
if (isMoneyMode) {
chineseStr.append("");
chineseStr.append(StrUtil.isNullOrUndefined(unitName) ? "" : unitName);
}
}
@ -127,6 +136,18 @@ public class NumberChineseFormatter {
return chineseStr.toString();
}
/**
* 阿拉伯数字转换成中文,小数点后四舍五入保留两位. 使用于整数小数的转换.
*
* @param amount 数字
* @param isUseTraditional 是否使用繁体
* @param isMoneyMode 是否为金额模式
* @return 中文
*/
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode) {
return format(amount, isUseTraditional, isMoneyMode, "", "");
}
/**
* 阿拉伯数字支持正负整数转换成中文
*