修复Convert.digitToChinese(0)输出金额无元整问题

This commit is contained in:
Looly 2024-07-31 00:15:37 +08:00
parent 8ae3a87174
commit 4bb0a445c4
4 changed files with 12 additions and 3 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog # 🚀Changelog
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.30(2024-07-30) # 5.8.30(2024-07-31)
### 🐣新特性 ### 🐣新特性
* 【core 】 Converter转换规则变更空对象、空值转为Bean时创建默认对象而非nullissue#3649@Github * 【core 】 Converter转换规则变更空对象、空值转为Bean时创建默认对象而非nullissue#3649@Github
@ -22,6 +22,7 @@
* 【core 】 修复FileUtil.file末尾换行符导致路径判断错误的问题issue#IAB65V@Gitee * 【core 】 修复FileUtil.file末尾换行符导致路径判断错误的问题issue#IAB65V@Gitee
* 【core 】 修复FileTypeUtil.getType空指针问题issue#IAD5JM@Gitee * 【core 】 修复FileTypeUtil.getType空指针问题issue#IAD5JM@Gitee
* 【core 】 修复IdcardUtil.isValidHKCard校验问题issue#IAFOLI@Gitee * 【core 】 修复IdcardUtil.isValidHKCard校验问题issue#IAFOLI@Gitee
* 【core 】 修复Convert.digitToChinese(0)输出金额无`元整问题`issue#3662@Github
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.8.29(2024-07-03) # 5.8.29(2024-07-03)

View File

@ -1030,7 +1030,7 @@ public class Convert {
*/ */
public static String digitToChinese(Number n) { public static String digitToChinese(Number n) {
if (null == n) { if (null == n) {
return ""; n = 0;
} }
return NumberChineseFormatter.format(n.doubleValue(), true, true); return NumberChineseFormatter.format(n.doubleValue(), true, true);
} }

View File

@ -92,7 +92,7 @@ public class NumberChineseFormatter {
*/ */
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 (0 == amount) { if (0 == amount) {
return ""; return isMoneyMode ? "零元整" : "";
} }
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)");

View File

@ -435,4 +435,12 @@ public class ConvertTest {
Assert.assertEquals(12, s); Assert.assertEquals(12, s);
} }
@Test
public void issue3662Test() {
String s = Convert.digitToChinese(0);
Assert.assertEquals("零元整", s);
s = Convert.digitToChinese(null);
Assert.assertEquals("零元整", s);
}
} }