1
0
mirror of https://gitee.com/dromara/hutool.git synced 2025-04-05 17:37:59 +08:00

修复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
CHANGELOG.md
hutool-core/src
main/java/cn/hutool/core/convert
test/java/cn/hutool/core/convert

View File

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

View File

@ -1030,7 +1030,7 @@ public class Convert {
*/
public static String digitToChinese(Number n) {
if (null == n) {
return "";
n = 0;
}
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) {
if (0 == amount) {
return "";
return isMoneyMode ? "零元整" : "";
}
Assert.checkBetween(amount, -99_9999_9999_9999.99, 99_9999_9999_9999.99,
"Number support only: (-99999999999999.99 ~ 99999999999999.99)");

View File

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