修复NumberChineseFormatter.format中自定义单位在0时错误问题(issue#3888@Github)

This commit is contained in:
Looly
2025-03-18 19:27:37 +08:00
parent 88cf61eb7f
commit cfb194a845
2 changed files with 8 additions and 3 deletions

View File

@@ -91,8 +91,12 @@ public class NumberChineseFormatter {
* @since 5.7.23
*/
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode, String negativeName, String unitName) {
if(StrUtil.isNullOrUndefined(unitName)){
unitName = "";
}
if (0 == amount) {
return isMoneyMode ? "" : "";
return isMoneyMode ? "" + unitName + "" : "";
}
Assert.checkBetween(amount, -99_9999_9999_9999.99, 99_9999_9999_9999.99,
"Number support only: (-99999999999999.99 ~ 99999999999999.99)");
@@ -116,7 +120,7 @@ public class NumberChineseFormatter {
// 金额模式下,无需“零元”
chineseStr.append(longToChinese(yuan, isUseTraditional));
if (isMoneyMode) {
chineseStr.append(StrUtil.isNullOrUndefined(unitName) ? "" : unitName);
chineseStr.append(unitName);
}
}