修复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

@ -2,7 +2,7 @@
# 🚀Changelog # 🚀Changelog
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.37(2025-03-11) # 5.8.37(2025-03-18)
### 🐣新特性 ### 🐣新特性
* 【json 】 ObjectMapper删除重复trimpr#3859@Github * 【json 】 ObjectMapper删除重复trimpr#3859@Github
@ -19,6 +19,7 @@
* 【cache 】 修复`ReentrantCache#getOrRemoveExpired`方法丢失onRemove触发问题pr#1315@Gitee * 【cache 】 修复`ReentrantCache#getOrRemoveExpired`方法丢失onRemove触发问题pr#1315@Gitee
* 【json 】 修复`JsonUtil.toBean`泛型数组类型丢失问题pr#3876@Github * 【json 】 修复`JsonUtil.toBean`泛型数组类型丢失问题pr#3876@Github
* 【http 】 修复`HttpUtil.normalizeParams`规则问题issue#IBQIYQ@Gitee * 【http 】 修复`HttpUtil.normalizeParams`规则问题issue#IBQIYQ@Gitee
* 【http 】 修复`NumberChineseFormatter.format`中自定义单位在0时错误问题issue#3888@Github
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.36(2025-02-18) # 5.8.36(2025-02-18)

View File

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